firstsun-dev_git-files-sync/tests/setup.ts
ClaudiaFang a77e0150a1 test(ui): add interaction tests for ActionBar, FileListItem, and DiffPanel
Adds comprehensive UI component test coverage with 54 new test cases across three components to close issue #23. Includes JSDOM setup polyfills and tooltip mock utilities for DOM-dependent component testing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 05:25:13 +00:00

72 lines
1.5 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 requestUrl = vi.fn();
export const setTooltip = vi.fn();
vi.mock('obsidian', () => ({
Plugin,
PluginSettingTab,
Setting,
Notice,
Modal,
MarkdownView,
Editor,
App,
TFile,
requestUrl,
setTooltip,
}));