import { describe, it, expect, jest, beforeEach } from '@jest/globals'; import { render, screen, waitFor } from '@testing-library/react'; import '@testing-library/jest-dom'; jest.mock('framer-motion', () => ({ motion: { div: ({ children, className, ...props }: any) => (
{children}
), section: ({ children, className, ...props }: any) => (
{children}
), }, AnimatePresence: ({ children }: any) => <>{children}, useInView: () => [null, true], })); jest.mock('next/link', () => { return ({ children, href, ...props }: any) => ( {children} ); }); jest.mock('lucide-react', () => ({ ArrowRight: () => , ArrowLeft: () => , Code: () => , Cloud: () => , BarChart3: () => , Shield: () => , Search: () => , ChevronLeft: () => , ChevronRight: () => , Filter: () => , })); jest.mock('@/components/ui/button', () => ({ Button: ({ children, className, ...props }: any) => ( ), })); jest.mock('@/components/ui/badge', () => ({ Badge: ({ children, className, ...props }: any) => ( {children} ), })); jest.mock('@/components/ui/input', () => ({ Input: ({ className, ...props }: any) => ( ), })); jest.mock('@/components/ui/loading-skeleton', () => ({ ServiceCardSkeleton: () =>
Loading...
, })); jest.mock('@/components/ui/page-header', () => ({ PageHeader: ({ title, description }: any) => (

{title}

{description}

), })); const mockServices = [ { id: 'software-dev', title: '软件开发', icon: 'Code', description: '定制化软件开发服务', features: ['需求分析', '架构设计', '开发测试', '运维支持'], }, { id: 'cloud-service', title: '云服务', icon: 'Cloud', description: '企业云服务解决方案', features: ['云迁移', '云原生', '云安全', '云运维'], }, ]; jest.mock('@/hooks/use-services', () => ({ useServices: () => ({ services: mockServices, loading: false, error: null, }), })); import ServicesPage from './page'; describe('ServicesPage', () => { beforeEach(() => { jest.clearAllMocks(); }); describe('Rendering', () => { it('should render services page', async () => { const { container } = render(); await waitFor(() => { const pageContainer = container.querySelector('.min-h-screen'); expect(pageContainer).toBeInTheDocument(); }); }); it('should render page header', async () => { render(); await waitFor(() => { const title = screen.getByText(/核心业务/i); expect(title).toBeInTheDocument(); }); }); it('should render back to home link', async () => { render(); await waitFor(() => { const backLink = screen.getByText(/返回首页/i); expect(backLink).toBeInTheDocument(); }); }); it('should render loading skeletons initially', async () => { render(); await waitFor(() => { const pageContainer = screen.queryByText('加载中...'); expect(pageContainer).not.toBeInTheDocument(); }); }); it('should render CTA section', async () => { render(); await waitFor(() => { const cta = screen.getByText(/准备开始您的数字化转型之旅/i); expect(cta).toBeInTheDocument(); }); }); }); describe('Navigation', () => { it('should have contact link', async () => { render(); await waitFor(() => { const contactLink = screen.getByRole('link', { name: /立即咨询/i }); expect(contactLink).toHaveAttribute('href', '/contact'); }); }); }); describe('Accessibility', () => { it('should have proper heading hierarchy', async () => { render(); await waitFor(() => { const h1 = screen.getByRole('heading', { level: 1 }); expect(h1).toBeInTheDocument(); }); }); }); });