Files
iven 803464b492
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
test(admin-v2): Phase 2 frontend tests — 61 tests for 5 pages
- Billing (13 tests): plan cards, prices, limits, usage bars, payment flow
- ScheduledTasks (16 tests): CRUD table, schedule/target types, color tags
- Knowledge (12 tests): 4 tabs, items/categories/search/analytics panels
- Roles (12 tests): roles + permission templates tabs
- ConfigSync (8 tests): sync log viewer with action labels

Fix: Knowledge.tsx missing </Select> and </Modal> closing tags (JSX parse error)
Fix: tests/setup.ts added ResizeObserver mock for ProTable compatibility
2026-04-07 16:06:47 +08:00

51 lines
1.5 KiB
TypeScript

// ============================================================
// Test setup: globals, jsdom polyfills, localStorage mock
// ============================================================
import { beforeAll, beforeEach, vi } from 'vitest'
import '@testing-library/jest-dom/vitest'
// ── localStorage mock (jsdom provides one but we ensure clean state) ──────
beforeEach(() => {
localStorage.clear()
})
// ── Ant Design / rc-util requires matchMedia ──────────────────────────────
beforeAll(() => {
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
})
// Ant Design's scrollTo polyfill
window.scrollTo = vi.fn()
// React 19 + jsdom: ensure getComputedStyle returns something useful
const originalGetComputedStyle = window.getComputedStyle
window.getComputedStyle = (elt: Element, pseudoElt?: string | null) => {
try {
return originalGetComputedStyle(elt, pseudoElt)
} catch {
return {} as CSSStyleDeclaration
}
}
// Ant Design ProTable / rc-virtual-list require ResizeObserver
global.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
})