feat: 增加测试覆盖率并优化代码质量

test: 添加单元测试和端到端测试
refactor: 重构登录页面和上传模块
ci: 更新测试覆盖率阈值至42%
build: 添加测试相关依赖
docs: 更新测试文档
style: 修复代码格式问题
This commit is contained in:
张翔
2026-03-11 11:14:37 +08:00
parent 8fd7ed84ed
commit b207bfa7af
58 changed files with 14494 additions and 655 deletions
+160
View File
@@ -0,0 +1,160 @@
import { describe, it, expect, jest, beforeAll } from '@jest/globals';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
jest.mock('framer-motion', () => ({
motion: {
div: ({ children, className, ...props }: any) => (
<div className={className} {...props}>
{children}
</div>
),
section: ({ children, className, ...props }: any) => (
<section className={className} {...props}>
{children}
</section>
),
span: ({ children, className, ...props }: any) => (
<span className={className} {...props}>
{children}
</span>
),
h1: ({ children, className, ...props }: any) => (
<h1 className={className} {...props}>
{children}
</h1>
),
h2: ({ children, className, ...props }: any) => (
<h2 className={className} {...props}>
{children}
</h2>
),
},
AnimatePresence: ({ children }: any) => <>{children}</>,
useInView: () => [null, true],
}));
jest.mock('next/link', () => {
return ({ children, href, ...props }: any) => (
<a href={href} {...props}>
{children}
</a>
);
});
jest.mock('lucide-react', () => ({
Lightbulb: () => <span data-testid="lightbulb-icon" />,
Users: () => <span data-testid="users-icon" />,
Target: () => <span data-testid="target-icon" />,
Award: () => <span data-testid="award-icon" />,
MapPin: () => <span data-testid="map-pin-icon" />,
Mail: () => <span data-testid="mail-icon" />,
Phone: () => <span data-testid="phone-icon" />,
}));
jest.mock('@/components/ui/card', () => ({
Card: ({ children, className, ...props }: any) => (
<div className={className} {...props}>
{children}
</div>
),
CardContent: ({ children, className, ...props }: any) => (
<div className={className} {...props}>
{children}
</div>
),
}));
jest.mock('@/components/ui/page-header', () => ({
PageHeader: ({ title, description }: any) => (
<header>
<h1>{title}</h1>
<p>{description}</p>
</header>
),
}));
jest.mock('@/components/ui/flip-clock', () => ({
FlipClock: ({ years, months, days }: any) => (
<div data-testid="flip-clock">
{years}年 {months}月 {days}天
</div>
),
}));
jest.mock('@/lib/constants', () => ({
COMPANY_INFO: {
name: '四川睿新致远科技有限公司',
shortName: '睿新致遠',
description: '以智慧连接数字趋势,以伙伴身份陪您成长',
address: '四川省成都市龙泉驿区',
email: 'contact@ruixin.com',
phone: '028-12345678',
},
STATS: [
{ value: '10+', label: '企业客户' },
{ value: '20+', label: '成功案例' },
{ value: '30+', label: '项目交付' },
{ value: '12+', label: '年行业经验' },
],
}));
import AboutPage from './page';
describe('AboutPage', () => {
beforeEach(() => {
jest.clearAllMocks();
});
describe('Rendering', () => {
it('should render about page', () => {
const { container } = render(<AboutPage />);
const pageContainer = container.querySelector('.min-h-screen');
expect(pageContainer).toBeInTheDocument();
});
it('should render company introduction', () => {
render(<AboutPage />);
const intro = screen.getByText(/关于我们/i);
expect(intro).toBeInTheDocument();
});
it('should render company history', () => {
render(<AboutPage />);
const history = screen.getByText(/发展历程/i);
expect(history).toBeInTheDocument();
});
it('should render company culture', () => {
render(<AboutPage />);
const culture = screen.getByText(/核心价值观/i);
expect(culture).toBeInTheDocument();
});
it('should render team members', () => {
render(<AboutPage />);
const team = screen.getByText(/团队组建/i);
expect(team).toBeInTheDocument();
});
it('should render contact information', () => {
render(<AboutPage />);
const contact = screen.getByText(/联系我们/i);
expect(contact).toBeInTheDocument();
});
it('should render statistics', () => {
render(<AboutPage />);
const stats = screen.getByText(/企业客户/i);
expect(stats).toBeInTheDocument();
});
});
describe('Accessibility', () => {
it('should have proper heading hierarchy', () => {
render(<AboutPage />);
const h1 = screen.getByRole('heading', { level: 1 });
expect(h1).toBeInTheDocument();
});
});
});