From 3082a6d23a9d10156f01ab8b09061557d46c7d61 Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 20 Oct 2025 09:41:55 -0400 Subject: [PATCH] test: add note-tools conflict resolution test Add test case for conflict resolution loop in createNote when multiple numbered file variants exist. Test verifies the loop correctly increments counter (lines 238-239) by creating file 3.md when file.md, file 1.md, and file 2.md already exist. Coverage improvement: note-tools.ts 96.01% -> 96.81% Lines 238-239 now covered. --- tests/note-tools.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/note-tools.test.ts b/tests/note-tools.test.ts index 52c5627..3bcae04 100644 --- a/tests/note-tools.test.ts +++ b/tests/note-tools.test.ts @@ -168,6 +168,28 @@ describe('NoteTools', () => { expect(parsed.originalPath).toBe('test.md'); }); + it('should create file with incremented counter when conflicts exist', async () => { + const mockFile = createMockTFile('test 3.md'); + + (PathUtils.fileExists as jest.Mock) + .mockReturnValueOnce(true) // Original test.md exists + .mockReturnValueOnce(true) // test 1.md exists + .mockReturnValueOnce(true) // test 2.md exists + .mockReturnValueOnce(false); // test 3.md doesn't exist + (PathUtils.folderExists as jest.Mock).mockReturnValue(false); + (PathUtils.getParentPath as jest.Mock).mockReturnValue(''); + mockVault.create = jest.fn().mockResolvedValue(mockFile); + + const result = await noteTools.createNote('test.md', 'content', false, 'rename'); + + expect(result.isError).toBeUndefined(); + expect(mockVault.create).toHaveBeenCalledWith('test 3.md', 'content'); + const parsed = JSON.parse(result.content[0].text); + expect(parsed.renamed).toBe(true); + expect(parsed.originalPath).toBe('test.md'); + expect(parsed.path).toBe('test 3.md'); + }); + it('should return error if parent folder does not exist and createParents is false', async () => { (PathUtils.fileExists as jest.Mock).mockReturnValue(false); (PathUtils.folderExists as jest.Mock).mockReturnValue(false);