// @ts-nocheck 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, viewport, transition, className, ...props }: any) => (
{children}
), }, useInView: jest.fn(() => true), AnimatePresence: ({ children }: any) => <>{children}, })); jest.mock('next/link', () => ({ __esModule: true, default: ({ children, href, className, ...props }: any) => ( {children} ), })); jest.mock('next/image', () => ({ __esModule: true, default: ({ src, alt, className, fill, ...props }: any) => ( {alt} ), })); jest.mock('lucide-react', () => ({ ArrowRight: (props: any) => , CheckCircle2: (props: any) => , })); // ─── Mock Data ──────────────────────────────────────────────────────────── const mockProduct = { id: 'erp', title: 'ERP 企业资源管理系统', description: '覆盖企业全业务流程的数字化管理平台,实现财务、供应链、生产一体化管理', image: '/images/products/erp.jpg', category: '企业套装', status: '已发布' as const, features: ['财务管理', '供应链管理', '人力资源管理'], }; // ─── Tests ─────────────────────────────────────────────────────────────── describe('ProductCard (detail)', () => { it('should render product title', async () => { const { ProductCard } = await import('./product-card'); render(); expect(screen.getByText('ERP 企业资源管理系统')).toBeInTheDocument(); }); it('should render product description', async () => { const { ProductCard } = await import('./product-card'); render(); expect( screen.getByText('覆盖企业全业务流程的数字化管理平台,实现财务、供应链、生产一体化管理') ).toBeInTheDocument(); }); it('should render category badge', async () => { const { ProductCard } = await import('./product-card'); render(); expect(screen.getByText('企业套装')).toBeInTheDocument(); }); it('should render status badge when status is "已发布"', async () => { const { ProductCard } = await import('./product-card'); render(); expect(screen.getByText('已发布')).toBeInTheDocument(); }); it('should not render status badge when status is not "已发布"', async () => { const { ProductCard } = await import('./product-card'); render(); expect(screen.queryByText('已发布')).not.toBeInTheDocument(); }); it('should render product image', async () => { const { ProductCard } = await import('./product-card'); render(); const img = screen.getByTestId('next-image'); expect(img).toHaveAttribute('src', '/images/products/erp.jpg'); expect(img).toHaveAttribute('alt', 'ERP 企业资源管理系统'); }); it('should render feature tags', async () => { const { ProductCard } = await import('./product-card'); render(); expect(screen.getByText('财务管理')).toBeInTheDocument(); expect(screen.getByText('供应链管理')).toBeInTheDocument(); expect(screen.getByText('人力资源管理')).toBeInTheDocument(); }); it('should render "了解详情" link', async () => { const { ProductCard } = await import('./product-card'); render(); expect(screen.getByText('了解详情')).toBeInTheDocument(); }); it('should link to correct product page', async () => { const { ProductCard } = await import('./product-card'); render(); const link = screen.getByTestId('next-link'); expect(link).toHaveAttribute('href', '/products/erp'); }); it('should render without features section when features is empty', async () => { const { ProductCard } = await import('./product-card'); render( ); // Should still render title and description expect(screen.getByText('ERP 企业资源管理系统')).toBeInTheDocument(); // Feature tags should not be present mockProduct.features.forEach((f) => { expect(screen.queryByText(f)).not.toBeInTheDocument(); }); }); it('should render without features section when features is undefined', async () => { const { ProductCard } = await import('./product-card'); render( ); expect(screen.getByText('ERP 企业资源管理系统')).toBeInTheDocument(); }); });