TEST-FE-CAL-001 add calendar frontend tests
This commit is contained in:
56
src/test/setup.ts
Normal file
56
src/test/setup.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import '@testing-library/jest-dom'
|
||||
import { vi } from 'vitest'
|
||||
|
||||
// Mock localStorage
|
||||
const localStorageMock = {
|
||||
getItem: vi.fn((key: string) => {
|
||||
if (key === 'token') return 'mock-token'
|
||||
if (key === 'HF_BACKEND_BASE_URL') return 'http://localhost:8000'
|
||||
return null
|
||||
}),
|
||||
setItem: vi.fn(),
|
||||
removeItem: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
}
|
||||
vi.stubGlobal('localStorage', localStorageMock)
|
||||
|
||||
// Mock window.location
|
||||
delete window.location
|
||||
window.location = Object.defineProperties({}, {
|
||||
pathname: { value: '/calendar', writable: true },
|
||||
href: { value: 'http://localhost/calendar', writable: true },
|
||||
assign: { value: vi.fn(), writable: true },
|
||||
replace: { value: vi.fn(), writable: true },
|
||||
}) as any
|
||||
|
||||
// Mock matchMedia
|
||||
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(),
|
||||
})),
|
||||
})
|
||||
|
||||
// Mock ResizeObserver
|
||||
class ResizeObserverMock {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
}
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverMock)
|
||||
|
||||
// Mock IntersectionObserver
|
||||
class IntersectionObserverMock {
|
||||
constructor() {}
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
}
|
||||
vi.stubGlobal('IntersectionObserver', IntersectionObserverMock)
|
||||
Reference in New Issue
Block a user