feat: 增加测试覆盖率并优化代码质量
test: 添加单元测试和端到端测试 refactor: 重构登录页面和上传模块 ci: 更新测试覆盖率阈值至42% build: 添加测试相关依赖 docs: 更新测试文档 style: 修复代码格式问题
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { CaseDetailClient } from './client';
|
||||
|
||||
jest.mock('next/navigation', () => ({
|
||||
useRouter: () => ({
|
||||
push: jest.fn(),
|
||||
back: jest.fn(),
|
||||
forward: jest.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('next/link', () => {
|
||||
return ({ children, href }: { children: React.ReactNode; href: string }) => {
|
||||
return <a href={href}>{children}</a>;
|
||||
};
|
||||
});
|
||||
|
||||
const mockCaseItem = {
|
||||
id: 'test-case',
|
||||
title: '测试案例标题',
|
||||
client: '测试客户',
|
||||
industry: '制造业',
|
||||
description: '这是一个测试案例的描述',
|
||||
results: [
|
||||
{ label: '业务处理效率', value: '提升50%' },
|
||||
{ label: '客户满意度', value: '提升30%' },
|
||||
],
|
||||
tags: ['AI', '大数据'],
|
||||
};
|
||||
|
||||
describe('CaseDetailClient', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Rendering', () => {
|
||||
it('should render case detail page', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const main = screen.getByRole('main');
|
||||
expect(main).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render case title', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const title = screen.getByRole('heading', { level: 1 });
|
||||
expect(title).toBeInTheDocument();
|
||||
expect(title).toHaveTextContent('测试案例标题');
|
||||
});
|
||||
|
||||
it('should render case client name', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const clients = screen.getAllByText('测试客户');
|
||||
expect(clients.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should render case industry badge', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const industries = screen.getAllByText('制造业');
|
||||
expect(industries.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should render case description', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const description = screen.getByText('这是一个测试案例的描述');
|
||||
expect(description).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render case results', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const result1 = screen.getByText('提升50%');
|
||||
const result2 = screen.getByText('提升30%');
|
||||
expect(result1).toBeInTheDocument();
|
||||
expect(result2).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render case tags', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const tags = screen.getAllByText('AI');
|
||||
expect(tags.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should render contact button', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const contactButton = screen.getByRole('link', { name: /联系我们/i });
|
||||
expect(contactButton).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Sections', () => {
|
||||
it('should render customer challenges section', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const section = screen.getByText('客户遇到的成长瓶颈');
|
||||
expect(section).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render solution section', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const section = screen.getByText('我们如何智连未来');
|
||||
expect(section).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render growth story section', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const section = screen.getByText('共同成长的故事');
|
||||
expect(section).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render achievements section', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const section = screen.getByText('今天,他们走到了哪里');
|
||||
expect(section).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render testimonial section', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const section = screen.getByText('客户证言精选');
|
||||
expect(section).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Navigation', () => {
|
||||
it('should have back button', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const backButton = screen.getByRole('button', { name: /返回/i });
|
||||
expect(backButton).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Accessibility', () => {
|
||||
it('should have main landmark', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const main = screen.getByRole('main');
|
||||
expect(main).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should have proper heading hierarchy', () => {
|
||||
render(<CaseDetailClient caseItem={mockCaseItem as any} />);
|
||||
const h1 = screen.getByRole('heading', { level: 1 });
|
||||
expect(h1).toBeInTheDocument();
|
||||
|
||||
const h2s = screen.getAllByRole('heading', { level: 2 });
|
||||
expect(h2s.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user