import { describe, it, expect, jest, beforeAll, afterEach } from '@jest/globals'; import React from 'react'; import { render, screen, fireEvent, waitFor } from '@testing-library/react'; import '@testing-library/jest-dom'; import userEvent from '@testing-library/user-event'; interface MotionComponentProps { children?: React.ReactNode; className?: string; disabled?: boolean; [key: string]: unknown; } interface InputComponentProps { label?: string; id?: string; placeholder?: string; required?: boolean; value?: string; onChange?: (e: React.ChangeEvent) => void; onBlur?: () => void; error?: string; rows?: number; [key: string]: unknown; } interface ToastComponentProps { message?: string; type?: string; onClose?: () => void; [key: string]: unknown; } global.fetch = jest.fn(() => Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true }), } as Response) ); jest.mock('framer-motion', () => ({ motion: { div: ({ children, className, ...props }: MotionComponentProps) => (
{children}
), section: ({ children, className, ...props }: MotionComponentProps) => (
{children}
), }, AnimatePresence: ({ children }: MotionComponentProps) => <>{children}, })); jest.mock('lucide-react', () => ({ Mail: () => , Phone: () => , MapPin: () => , Send: () => , Loader2: () => , Clock: () => , HeadphonesIcon: () => , CheckCircle2: () => , RefreshCw: () => , })); jest.mock('@/lib/sanitize', () => ({ sanitizeInput: (value: string) => value, })); jest.mock('@/lib/csrf', () => ({ generateCSRFToken: jest.fn(() => 'test-csrf-token'), setCSRFTokenToStorage: jest.fn(), getCSRFTokenFromStorage: jest.fn(() => 'test-csrf-token'), })); const { generateCSRFToken, setCSRFTokenToStorage } = jest.requireMock('@/lib/csrf') as { generateCSRFToken: jest.Mock; setCSRFTokenToStorage: jest.Mock; }; jest.mock('@/lib/security/captcha', () => ({ generateCaptcha: jest.fn(() => ({ question: '1 + 1 = ?', answer: 2, hash: 'test-hash', timestamp: Date.now(), })), })); const { generateCaptcha } = jest.requireMock('@/lib/security/captcha') as { generateCaptcha: jest.Mock; }; jest.mock('@/lib/constants', () => ({ COMPANY_INFO: { name: '四川睿新致远科技有限公司', email: 'contact@novalon.cn', phone: '028-88888888', address: '中国四川省成都市龙泉驿区幸福路12号', }, })); jest.mock('@/components/ui/button', () => ({ Button: ({ children, className, disabled, ...props }: MotionComponentProps) => ( ), })); jest.mock('@/components/ui/input', () => ({ Input: ({ label, id, placeholder, required, value, onChange, onBlur, error, ...props }: InputComponentProps) => (
{error && {error}}
), })); jest.mock('@/components/ui/textarea', () => ({ Textarea: ({ label, id, placeholder, rows, required, value, onChange, onBlur, error, ...props }: InputComponentProps) => (