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:
55
tests/web/components/TargetBoard.test.tsx
Normal file
55
tests/web/components/TargetBoard.test.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
import "../../../tests/web/test-utils";
|
||||
import { render } from "@testing-library/react";
|
||||
import { describe, expect, test, vi } from "bun:test";
|
||||
|
||||
import type { TargetStatus } from "../../../src/shared/api";
|
||||
|
||||
import { TargetBoard } from "../../../src/web/components/TargetBoard";
|
||||
|
||||
// Mock useMeta hook
|
||||
void vi.mock("../../../src/web/hooks/use-queries", () => ({
|
||||
useMeta: () => ({
|
||||
data: { checkerTypes: ["http", "cmd"] },
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("TargetBoard", () => {
|
||||
const onTargetClick = vi.fn();
|
||||
|
||||
const targets: TargetStatus[] = [
|
||||
{
|
||||
currentStreak: null,
|
||||
group: "default",
|
||||
id: 1,
|
||||
interval: "30s",
|
||||
latestCheck: null,
|
||||
name: "target-1",
|
||||
recentSamples: [],
|
||||
stats: { availability: 100, downChecks: 0, totalChecks: 0, upChecks: 0 },
|
||||
target: "https://example.com",
|
||||
type: "http",
|
||||
},
|
||||
{
|
||||
currentStreak: null,
|
||||
group: "production",
|
||||
id: 2,
|
||||
interval: "30s",
|
||||
latestCheck: null,
|
||||
name: "target-2",
|
||||
recentSamples: [],
|
||||
stats: { availability: 100, downChecks: 0, totalChecks: 0, upChecks: 0 },
|
||||
target: "https://example.org",
|
||||
type: "http",
|
||||
},
|
||||
];
|
||||
|
||||
test("有 targets 时不崩溃", () => {
|
||||
const { container } = render(<TargetBoard onTargetClick={onTargetClick} targets={targets} />);
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
|
||||
test("空 targets 列表不崩溃", () => {
|
||||
const { container } = render(<TargetBoard onTargetClick={onTargetClick} targets={[]} />);
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user