diff --git a/src/renderer/inbox/store.ts b/src/renderer/inbox/store.ts index bf88933..3cc22ae 100644 --- a/src/renderer/inbox/store.ts +++ b/src/renderer/inbox/store.ts @@ -10,6 +10,7 @@ interface InboxState { trashNotes: Note[]; trashCount: number; showTrash: boolean; + showSettings: boolean; continuity: WeeklyContinuity; pendingCount: number; ollamaStatus: { ok: boolean; reason?: string }; @@ -26,6 +27,7 @@ interface InboxState { upsertNote: (note: Note) => void; removeNote: (id: string) => void; setTagFilter: (tag: string | null) => void; + setShowSettings: (open: boolean) => void; toggleShowTrash: () => Promise; loadTrash: () => Promise; restoreNote: (id: string) => Promise; @@ -52,6 +54,7 @@ export const useInbox = create((set, get) => ({ trashNotes: [], trashCount: 0, showTrash: false, + showSettings: false, continuity: emptyContinuity, pendingCount: 0, ollamaStatus: { ok: true }, @@ -134,6 +137,9 @@ export const useInbox = create((set, get) => ({ setTagFilter(tag) { set({ tagFilter: tag }); }, + setShowSettings(open) { + set({ showSettings: open }); + }, async toggleShowTrash() { const next = !get().showTrash; set({ showTrash: next }); diff --git a/tests/unit/store.showSettings.test.ts b/tests/unit/store.showSettings.test.ts new file mode 100644 index 0000000..f7bbd9d --- /dev/null +++ b/tests/unit/store.showSettings.test.ts @@ -0,0 +1,65 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import type { Note } from '@shared/types'; + +const mockApi = { + listNotes: vi.fn(async () => [] as Note[]), + listTrash: vi.fn(async () => [] as Note[]), + getTrashCount: vi.fn(async () => 0), + getContinuity: vi.fn(async () => ({ weekStart: '', weekCount: 0, weekTarget: 7, consecutiveCompleteWeeks: 0, showRecoveryToast: false, lastNoteAt: null })), + getPendingCount: vi.fn(async () => 0), + getOllamaStatus: vi.fn(async () => ({ ok: true })), + getTodayCount: vi.fn(async () => 0), + getFailedCount: vi.fn(async () => 0), + listExpired: vi.fn(async () => [] as Note[]), + listRecallCandidate: vi.fn(async () => null), + restoreNote: vi.fn(async () => {}), + permanentDeleteNote: vi.fn(async () => ({ confirmed: true })), + emptyTrash: vi.fn(async () => ({ confirmed: true, count: 0 })), + trashExpiredBatch: vi.fn(async () => ({ confirmed: true, trashedCount: 0 })), + onNoteUpdated: vi.fn(() => () => {}), + updateAiFields: vi.fn(async () => {}), + setDueDate: vi.fn(async () => {}), + setIntent: vi.fn(async () => {}), + dismissIntent: vi.fn(async () => {}), + ollamaRecheck: vi.fn(async () => ({ ok: true })), + retryAllFailed: vi.fn(async () => {}), + markRecallOpened: vi.fn(async () => {}), + dismissRecall: vi.fn(async () => {}), + emitRecallSnoozed: vi.fn(async () => {}) +}; + +vi.mock('../../src/renderer/inbox/api.js', () => ({ inboxApi: mockApi })); + +describe('inbox store — showSettings', () => { + beforeEach(async () => { + const { useInbox } = await import('../../src/renderer/inbox/store.js'); + useInbox.setState({ + notes: [], trashNotes: [], trashCount: 0, showTrash: false, + loading: false, tagFilter: null, pendingCount: 0, todayCount: 0, + ollamaStatus: { ok: true }, + continuity: { weekStart: '', weekCount: 0, weekTarget: 7, consecutiveCompleteWeeks: 0, showRecoveryToast: false, lastNoteAt: null }, + expiredCandidates: [], expiredSnoozeUntilMs: null, + failedCount: 0, recallCandidate: null, recallSnoozeUntilMs: null, + showSettings: false + }); + Object.values(mockApi).forEach((fn) => 'mockClear' in fn && (fn as any).mockClear()); + }); + + it('initial state has showSettings=false', async () => { + const { useInbox } = await import('../../src/renderer/inbox/store.js'); + expect(useInbox.getState().showSettings).toBe(false); + }); + + it('setShowSettings(true) sets state', async () => { + const { useInbox } = await import('../../src/renderer/inbox/store.js'); + useInbox.getState().setShowSettings(true); + expect(useInbox.getState().showSettings).toBe(true); + }); + + it('setShowSettings(false) toggles back', async () => { + const { useInbox } = await import('../../src/renderer/inbox/store.js'); + useInbox.getState().setShowSettings(true); + useInbox.getState().setShowSettings(false); + expect(useInbox.getState().showSettings).toBe(false); + }); +});