Files
obsidian-remarkable/tests/obsidian-mock.ts
T
fegger ff21ec921a Add test script and initial test suite
The test runner bundles TypeScript tests with esbuild and executes them using Node's built-in test runner. Tests cover
document downloader behavior, path utilities, rmapi bridge configuration, style refinement, and ZIP file handling. Mock
implementations for Obsidian plugin interfaces enable isolated unit testing.
2026-05-31 16:33:30 +02:00

94 lines
1.7 KiB
TypeScript

export class Notice {
static messages: Array<{ message: string; timeout?: number }> = [];
constructor(message: string, timeout?: number) {
Notice.messages.push({ message, timeout });
}
}
export class Plugin {
app: any;
constructor(app?: any) {
this.app = app;
}
async loadData(): Promise<any> {
return {};
}
async saveData(): Promise<void> {}
addRibbonIcon(): void {}
addCommand(): void {}
addSettingTab(): void {}
addStatusBarItem(): { setText: (text: string) => void } {
return { setText: () => {} };
}
registerInterval(): void {}
}
export class PluginSettingTab {
app: any;
plugin: any;
containerEl = {
empty: () => {},
createEl: () => {},
};
constructor(app: any, plugin: any) {
this.app = app;
this.plugin = plugin;
}
}
export class Setting {
constructor(_containerEl: any) {}
setName(): this {
return this;
}
setDesc(): this {
return this;
}
addText(callback: (text: any) => void): this {
callback(createTextControl());
return this;
}
addToggle(callback: (toggle: any) => void): this {
callback(createControl());
return this;
}
addDropdown(callback: (dropdown: any) => void): this {
callback({
...createControl(),
addOption: () => createControl(),
});
return this;
}
}
function createControl(): any {
const control: any = {
inputEl: {},
setValue: () => control,
onChange: () => control,
addOption: () => control,
};
return control;
}
function createTextControl(): any {
const control = createControl();
control.inputEl = {};
return control;
}
export function normalizePath(path: string): string {
return path.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\.\//, "");
}