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:
33
tests/web/components/SummaryCards.test.tsx
Normal file
33
tests/web/components/SummaryCards.test.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import "../../../tests/web/test-utils";
|
||||
import { render } from "@testing-library/react";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import type { DashboardResponse } from "../../../src/shared/api";
|
||||
|
||||
import { SummaryCards } from "../../../src/web/components/SummaryCards";
|
||||
|
||||
describe("SummaryCards", () => {
|
||||
const summary: DashboardResponse["summary"] = {
|
||||
down: 2,
|
||||
incidents: 1,
|
||||
lastCheckTime: "2025-01-15T10:00:00.000Z",
|
||||
total: 10,
|
||||
up: 8,
|
||||
window: {
|
||||
from: "2025-01-14T10:00:00.000Z",
|
||||
label: "24h",
|
||||
to: "2025-01-15T10:00:00.000Z",
|
||||
},
|
||||
};
|
||||
|
||||
test("summary 为 null 时不渲染", () => {
|
||||
const { container } = render(<SummaryCards summary={null} />);
|
||||
|
||||
expect(container.firstChild).toBeNull();
|
||||
});
|
||||
|
||||
test("有数据不崩溃", () => {
|
||||
const { container } = render(<SummaryCards summary={summary} />);
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user