From 4296977fe3af16bb430bf9b83e63f74a65076d60 Mon Sep 17 00:00:00 2001 From: lucaronin Date: Wed, 27 May 2026 04:05:26 +0200 Subject: [PATCH] test: cover folder note creation event bridge --- src/hooks/useNoteCreation.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/hooks/useNoteCreation.test.ts b/src/hooks/useNoteCreation.test.ts index 268fa4e5..c820b842 100644 --- a/src/hooks/useNoteCreation.test.ts +++ b/src/hooks/useNoteCreation.test.ts @@ -18,6 +18,7 @@ import { useNoteCreation, } from './useNoteCreation' import type { NoteCreationConfig } from './useNoteCreation' +import { requestCreateNoteInFolder } from './noteCreationRequests' vi.mock('@tauri-apps/api/core', () => ({ invoke: vi.fn() })) vi.mock('../mock-tauri', () => ({ @@ -390,6 +391,31 @@ describe('useNoteCreation hook', () => { vi.restoreAllMocks() }) + it('handles folder create requests from the folder tree event bridge', async () => { + vi.mocked(isTauri).mockReturnValue(true) + vi.mocked(invoke).mockResolvedValueOnce(undefined) + vi.spyOn(Date, 'now').mockReturnValue(1700000000000) + renderHook(() => useNoteCreation(makeConfig(), tabDeps)) + + await act(async () => { + requestCreateNoteInFolder('Projects/2026 Planning', '/Users/luca/Team') + await flushImmediateCreate() + }) + + const createdPath = '/Users/luca/Team/Projects/2026 Planning/untitled-note-1700000000.md' + expect(vi.mocked(invoke)).toHaveBeenCalledWith('create_note_content', { + path: createdPath, + content: expect.stringContaining('type: Note'), + vaultPath: '/Users/luca/Team', + }) + expect(openTabWithContent).toHaveBeenCalledWith( + expect.objectContaining({ path: createdPath }), + expect.stringContaining('type: Note'), + ) + expect(addEntry).toHaveBeenCalledWith(expect.objectContaining({ path: createdPath })) + vi.restoreAllMocks() + }) + it('handleCreateNoteImmediate generates unique names on rapid calls via timestamp', async () => { vi.useFakeTimers() let ts = 1700000000000