1
0

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:
2026-05-15 18:31:33 +08:00
parent 2b08f81a0d
commit 8793fbd786
24 changed files with 1392 additions and 143 deletions

View File

@@ -1,81 +0,0 @@
import { describe, expect, test } from "bun:test";
function shouldEnableHistory(
selectedTargetId: null | number,
timeFrom: string,
timeTo: string,
activeTab: string,
): boolean {
return selectedTargetId !== null && !!timeFrom && !!timeTo && activeTab === "history";
}
function shouldEnableMetrics(selectedTargetId: null | number, timeFrom: string, timeTo: string): boolean {
return selectedTargetId !== null && !!timeFrom && !!timeTo;
}
describe("metrics enabled 条件", () => {
test("未选中目标时不启用", () => {
expect(shouldEnableMetrics(null, "", "")).toBe(false);
});
test("选中目标但无时间范围时不启用", () => {
expect(shouldEnableMetrics(1, "", "")).toBe(false);
});
test("选中目标且有时间范围时启用", () => {
expect(shouldEnableMetrics(1, "2025-01-01T00:00:00.000Z", "2025-01-02T00:00:00.000Z")).toBe(true);
});
});
describe("history enabled 条件", () => {
test("未选中目标时不启用", () => {
expect(shouldEnableHistory(null, "from", "to", "history")).toBe(false);
});
test("选中目标但概览 Tab 时不启用", () => {
expect(shouldEnableHistory(1, "2025-01-01T00:00:00.000Z", "2025-01-02T00:00:00.000Z", "overview")).toBe(false);
});
test("选中目标且记录 Tab 激活但无时间范围时不启用", () => {
expect(shouldEnableHistory(1, "", "", "history")).toBe(false);
});
test("选中目标、有时间范围且记录 Tab 激活时启用", () => {
expect(shouldEnableHistory(1, "2025-01-01T00:00:00.000Z", "2025-01-02T00:00:00.000Z", "history")).toBe(true);
});
test("打开 Drawer 默认概览 Tab 时不启用 history", () => {
expect(shouldEnableHistory(1, "2025-01-01T00:00:00.000Z", "2025-01-02T00:00:00.000Z", "overview")).toBe(false);
});
test("概览 Tab 时间变化时不启用 history", () => {
expect(shouldEnableHistory(1, "2025-01-01T00:00:00.000Z", "2025-01-02T00:00:00.000Z", "overview")).toBe(false);
});
test("记录 Tab 时间变化时启用 history", () => {
expect(shouldEnableHistory(1, "2025-01-01T00:00:00.000Z", "2025-01-02T00:00:00.000Z", "history")).toBe(true);
});
});
describe("默认概览 Tab 行为", () => {
test("打开 Drawer 时 activeTab 应为 overview", () => {
const resetTab = "overview";
expect(resetTab).toBe("overview");
});
test("切换目标时 activeTab 应重置为 overview", () => {
const previousTab = "history";
const resetTab = "overview";
expect(previousTab).not.toBe(resetTab);
expect(resetTab).toBe("overview");
});
});
describe("history 页码重置", () => {
test("时间变化时 historyPage 应重置为 1", () => {
const previousPage = 3;
const resetPage = 1;
expect(previousPage).not.toBe(resetPage);
expect(resetPage).toBe(1);
});
});