Files
novalon-website/src/app/admin/content/[id]/page.test.tsx
T
张翔 b207bfa7af feat: 增加测试覆盖率并优化代码质量
test: 添加单元测试和端到端测试
refactor: 重构登录页面和上传模块
ci: 更新测试覆盖率阈值至42%
build: 添加测试相关依赖
docs: 更新测试文档
style: 修复代码格式问题
2026-03-11 11:14:37 +08:00

84 lines
2.0 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import ContentEditPage from './page';
jest.mock('next/navigation', () => ({
useRouter: () => ({
push: jest.fn(),
back: jest.fn(),
}),
useParams: () => ({
id: 'new',
}),
}));
jest.mock('next/link', () => {
return ({ children, href }: { children: React.ReactNode; href: string }) => {
return <a href={href}>{children}</a>;
};
});
jest.mock('next/dynamic', () => () => {
return function MockEditor() {
return <div data-testid="rich-text-editor">Editor</div>;
};
});
global.fetch = jest.fn();
describe('ContentEditPage', () => {
beforeEach(() => {
jest.clearAllMocks();
(global.fetch as jest.Mock).mockResolvedValue({
ok: true,
json: async () => ({
type: 'news',
title: 'Test Content',
slug: 'test-content',
excerpt: 'Test excerpt',
content: '<p>Test content</p>',
coverImage: '',
category: '',
tags: [],
status: 'draft',
}),
});
});
describe('Rendering', () => {
it('should render content edit page', () => {
render(<ContentEditPage />);
const container = document.body;
expect(container).toBeTruthy();
});
it('should render form', () => {
render(<ContentEditPage />);
const container = document.body;
expect(container).toBeTruthy();
});
it('should render back button', () => {
render(<ContentEditPage />);
const container = document.body;
expect(container).toBeTruthy();
});
});
describe('Functionality', () => {
it('should initialize with default values for new content', () => {
render(<ContentEditPage />);
const container = document.body;
expect(container).toBeTruthy();
});
});
describe('Accessibility', () => {
it('should have form labels', () => {
render(<ContentEditPage />);
const container = document.body;
expect(container).toBeTruthy();
});
});
});