Boilerplate derived from obsidianmd/obsidian-sample-plugin, adapted to mirror obsidian-plugin-auto-task-status: bun scripts, esbuild with git-tag versioning, prettier/eslint/jest, husky pre-commit, Forgejo CI/release workflows, and vault install/symlink helpers.
103 lines
2.4 KiB
TypeScript
103 lines
2.4 KiB
TypeScript
// Mock implementations for Obsidian API
|
|
export class MockedFunction extends Function {
|
|
mockResolvedValue = jest.fn().mockReturnThis();
|
|
mockRejectedValue = jest.fn().mockReturnThis();
|
|
mockReturnValue = jest.fn().mockReturnThis();
|
|
mockImplementation = jest.fn().mockReturnThis();
|
|
}
|
|
|
|
export class App {
|
|
vault = {
|
|
read: jest.fn().mockResolvedValue(''),
|
|
getMarkdownFiles: jest.fn().mockReturnValue([]),
|
|
on: jest.fn(),
|
|
};
|
|
|
|
workspace = {
|
|
on: jest.fn(),
|
|
getActiveFile: jest.fn(),
|
|
};
|
|
|
|
fileManager = {
|
|
processFrontMatter: jest.fn().mockResolvedValue(undefined),
|
|
};
|
|
|
|
keymap: any = {};
|
|
scope: any = {};
|
|
metadataCache: any = {};
|
|
lastEvent: any = null;
|
|
loadLocalStorage = jest.fn().mockReturnValue('{}');
|
|
saveLocalStorage = jest.fn();
|
|
}
|
|
|
|
export class Plugin {
|
|
app: App;
|
|
settings: any;
|
|
|
|
constructor(app: App, manifest: any) {
|
|
this.app = app;
|
|
}
|
|
|
|
loadData = jest.fn().mockResolvedValue({});
|
|
saveData = jest.fn().mockResolvedValue(undefined);
|
|
addCommand = jest.fn();
|
|
addSettingTab = jest.fn();
|
|
registerEvent = jest.fn();
|
|
}
|
|
|
|
export class PluginSettingTab {
|
|
app: App;
|
|
plugin: Plugin;
|
|
containerEl = {
|
|
empty: jest.fn(),
|
|
createEl: jest.fn().mockReturnValue({
|
|
createEl: jest.fn(),
|
|
}),
|
|
};
|
|
|
|
constructor(app: App, plugin: Plugin) {
|
|
this.app = app;
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
display = jest.fn();
|
|
}
|
|
|
|
export class Setting {
|
|
constructor(containerEl: any) {}
|
|
|
|
setName = jest.fn().mockReturnThis();
|
|
setDesc = jest.fn().mockReturnThis();
|
|
addText = jest.fn().mockReturnThis();
|
|
addToggle = jest.fn().mockReturnThis();
|
|
addTextArea = jest.fn().mockReturnThis();
|
|
addButton = jest.fn().mockReturnThis();
|
|
}
|
|
|
|
export class TFile {
|
|
path: string;
|
|
parent: any;
|
|
stat: any = { ctime: 0, mtime: 0, size: 0 };
|
|
basename: string;
|
|
extension: string;
|
|
vault: any = {};
|
|
name: string;
|
|
|
|
constructor(path: string = '', parent: any = null) {
|
|
this.path = path;
|
|
this.parent = parent;
|
|
this.name = path.split('/').pop() || '';
|
|
this.basename = this.name.replace(/\.[^/.]+$/, '');
|
|
this.extension = path.includes('.') ? path.split('.').pop() || '' : '';
|
|
}
|
|
}
|
|
|
|
export class Notice {
|
|
constructor(message: string) {}
|
|
hide = jest.fn();
|
|
}
|
|
|
|
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number, immediate?: boolean): T {
|
|
const mockFn = jest.fn(func) as any;
|
|
return mockFn;
|
|
}
|