import { describe, it, expect, jest } from '@jest/globals'; import { render, screen } from '@testing-library/react'; import '@testing-library/jest-dom'; // ─── Mocks ─────────────────────────────────────────────────────────────── jest.mock('framer-motion', () => ({ motion: { div: ({ children, initial, animate, variants, whileInView, whileHover, whileTap, viewport, transition, className, onMouseMove, onMouseEnter, onMouseLeave, style, ref, ...props }: any) => (
{children}
), p: ({ children, className, ...props }: any) => (

{children}

), h1: ({ children, className, ...props }: any) => (

{children}

), span: ({ children, className, ...props }: any) => ( {children} ), button: ({ children, onClick, className, ...props }: any) => ( ), }, useInView: jest.fn(() => true), AnimatePresence: ({ children }: any) => <>{children}, })); jest.mock('@/hooks/use-reduced-motion', () => ({ useReducedMotion: jest.fn(() => false), })); jest.mock('@/components/ui/static-link', () => ({ StaticLink: ({ children, href, className, onClick, ...props }: any) => ( {children} ), })); jest.mock('@/components/ui/button', () => ({ Button: ({ children, size, variant, className, ...props }: any) => ( ), })); jest.mock('@/components/ui/brand-visuals', () => ({ BrandStamp: ({ children }: { children: React.ReactNode }) => ( {children} ), })); jest.mock('next/link', () => ({ __esModule: true, default: ({ children, href, className, ...props }: any) => ( {children} ), })); jest.mock('lucide-react', () => { const mockIcon = (name: string) => { const Icon = (props: any) => ; Icon.displayName = name; return Icon; }; return { ArrowRight: mockIcon('arrow-right'), MessageSquare: mockIcon('message-square'), Search: mockIcon('search'), Rocket: mockIcon('rocket'), Handshake: mockIcon('handshake'), Sparkles: mockIcon('sparkles'), MessageCircle: mockIcon('message-circle'), Clock: mockIcon('clock'), ShieldCheck: mockIcon('shield-check'), }; }); // ─── Tests ────────────────────────────────────────────────────────────── describe('SectionHeader', () => { it('should render label, title, and description', async () => { const { SectionHeader } = await import('./section-header'); render(); expect(screen.getByText('TEST')).toBeInTheDocument(); expect(screen.getByText('Test Title')).toBeInTheDocument(); expect(screen.getByText('Test description')).toBeInTheDocument(); }); it('should render highlighted text', async () => { const { SectionHeader } = await import('./section-header'); render(); expect(screen.getByText('World')).toBeInTheDocument(); }); it('should apply light mode', async () => { const { SectionHeader } = await import('./section-header'); render(); const heading = screen.getByText('Title'); // Light mode: white text (rendered as rgb) expect(heading.closest('h2')?.style.color).toBe('rgb(255, 255, 255)'); }); it('washes the description white on dark sections and keeps it muted on light ones', async () => { const { SectionHeader } = await import('./section-header'); const { unmount } = render(); expect(screen.getByText('深色底的说明文字').style.color).toBe('rgba(255, 255, 255, 0.5)'); unmount(); render(); expect(screen.getByText('浅色底的说明文字').style.color).toBe('var(--color-text-muted)'); }); it('should apply custom className', async () => { const { SectionHeader } = await import('./section-header'); render(); // SectionHeader has multiple motion.div elements, find the first/outer one const elements = screen.getAllByTestId('motion-div'); const outer = elements.find(el => el.className.includes('my-class')); expect(outer).toBeTruthy(); }); it('should render without description when not provided', async () => { const { SectionHeader } = await import('./section-header'); const { container } = render(); // There should be no

element for description const paragraphs = container.querySelectorAll('p'); expect(paragraphs.length).toBe(0); }); }); describe('ProductCard', () => { it('should render title, description and icon', async () => { const { ProductCard } = await import('./product-card'); render( ★} title="ERP 系统" description="企业资源管理系统" href="/products/erp" /> ); expect(screen.getByText('ERP 系统')).toBeInTheDocument(); expect(screen.getByText('企业资源管理系统')).toBeInTheDocument(); expect(screen.getByTestId('custom-icon')).toBeInTheDocument(); expect(screen.getByTestId('static-link')).toHaveAttribute('href', '/products/erp'); }); it('should render badge when provided', async () => { const { ProductCard } = await import('./product-card'); render( ★} title="ERP" description="Desc" href="/products/erp" badge="新版本" /> ); expect(screen.getByText('新版本')).toBeInTheDocument(); }); it('should render "了解更多" link', async () => { const { ProductCard } = await import('./product-card'); render( ★} title="ERP" description="Desc" href="/products/erp" /> ); expect(screen.getByText('了解更多')).toBeInTheDocument(); }); it('should apply custom className', async () => { const { ProductCard } = await import('./product-card'); render( ★} title="ERP" description="Desc" href="/products/erp" className="card-class" /> ); const link = screen.getByTestId('static-link'); expect(link.className).toContain('card-class'); }); }); describe('ServiceCard', () => { it('should render title, description and link', async () => { const { ServiceCard } = await import('./service-card'); render( ); expect(screen.getByText('战略咨询')).toBeInTheDocument(); expect(screen.getByText('业务诊断与战略规划')).toBeInTheDocument(); expect(screen.getByText('了解详情')).toBeInTheDocument(); expect(screen.getByTestId('next-link')).toHaveAttribute('href', '/services/consulting'); }); it('should apply custom className', async () => { const { ServiceCard } = await import('./service-card'); render( ); const elements = screen.getAllByTestId('motion-div'); const target = elements.find(el => el.className.includes('service-class')); expect(target).toBeTruthy(); }); it('should accept optional number and color props for compatibility', async () => { const { ServiceCard } = await import('./service-card'); render( ); // ServiceCard has multiple motion.div elements, use getAllByTestId const elements = screen.getAllByTestId('motion-div'); expect(elements.length).toBeGreaterThan(0); }); }); describe('CTASection', () => { it('should render default content', async () => { const { CTASection } = await import('./cta-section'); render(); expect(screen.getByText('一起聊聊您的数字化需求')).toBeInTheDocument(); expect(screen.getByText('预约咨询')).toBeInTheDocument(); }); it('should render custom title and description', async () => { const { CTASection } = await import('./cta-section'); render( ); expect(screen.getByText('Custom Title')).toBeInTheDocument(); expect(screen.getByText('Custom description')).toBeInTheDocument(); expect(screen.getByText('Get Started')).toBeInTheDocument(); expect(screen.getByText('Learn More')).toBeInTheDocument(); }); it('should have proper links', async () => { const { CTASection } = await import('./cta-section'); render(); const links = screen.getAllByTestId('static-link'); expect(links.length).toBeGreaterThan(0); }); it('should render brand stamp', async () => { const { CTASection } = await import('./cta-section'); render(); expect(screen.getByTestId('brand-stamp')).toBeInTheDocument(); }); }); // HeroSectionV2 的三个用例随组件本体一同删除(2026-10-16): // 该组件全站零生产引用(仅被本测试文件 dynamic import),属 qa-tracker DEC-P-2 死码族。 // 保留测试会让死码继续占用覆盖率分母,并在视觉上被误读为「有活在跑」。