Skip to content

Commit 8bed253

Browse files
test: fix broken mocks and stale expectations for a green full run (#861)
1 parent c666333 commit 8bed253

5 files changed

Lines changed: 59 additions & 4 deletions

File tree

src/main/ipc/handlers/__tests__/system.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ vi.mock('electron', () => ({
2929
app: {
3030
relaunch,
3131
quit,
32+
// Транзитивный импорт main-меню читает версию при инициализации модуля.
33+
getVersion: vi.fn(() => '0.0.0-test'),
34+
},
35+
BrowserWindow: {
36+
getAllWindows: vi.fn(() => []),
37+
getFocusedWindow: vi.fn(() => null),
38+
},
39+
Menu: {
40+
buildFromTemplate: vi.fn(() => ({})),
41+
setApplicationMenu: vi.fn(),
42+
},
43+
dialog: {
44+
showMessageBox: vi.fn(),
3245
},
3346
ipcMain: {
3447
handle,
@@ -70,6 +83,8 @@ vi.mock('../../../storage/providers/markdown/runtime/paths', () => ({
7083
vi.mock('../../../store', () => ({
7184
store: {
7285
preferences: {
86+
// Транзитивный импорт i18n читает локаль при инициализации модуля.
87+
get: vi.fn(),
7388
set: preferencesSet,
7489
},
7590
},

src/renderer/composables/__tests__/useSnippetsSearch.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ async function setup(options: SetupOptions = {}) {
3434
data: [{ contents: [], id: 1, name: 'Search result', tags: [] }],
3535
}))
3636

37+
// useContentSort читает store.app при импорте модуля: мокается целиком,
38+
// чтобы не тянуть electron store в тест.
39+
vi.doMock('@/composables/useContentSort', () => ({
40+
useContentSort: () => ({
41+
getContentSortQuery: () => ({}),
42+
}),
43+
}))
44+
3745
vi.doMock('@/composables/useDonations', () => ({
3846
useDonations: () => ({
3947
incrementCopy: vi.fn(),

src/renderer/composables/math-notebook/math-engine/__tests__/format.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ describe('formatMathNumber', () => {
5151
describe('formatMathDate', () => {
5252
const date = new Date(2026, 2, 28) // March 28, 2026
5353

54+
// Время форматируется без секунд (hour + minute, см. formatMathDate).
5455
it('formats date with en-US locale', () => {
55-
expect(formatMathDate(date, 'en-US')).toBe('3/28/2026, 12:00:00 AM')
56+
expect(formatMathDate(date, 'en-US')).toBe('3/28/2026, 12:00 AM')
5657
})
5758

5859
it('formats date with de-DE locale', () => {
59-
expect(formatMathDate(date, 'de-DE')).toBe('28.3.2026, 0:00:00')
60+
expect(formatMathDate(date, 'de-DE')).toBe('28.3.2026, 0:00')
6061
})
6162

6263
it('formats date with ru-RU locale', () => {
63-
expect(formatMathDate(date, 'ru-RU')).toBe('28.03.2026, 0:00:00')
64+
expect(formatMathDate(date, 'ru-RU')).toBe('28.03.2026, 0:00')
6465
})
6566
})

src/renderer/ipc/listeners/__tests__/deepLinks.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest'
2-
import { computed, ref } from 'vue'
2+
import { computed, reactive, ref } from 'vue'
33

44
interface SetupOptions {
55
httpRequestResponse?: any
@@ -138,6 +138,11 @@ async function setup(options: SetupOptions = {}) {
138138
focusedRequestId: ref<number | undefined>(),
139139
highlightedFolderIds: ref(new Set<number>()),
140140
highlightedRequestIds: ref(new Set<number>()),
141+
httpState: reactive<{
142+
folderId?: number
143+
libraryFilter?: string
144+
requestId?: number
145+
}>({}),
141146
isHttpSpaceInitialized,
142147
}),
143148
useHttpFolders: () => ({
@@ -202,6 +207,28 @@ async function setup(options: SetupOptions = {}) {
202207
}),
203208
}))
204209

210+
// deepLinks импортирует '@/electron' напрямую: без мока модуль падает на
211+
// window.electron в node-окружении.
212+
vi.doMock('@/electron', () => ({
213+
i18n: {
214+
t: (key: string) => key,
215+
},
216+
ipc: {
217+
invoke: vi.fn(),
218+
on: vi.fn(),
219+
},
220+
store: {
221+
app: {
222+
get: vi.fn(),
223+
set: vi.fn(),
224+
},
225+
preferences: {
226+
get: vi.fn(),
227+
set: vi.fn(),
228+
},
229+
},
230+
}))
231+
205232
vi.doMock('@/services/api', () => ({
206233
api: {
207234
notes: {

vitest.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import path from 'node:path'
2+
import vue from '@vitejs/plugin-vue'
23
import { defineConfig } from 'vitest/config'
34

45
export default defineConfig({
6+
// Renderer-модули транзитивно импортируют .vue (например, useSonner →
7+
// Sonner.vue): без vue-плагина такие тесты падают на import analysis.
8+
plugins: [vue()],
59
resolve: {
610
alias: {
711
'@': path.resolve(__dirname, 'src/renderer'),

0 commit comments

Comments
 (0)