- Raise use-swipe-gesture mutation score to 66.13% (target 65%+) - Maintain use-reduced-motion mutation score at 76.32% (target 50%+) - Fix use-reduced-motion.ts ESLint set-state-in-effect warning - Add UJ-10 deep searcher journey (category browse → article read → content discovery) - Add 40 new test files (analytics, detail, sections, ui, lib components) - Update test-strategy-plan.md to v2.0 (sync test count to 1591) - Sync README.md with final release metrics Quality gates: TS 0 errors, ESLint 0 errors, 121 suites / 1591 tests passed
154 lines
6.0 KiB
TypeScript
154 lines
6.0 KiB
TypeScript
// @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) => (
|
|
<div
|
|
data-testid="motion-div"
|
|
data-initial={JSON.stringify(initial)}
|
|
data-animate={JSON.stringify(animate)}
|
|
data-variants={JSON.stringify(variants)}
|
|
data-while-inview={JSON.stringify(whileInView)}
|
|
data-viewport={JSON.stringify(viewport)}
|
|
data-transition={JSON.stringify(transition)}
|
|
className={className}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</div>
|
|
),
|
|
},
|
|
useInView: jest.fn(() => true),
|
|
AnimatePresence: ({ children }: any) => <>{children}</>,
|
|
}));
|
|
|
|
jest.mock('next/link', () => ({
|
|
__esModule: true,
|
|
default: ({ children, href, className, ...props }: any) => (
|
|
<a href={href} className={className} data-testid="next-link" {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}));
|
|
|
|
jest.mock('next/image', () => ({
|
|
__esModule: true,
|
|
default: ({ src, alt, className, fill, ...props }: any) => (
|
|
<img
|
|
src={src}
|
|
alt={alt}
|
|
className={className}
|
|
data-fill={fill ? 'true' : undefined}
|
|
data-testid="next-image"
|
|
{...props}
|
|
/>
|
|
),
|
|
}));
|
|
|
|
jest.mock('lucide-react', () => ({
|
|
ArrowRight: (props: any) => <svg data-testid="icon-arrow-right" className={props.className} />,
|
|
CheckCircle2: (props: any) => <svg data-testid="icon-check-circle-2" className={props.className} />,
|
|
}));
|
|
|
|
// ─── 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(<ProductCard product={mockProduct} />);
|
|
expect(screen.getByText('ERP 企业资源管理系统')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should render product description', async () => {
|
|
const { ProductCard } = await import('./product-card');
|
|
render(<ProductCard product={mockProduct} />);
|
|
expect(
|
|
screen.getByText('覆盖企业全业务流程的数字化管理平台,实现财务、供应链、生产一体化管理')
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it('should render category badge', async () => {
|
|
const { ProductCard } = await import('./product-card');
|
|
render(<ProductCard product={mockProduct} />);
|
|
expect(screen.getByText('企业套装')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should render status badge when status is "已发布"', async () => {
|
|
const { ProductCard } = await import('./product-card');
|
|
render(<ProductCard product={mockProduct} />);
|
|
expect(screen.getByText('已发布')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should not render status badge when status is not "已发布"', async () => {
|
|
const { ProductCard } = await import('./product-card');
|
|
render(<ProductCard product={{ ...mockProduct, status: '研发中' }} />);
|
|
expect(screen.queryByText('已发布')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('should render product image', async () => {
|
|
const { ProductCard } = await import('./product-card');
|
|
render(<ProductCard product={mockProduct} />);
|
|
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(<ProductCard product={mockProduct} />);
|
|
expect(screen.getByText('财务管理')).toBeInTheDocument();
|
|
expect(screen.getByText('供应链管理')).toBeInTheDocument();
|
|
expect(screen.getByText('人力资源管理')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should render "了解详情" link', async () => {
|
|
const { ProductCard } = await import('./product-card');
|
|
render(<ProductCard product={mockProduct} />);
|
|
expect(screen.getByText('了解详情')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should link to correct product page', async () => {
|
|
const { ProductCard } = await import('./product-card');
|
|
render(<ProductCard product={mockProduct} />);
|
|
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(
|
|
<ProductCard product={{ ...mockProduct, features: [] }} />
|
|
);
|
|
// 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(
|
|
<ProductCard product={{ ...mockProduct, features: undefined }} />
|
|
);
|
|
expect(screen.getByText('ERP 企业资源管理系统')).toBeInTheDocument();
|
|
});
|
|
}); |