154 lines
3.2 KiB
JavaScript
154 lines
3.2 KiB
JavaScript
import '@testing-library/jest-dom'
|
|
|
|
// Mock Next.js navigation
|
|
jest.mock('@/components/navigation', () => ({
|
|
useRouter() {
|
|
return {
|
|
push: jest.fn(),
|
|
replace: jest.fn(),
|
|
prefetch: jest.fn(),
|
|
back: jest.fn(),
|
|
forward: jest.fn(),
|
|
refresh: jest.fn(),
|
|
}
|
|
},
|
|
usePathname() {
|
|
return '/'
|
|
},
|
|
Link: ({ children, href, ...props }) => (
|
|
<a href={href} {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
redirect: jest.fn(),
|
|
}))
|
|
|
|
// Mock next-intl
|
|
jest.mock('next-intl', () => ({
|
|
useTranslations: () => (key, options) => options?.defaultValue || key,
|
|
useLocale: () => 'en',
|
|
getTranslations: () => (key) => key,
|
|
}))
|
|
|
|
// Mock next-intl/navigation
|
|
jest.mock('next-intl/navigation', () => ({
|
|
createSharedPathnamesNavigation: () => ({
|
|
useRouter: () => ({
|
|
push: jest.fn(),
|
|
replace: jest.fn(),
|
|
prefetch: jest.fn(),
|
|
back: jest.fn(),
|
|
forward: jest.fn(),
|
|
refresh: jest.fn(),
|
|
}),
|
|
usePathname: () => '/',
|
|
Link: ({ children, href, ...props }) => (
|
|
<a href={href} {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
redirect: jest.fn(),
|
|
}),
|
|
}))
|
|
|
|
// Mock React Hook Form
|
|
jest.mock('react-hook-form', () => ({
|
|
useForm: () => ({
|
|
register: jest.fn(),
|
|
handleSubmit: (fn) => fn,
|
|
formState: { errors: {}, isSubmitting: false },
|
|
getValues: jest.fn(),
|
|
setValue: jest.fn(),
|
|
watch: jest.fn(),
|
|
reset: jest.fn(),
|
|
}),
|
|
}))
|
|
|
|
// Mock @hookform/resolvers
|
|
jest.mock('@hookform/resolvers/zod', () => ({
|
|
zodResolver: () => jest.fn(),
|
|
}))
|
|
|
|
// Mock sonner toast
|
|
jest.mock('sonner', () => ({
|
|
toast: {
|
|
error: jest.fn(),
|
|
success: jest.fn(),
|
|
info: jest.fn(),
|
|
warning: jest.fn(),
|
|
},
|
|
}))
|
|
|
|
// Mock window.location
|
|
delete window.location
|
|
window.location = {
|
|
href: 'http://localhost:3000',
|
|
assign: jest.fn(),
|
|
replace: jest.fn(),
|
|
reload: jest.fn(),
|
|
}
|
|
|
|
// Mock localStorage
|
|
const localStorageMock = {
|
|
getItem: jest.fn(),
|
|
setItem: jest.fn(),
|
|
removeItem: jest.fn(),
|
|
clear: jest.fn(),
|
|
}
|
|
global.localStorage = localStorageMock
|
|
|
|
// Mock sessionStorage
|
|
const sessionStorageMock = {
|
|
getItem: jest.fn(),
|
|
setItem: jest.fn(),
|
|
removeItem: jest.fn(),
|
|
clear: jest.fn(),
|
|
}
|
|
global.sessionStorage = sessionStorageMock
|
|
|
|
// Mock js-cookie
|
|
jest.mock('js-cookie', () => ({
|
|
get: jest.fn(),
|
|
set: jest.fn(),
|
|
remove: jest.fn(),
|
|
}))
|
|
|
|
// Mock window.matchMedia
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
writable: true,
|
|
value: jest.fn().mockImplementation(query => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: jest.fn(), // deprecated
|
|
removeListener: jest.fn(), // deprecated
|
|
addEventListener: jest.fn(),
|
|
removeEventListener: jest.fn(),
|
|
dispatchEvent: jest.fn(),
|
|
})),
|
|
})
|
|
|
|
// Mock ResizeObserver
|
|
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
observe: jest.fn(),
|
|
unobserve: jest.fn(),
|
|
disconnect: jest.fn(),
|
|
}))
|
|
|
|
// Mock IntersectionObserver
|
|
global.IntersectionObserver = jest.fn().mockImplementation(() => ({
|
|
observe: jest.fn(),
|
|
unobserve: jest.fn(),
|
|
disconnect: jest.fn(),
|
|
}))
|
|
|
|
// Mock Google Maps
|
|
global.google = {
|
|
maps: {
|
|
Map: jest.fn(),
|
|
Marker: jest.fn(),
|
|
places: {
|
|
Autocomplete: jest.fn(),
|
|
},
|
|
},
|
|
}
|