114 lines
2.0 KiB
TypeScript
Executable File
114 lines
2.0 KiB
TypeScript
Executable File
// Enhanced Obsidian mock for testing
|
|
|
|
// Mock Vault
|
|
export class Vault {
|
|
getMarkdownFiles: () => any[];
|
|
read: (file: any) => Promise<string>;
|
|
create: (path: string, content: string) => Promise<any>;
|
|
|
|
constructor() {
|
|
this.getMarkdownFiles = () => [];
|
|
this.read = async () => '';
|
|
this.create = async () => null;
|
|
}
|
|
}
|
|
|
|
// Mock Workspace
|
|
export class Workspace {
|
|
getLeaf: () => any;
|
|
|
|
constructor() {
|
|
this.getLeaf = () => ({
|
|
setViewState: jest.fn(),
|
|
revealLeaf: jest.fn(),
|
|
});
|
|
}
|
|
}
|
|
|
|
// Mock App
|
|
export class App {
|
|
vault: Vault;
|
|
workspace: Workspace;
|
|
|
|
constructor() {
|
|
this.vault = new Vault();
|
|
this.workspace = new Workspace();
|
|
}
|
|
}
|
|
|
|
// Mock WorkspaceLeaf
|
|
export class WorkspaceLeaf {
|
|
app: App;
|
|
view: any;
|
|
setViewState: jest.Mock;
|
|
|
|
constructor() {
|
|
this.app = new App();
|
|
this.view = null;
|
|
this.setViewState = jest.fn();
|
|
}
|
|
}
|
|
|
|
// Mock ItemView - accepts a leaf and derives app from it
|
|
export class ItemView {
|
|
contentEl: HTMLElement;
|
|
app: App;
|
|
|
|
constructor(leaf?: WorkspaceLeaf) {
|
|
this.contentEl = document.createElement('div');
|
|
if (leaf && leaf.app) {
|
|
this.app = leaf.app;
|
|
} else {
|
|
this.app = new App();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Mock Notice - can be called with `new Notice(msg)` or as a function
|
|
export class Notice {
|
|
message: string;
|
|
|
|
constructor(message: string) {
|
|
this.message = message;
|
|
// Also record via jest for testing
|
|
(Notice as any).lastMessage = message;
|
|
}
|
|
}
|
|
(Notice as any).lastMessage = '';
|
|
|
|
// Mock Setting
|
|
export class Setting {
|
|
containerEl: HTMLElement;
|
|
|
|
constructor(containerEl: HTMLElement) {
|
|
this.containerEl = containerEl;
|
|
}
|
|
|
|
setName(_name: string): this {
|
|
return this;
|
|
}
|
|
|
|
setDesc(_desc: string): this {
|
|
return this;
|
|
}
|
|
|
|
addText(_callback: (text: any) => void): this {
|
|
return this;
|
|
}
|
|
}
|
|
|
|
// TFile type
|
|
export interface TFile {
|
|
basename: string;
|
|
path: string;
|
|
}
|
|
|
|
// Plugin class (used by main.ts)
|
|
export class Plugin {
|
|
app: App;
|
|
|
|
constructor() {
|
|
this.app = new App();
|
|
}
|
|
}
|