|
| 1 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | +import { computed, reactive, ref, watch } from 'vue' |
| 3 | + |
| 4 | +globalThis.computed = computed |
| 5 | +globalThis.reactive = reactive |
| 6 | +globalThis.ref = ref |
| 7 | +globalThis.watch = watch |
| 8 | + |
| 9 | +const storeGet = vi.fn() |
| 10 | +const storeSet = vi.fn() |
| 11 | + |
| 12 | +async function setup() { |
| 13 | + vi.resetModules() |
| 14 | + |
| 15 | + storeGet.mockImplementation((key: string) => { |
| 16 | + if (key === 'notes.selection') { |
| 17 | + return {} |
| 18 | + } |
| 19 | + |
| 20 | + if (key === 'notes.editorMode') { |
| 21 | + return 'livePreview' |
| 22 | + } |
| 23 | + |
| 24 | + if (key === 'notes.layout.mode') { |
| 25 | + return 'all-panels' |
| 26 | + } |
| 27 | + }) |
| 28 | + |
| 29 | + vi.doMock('@/electron', () => ({ |
| 30 | + store: { |
| 31 | + app: { |
| 32 | + get: storeGet, |
| 33 | + set: storeSet, |
| 34 | + }, |
| 35 | + }, |
| 36 | + })) |
| 37 | + |
| 38 | + const { useNotesApp } = await import('../useNotesApp') |
| 39 | + |
| 40 | + return useNotesApp() |
| 41 | +} |
| 42 | + |
| 43 | +beforeEach(() => { |
| 44 | + vi.clearAllMocks() |
| 45 | +}) |
| 46 | + |
| 47 | +describe('useNotesApp', () => { |
| 48 | + it('restores all notes panels after clearing search', async () => { |
| 49 | + const notesApp = await setup() |
| 50 | + |
| 51 | + notesApp.setNotesLayoutMode('all-panels') |
| 52 | + notesApp.saveNotesStateSnapshot('beforeSearch') |
| 53 | + |
| 54 | + notesApp.setNotesLayoutMode('list-editor') |
| 55 | + notesApp.restoreNotesStateSnapshot('beforeSearch') |
| 56 | + |
| 57 | + expect(notesApp.notesLayoutMode.value).toBe('all-panels') |
| 58 | + expect(notesApp.isNotesSidebarHidden.value).toBe(false) |
| 59 | + expect(notesApp.isNotesListHidden.value).toBe(false) |
| 60 | + }) |
| 61 | + |
| 62 | + it('restores editor-only notes layout after clearing search', async () => { |
| 63 | + const notesApp = await setup() |
| 64 | + |
| 65 | + notesApp.setNotesLayoutMode('editor-only') |
| 66 | + notesApp.saveNotesStateSnapshot('beforeSearch') |
| 67 | + |
| 68 | + notesApp.setNotesLayoutMode('all-panels') |
| 69 | + notesApp.restoreNotesStateSnapshot('beforeSearch') |
| 70 | + |
| 71 | + expect(notesApp.notesLayoutMode.value).toBe('editor-only') |
| 72 | + expect(notesApp.isNotesSidebarHidden.value).toBe(true) |
| 73 | + expect(notesApp.isNotesListHidden.value).toBe(true) |
| 74 | + }) |
| 75 | +}) |
0 commit comments