test: comprehensive coverage for NoteTools

Add extensive test suite for note-tools.ts covering all major operations
and error paths. Improves statement coverage from 13.94% to 96.01%.

Tests added:
- readNote: success, errors, frontmatter parsing
- createNote: success, conflict strategies (error/overwrite/rename), parent folder creation
- updateNote: success, errors, waypoint protection
- deleteNote: soft/permanent delete, dry run, version checking
- renameFile: success, errors, version checking, parent folder creation
- readExcalidraw: success, non-Excalidraw files, errors
- updateFrontmatter: success, field removal, version checking
- updateSections: success, invalid ranges, version checking
- Path validation for all methods
- Empty path validation for all methods

Mock enhancements:
- Added modify, delete, trash methods to VaultAdapter mock
- Added parseYaml function to Obsidian mock for frontmatter testing

Coverage improvements for note-tools.ts:
- Statements: 13.94% -> 96.01% (+82.07%)
- Branches: 5.1% -> 88.44% (+83.34%)
- Functions: 27.27% -> 90.9% (+63.63%)
- Lines: 13.94% -> 96.4% (+82.46%)
This commit is contained in:
2025-10-20 00:13:03 -04:00
parent f5a671e625
commit 2e30b81f01
3 changed files with 922 additions and 0 deletions

View File

@@ -14,6 +14,9 @@ export function createMockVaultAdapter(overrides?: Partial<IVaultAdapter>): IVau
process: jest.fn(),
createFolder: jest.fn(),
create: jest.fn(),
modify: jest.fn(),
delete: jest.fn(),
trash: jest.fn(),
...overrides
};
}

View File

@@ -71,3 +71,29 @@ export class Plugin {}
export class Notice {}
export class PluginSettingTab {}
export class Setting {}
// Mock parseYaml function
export function parseYaml(yaml: string): any {
// Simple YAML parser mock for testing
const result: any = {};
const lines = yaml.split('\n');
for (const line of lines) {
if (line.trim() && !line.startsWith('#')) {
const colonIndex = line.indexOf(':');
if (colonIndex > 0) {
const key = line.substring(0, colonIndex).trim();
let value = line.substring(colonIndex + 1).trim();
// Handle arrays
if (value.startsWith('[') && value.endsWith(']')) {
value = value.slice(1, -1).split(',').map(v => v.trim());
}
result[key] = value;
}
}
}
return result;
}