feat: more cleanup work in UI
This commit is contained in:
@@ -4,6 +4,88 @@
|
||||
*/
|
||||
|
||||
import { vi, beforeEach, afterEach } from 'vitest';
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
|
||||
// Mock localStorage for Zustand persist middleware
|
||||
const localStorageMock = (() => {
|
||||
let store: Record<string, string> = {};
|
||||
return {
|
||||
getItem: vi.fn((key: string) => store[key] || null),
|
||||
setItem: vi.fn((key: string, value: string) => {
|
||||
store[key] = value;
|
||||
}),
|
||||
removeItem: vi.fn((key: string) => {
|
||||
delete store[key];
|
||||
}),
|
||||
clear: vi.fn(() => {
|
||||
store = {};
|
||||
}),
|
||||
get length() {
|
||||
return Object.keys(store).length;
|
||||
},
|
||||
key: vi.fn((index: number) => Object.keys(store)[index] || null),
|
||||
};
|
||||
})();
|
||||
|
||||
Object.defineProperty(globalThis, 'localStorage', {
|
||||
value: localStorageMock,
|
||||
writable: true,
|
||||
});
|
||||
|
||||
// Mock window.electronAPI for renderer tests
|
||||
Object.defineProperty(globalThis, 'window', {
|
||||
value: {
|
||||
electronAPI: {
|
||||
posts: {
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
get: vi.fn(),
|
||||
getAll: vi.fn(),
|
||||
getByStatus: vi.fn(),
|
||||
publish: vi.fn(),
|
||||
unpublish: vi.fn(),
|
||||
rebuildFromFiles: vi.fn(),
|
||||
search: vi.fn(),
|
||||
filter: vi.fn(),
|
||||
getTags: vi.fn(),
|
||||
getCategories: vi.fn(),
|
||||
getByYearMonth: vi.fn(),
|
||||
getLinksTo: vi.fn(),
|
||||
getLinkedBy: vi.fn(),
|
||||
rebuildLinks: vi.fn(),
|
||||
},
|
||||
media: {
|
||||
import: vi.fn(),
|
||||
importDialog: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
get: vi.fn(),
|
||||
getAll: vi.fn(),
|
||||
rebuildFromFiles: vi.fn(),
|
||||
getThumbnail: vi.fn(),
|
||||
regenerateThumbnails: vi.fn(),
|
||||
},
|
||||
sync: {
|
||||
configure: vi.fn(),
|
||||
start: vi.fn(),
|
||||
getStatus: vi.fn(),
|
||||
isConfigured: vi.fn(),
|
||||
getPendingCount: vi.fn(),
|
||||
getLog: vi.fn(),
|
||||
stopAutoSync: vi.fn(),
|
||||
},
|
||||
tasks: {
|
||||
getAll: vi.fn(),
|
||||
getRunning: vi.fn(),
|
||||
cancel: vi.fn(),
|
||||
clearCompleted: vi.fn(),
|
||||
},
|
||||
on: vi.fn(() => () => {}),
|
||||
},
|
||||
},
|
||||
writable: true,
|
||||
});
|
||||
|
||||
// Mock Electron app module
|
||||
vi.mock('electron', () => ({
|
||||
|
||||
Reference in New Issue
Block a user