// Minimal Obsidian API mock for unit tests. // Surface area covers what the QoL modules need: BaseModule, PreserveLinkAliasesModule, etc. export class Plugin { // Intentionally minimal — tests supply their own `{}` when calling onunload. } export class TFile { name: string; path: string; basename: string; extension: string; constructor(path: string = '') { this.path = path; const lastSlash = path.lastIndexOf('/'); const fileName = lastSlash >= 0 ? path.slice(lastSlash + 1) : path; this.name = fileName; const dotIndex = fileName.lastIndexOf('.'); this.basename = dotIndex > 0 ? fileName.slice(0, dotIndex) : fileName; this.extension = dotIndex > 0 ? fileName.slice(dotIndex + 1) : ''; } } export class ToggleComponent { private value = false; setValue(value: boolean): this { this.value = value; return this; } onChange(_cb: (value: boolean) => unknown): this { return this; } } export class Setting { constructor(_containerEl: HTMLElement) {} setName(_name: string): this { return this; } setDesc(_desc: string): this { return this; } addToggle(cb: (toggle: ToggleComponent) => void): this { cb(new ToggleComponent()); return this; } } export class Vault { // Pre-loaded file lists for getMarkdownFiles() / getFiles(). mdFiles: TFile[] = []; allFiles: TFile[] = []; // In-memory storage backing read()/modify(). storage: Map = new Map(); // Recording for assertions. readCalls: TFile[] = []; modifyCalls: Array<{ file: TFile; content: string }> = []; // Listeners registered via on('rename', ...). private renameListeners: Array<(file: TFile, oldPath: string) => unknown> = []; on(event: string, cb: (file: TFile, oldPath: string) => unknown): unknown { if (event === 'rename') { this.renameListeners.push(cb); return { id: this.renameListeners.length }; } return null; } offref(_ref: unknown): void { // no-op } async read(file: TFile): Promise { this.readCalls.push(file); return this.storage.get(file) ?? ''; } async modify(file: TFile, content: string): Promise { this.modifyCalls.push({ file, content }); this.storage.set(file, content); } getMarkdownFiles(): TFile[] { return this.mdFiles; } getFiles(): TFile[] { return this.allFiles; } }