56 lines
2.6 KiB
TypeScript
56 lines
2.6 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
const mockApi = {
|
|
listNotes: vi.fn(async () => []),
|
|
listTrash: vi.fn(async () => []),
|
|
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),
|
|
restoreNote: vi.fn(async () => {}),
|
|
permanentDeleteNote: vi.fn(async () => ({ confirmed: true })),
|
|
emptyTrash: vi.fn(async () => ({ confirmed: true, count: 0 })),
|
|
deleteNote: vi.fn(async () => {}),
|
|
onNoteUpdated: vi.fn(() => () => {}),
|
|
updateAiFields: vi.fn(async () => {}),
|
|
setDueDate: vi.fn(async () => {}),
|
|
setIntent: vi.fn(async () => {}),
|
|
dismissIntent: vi.fn(async () => {}),
|
|
listExpired: vi.fn(async () => []),
|
|
trashExpiredBatch: vi.fn(async () => ({ trashedCount: 0, confirmed: false })),
|
|
ollamaRecheck: vi.fn(async (): Promise<{ ok: boolean; reason?: string }> => ({ ok: true })),
|
|
onOllamaStatus: vi.fn(() => () => {})
|
|
};
|
|
|
|
vi.mock('../../src/renderer/inbox/api.js', () => ({ inboxApi: mockApi }));
|
|
|
|
describe('useInbox — ollama (v0.2.3 #1)', () => {
|
|
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: false, reason: 'refused' },
|
|
continuity: { weekStart: '', weekCount: 0, weekTarget: 7, consecutiveCompleteWeeks: 0, showRecoveryToast: false, lastNoteAt: null },
|
|
expiredCandidates: [], expiredSnoozeUntilMs: null
|
|
});
|
|
Object.values(mockApi).forEach((fn) => 'mockClear' in fn && (fn as any).mockClear());
|
|
});
|
|
|
|
it('recheckOllama calls inboxApi.ollamaRecheck and updates ollamaStatus', async () => {
|
|
mockApi.ollamaRecheck.mockResolvedValueOnce({ ok: true });
|
|
const { useInbox } = await import('../../src/renderer/inbox/store.js');
|
|
await useInbox.getState().recheckOllama();
|
|
expect(mockApi.ollamaRecheck).toHaveBeenCalledTimes(1);
|
|
expect(useInbox.getState().ollamaStatus).toEqual({ ok: true });
|
|
});
|
|
|
|
it('recheckOllama propagates failure status', async () => {
|
|
mockApi.ollamaRecheck.mockResolvedValueOnce({ ok: false, reason: 'timeout' });
|
|
const { useInbox } = await import('../../src/renderer/inbox/store.js');
|
|
await useInbox.getState().recheckOllama();
|
|
expect(useInbox.getState().ollamaStatus).toEqual({ ok: false, reason: 'timeout' });
|
|
});
|
|
});
|