test: 重构测试体系 — 建立组件测试层、补充后端测试、清理低质量测试
- 新增 jsdom + @testing-library/react 组件测试环境 - 新增 12 个组件测试,覆盖所有前端组件 - 补充后端 middleware 和 helpers 单元测试 - 删除伪测试 use-target-detail-logic.test.ts - 精简过度枚举的 color-threshold.test.ts - 新增 bunfig.toml 配置测试 preload - 更新 DEVELOPMENT.md 测试章节 - 安装 @types/jsdom 修复类型声明
This commit is contained in:
64
tests/web/components/RefreshCountdown.test.tsx
Normal file
64
tests/web/components/RefreshCountdown.test.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import "../../../tests/web/test-utils";
|
||||
import { render } from "@testing-library/react";
|
||||
import { describe, expect, test, vi } from "bun:test";
|
||||
|
||||
import { RefreshCountdown } from "../../../src/web/components/RefreshCountdown";
|
||||
|
||||
describe("RefreshCountdown", () => {
|
||||
test("手动模式不崩溃", () => {
|
||||
const { container } = render(
|
||||
<RefreshCountdown
|
||||
dashboardUpdatedAt={0}
|
||||
isFetching={false}
|
||||
isManualRefresh={true}
|
||||
onRefresh={vi.fn()}
|
||||
refreshInterval={30000}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
|
||||
test("自动模式不崩溃", () => {
|
||||
const now = Date.now();
|
||||
const { container } = render(
|
||||
<RefreshCountdown
|
||||
dashboardUpdatedAt={now - 10000}
|
||||
isFetching={false}
|
||||
isManualRefresh={false}
|
||||
onRefresh={vi.fn()}
|
||||
refreshInterval={30000}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
|
||||
test("fetching 状态不崩溃", () => {
|
||||
const { container } = render(
|
||||
<RefreshCountdown
|
||||
dashboardUpdatedAt={1000}
|
||||
isFetching={true}
|
||||
isManualRefresh={false}
|
||||
onRefresh={vi.fn()}
|
||||
refreshInterval={30000}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
|
||||
test("未刷新状态不崩溃", () => {
|
||||
const { container } = render(
|
||||
<RefreshCountdown
|
||||
dashboardUpdatedAt={0}
|
||||
isFetching={false}
|
||||
isManualRefresh={false}
|
||||
onRefresh={vi.fn()}
|
||||
refreshInterval={30000}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user