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.
This commit is contained in:
2025-10-20 09:41:55 -04:00
parent b047e4d7d2
commit 3082a6d23a

View File

@@ -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);