- 新增 jsdom + @testing-library/react 组件测试环境 - 新增 12 个组件测试,覆盖所有前端组件 - 补充后端 middleware 和 helpers 单元测试 - 删除伪测试 use-target-detail-logic.test.ts - 精简过度枚举的 color-threshold.test.ts - 新增 bunfig.toml 配置测试 preload - 更新 DEVELOPMENT.md 测试章节 - 安装 @types/jsdom 修复类型声明
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import "../../../tests/web/test-utils";
|
|
import { render } from "@testing-library/react";
|
|
import { describe, expect, test } from "bun:test";
|
|
|
|
import type { TrendPoint } from "../../../src/shared/api";
|
|
|
|
import { TrendChart } from "../../../src/web/components/TrendChart";
|
|
|
|
describe("TrendChart", () => {
|
|
const data: TrendPoint[] = [
|
|
{
|
|
availability: 100,
|
|
avgDurationMs: 100,
|
|
bucketStart: "2025-01-15T10:00:00.000Z",
|
|
downChecks: 0,
|
|
maxDurationMs: 150,
|
|
minDurationMs: 50,
|
|
totalChecks: 10,
|
|
upChecks: 10,
|
|
},
|
|
{
|
|
availability: 95,
|
|
avgDurationMs: 120,
|
|
bucketStart: "2025-01-15T11:00:00.000Z",
|
|
downChecks: 1,
|
|
maxDurationMs: 200,
|
|
minDurationMs: 80,
|
|
totalChecks: 20,
|
|
upChecks: 19,
|
|
},
|
|
];
|
|
|
|
test("有数据时不崩溃", () => {
|
|
const { container } = render(<TrendChart data={data} />);
|
|
|
|
expect(container.firstChild).not.toBeNull();
|
|
});
|
|
|
|
test("空数据显示占位", () => {
|
|
const { container } = render(<TrendChart data={[]} />);
|
|
|
|
// 应该显示占位文本
|
|
const element = container.querySelector(".trend-empty");
|
|
expect(element).not.toBeNull();
|
|
});
|
|
|
|
test("包含 trend-chart className", () => {
|
|
const { container } = render(<TrendChart data={data} />);
|
|
|
|
const element = container.querySelector(".trend-chart");
|
|
expect(element).not.toBeNull();
|
|
});
|
|
});
|