9ff6b8985c
- 创建 CLAUDE.md 项目开发指导文档 - 提取公共常量到 components/constants.ts - 修复 TimestampToDatetime 重复插件扩展问题 - 修复 DatetimeToTimestamp 时区解析问题 - 优化 RoutePersistence 移除不必要依赖 - 添加 Vitest 测试框架配置 - 为所有组件编写单元测试 (16个测试用例) - 更新 .gitignore 忽略测试结果目录 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import { TimestampExecution } from '../TimestampExecution';
|
|
import { vi } from 'vitest';
|
|
|
|
describe('TimestampExecution', () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it('应该正确渲染组件', () => {
|
|
render(<TimestampExecution />);
|
|
expect(screen.getByText('切换单位')).toBeInTheDocument();
|
|
expect(screen.getByText('复制')).toBeInTheDocument();
|
|
expect(screen.getByText('停止')).toBeInTheDocument();
|
|
});
|
|
|
|
it('初始状态应该显示毫秒单位', () => {
|
|
render(<TimestampExecution />);
|
|
expect(screen.getByText('毫秒')).toBeInTheDocument();
|
|
});
|
|
|
|
it('点击切换单位按钮应该切换为秒显示', () => {
|
|
render(<TimestampExecution />);
|
|
const toggleUnitButton = screen.getByText('切换单位');
|
|
fireEvent.click(toggleUnitButton);
|
|
expect(screen.getByText('秒')).toBeInTheDocument();
|
|
});
|
|
|
|
it('点击停止按钮应该停止时间戳自动更新', () => {
|
|
render(<TimestampExecution />);
|
|
const toggleButton = screen.getByText('停止');
|
|
fireEvent.click(toggleButton);
|
|
expect(screen.getByText('开始')).toBeInTheDocument();
|
|
});
|
|
});
|