firstsun-dev_git-files-sync/tests/setup.ts
ClaudiaFang c107979427 feat(settings): add folder picker for root path and vault folder settings
Attach an AbstractInputSuggest to the "Root path" and "Vault folder"
text inputs so typing shows a filtered dropdown of existing vault
folders, sourced from app.vault.getAllFolders(). Selecting a suggestion
fills the field and dispatches an input event so the existing
onChange/save/initializeGitService flow still fires. Free typing is
still accepted for paths that don't exist yet (e.g. a not-yet-created
repo subfolder for "Root path").

Closes #48

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BNWwPd5zudtW2JQr6ZAUm
2026-07-13 12:51:32 +00:00

87 lines
1.7 KiB
TypeScript

import { vi } from 'vitest';
// Mock global browser environment if not in JSDOM
if (typeof document === 'undefined') {
(globalThis as unknown as { document: unknown }).document = {
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
};
}
if (typeof window === 'undefined') {
(globalThis as unknown as { window: unknown }).window = {
setInterval: vi.fn(),
clearInterval: vi.fn(),
};
}
// Mock Obsidian API components
export const Plugin = class {};
export const PluginSettingTab = class {
constructor() {}
};
export const Setting = class {
constructor() {}
setName() { return this; }
setDesc() { return this; }
addText() { return this; }
addToggle() { return this; }
addButton() { return this; }
};
export const Notice = class {
constructor() {}
};
export const Modal = class {
constructor() {}
open() {}
close() {}
};
export const MarkdownView = class {};
export const Editor = class {};
export const App = class {
workspace = {
getActiveViewOfType: vi.fn(),
on: vi.fn(),
};
vault = {
read: vi.fn(),
modify: vi.fn(),
getFileByPath: vi.fn(),
on: vi.fn(),
adapter: {
getBasePath: vi.fn().mockReturnValue('/mock/path'),
},
};
};
export const TFile = class {};
export const TFolder = class {};
export const AbstractInputSuggest = class {
app: unknown;
constructor(app: unknown) {
this.app = app;
}
setValue() {}
getValue() { return ''; }
close() {}
open() {}
};
export const requestUrl = vi.fn();
export const setTooltip = vi.fn();
export const setIcon = vi.fn();
vi.mock('obsidian', () => ({
Plugin,
PluginSettingTab,
Setting,
Notice,
Modal,
MarkdownView,
Editor,
App,
TFile,
TFolder,
AbstractInputSuggest,
requestUrl,
setTooltip,
setIcon,
}));