feat: 增加测试覆盖率并优化代码质量
test: 添加单元测试和端到端测试 refactor: 重构登录页面和上传模块 ci: 更新测试覆盖率阈值至42% build: 添加测试相关依赖 docs: 更新测试文档 style: 修复代码格式问题
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { Breadcrumb } from './breadcrumb';
|
||||
|
||||
jest.mock('next/link', () => {
|
||||
return ({ children, href }: { children: React.ReactNode; href: string }) => {
|
||||
return <a href={href}>{children}</a>;
|
||||
};
|
||||
});
|
||||
|
||||
describe('Breadcrumb', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Rendering', () => {
|
||||
it('should render breadcrumb component', () => {
|
||||
render(<Breadcrumb items={[]} />);
|
||||
const nav = screen.getByRole('navigation', { name: /breadcrumb/i });
|
||||
expect(nav).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render home link', () => {
|
||||
render(<Breadcrumb items={[]} />);
|
||||
const homeLinks = screen.getAllByRole('link');
|
||||
expect(homeLinks.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should render breadcrumb items', () => {
|
||||
const items = [
|
||||
{ label: 'Products', href: '/products' },
|
||||
{ label: 'Details', href: '/products/1' },
|
||||
];
|
||||
|
||||
render(<Breadcrumb items={items} />);
|
||||
|
||||
const productLink = screen.getByRole('link', { name: /Products/i });
|
||||
const detailsLink = screen.getByRole('link', { name: /Details/i });
|
||||
|
||||
expect(productLink).toBeInTheDocument();
|
||||
expect(detailsLink).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Accessibility', () => {
|
||||
it('should have nav element with aria-label', () => {
|
||||
render(<Breadcrumb items={[]} />);
|
||||
const nav = screen.getByRole('navigation', { name: /breadcrumb/i });
|
||||
expect(nav).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user