1
0
Files
DiAL/tests/web/components/TargetGroup.test.tsx
lanyuanxiaoyao 375dd3492b feat: 结构化 observation 替代 statusDetail,API 层动态构造 detail
- CheckResult: statusDetail -> observation (持久化) + detail (API 动态派生)
- 存储: status_detail 列 -> observation TEXT (JSON)
- CheckerDefinition: 新增 buildDetail(observation) 方法
- 各 checker 返回结构化 observation,API 层通过 registry 调用 buildDetail
- HTTP: bodyPreview 在 status/header 失败时也提前采集
- UDP: observation 包含 durationMs,未响应归为 error failure
- CMD: 超时/输出超限时保留已收集 observation
- TCP: connectTimeMs 仅含连接建立耗时,不含 banner 等待
- 新增 buildDetail 单测和 mapCheckResult 覆盖测试
- 同步 openspec 主规范,归档 checker-observation 变更
2026-05-19 22:49:00 +08:00

81 lines
2.3 KiB
TypeScript

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 { TargetGroup } from "../../../src/web/components/TargetGroup";
describe("TargetGroup", () => {
const columns = [
{ colKey: "name", title: "名称" },
{ colKey: "target", title: "目标" },
];
const targets: TargetStatus[] = [
{
currentStreak: null,
description: null,
group: "default",
id: "1",
interval: "30s",
latestCheck: {
detail: "200 OK",
durationMs: 100,
failure: null,
matched: true,
observation: null,
timestamp: "2025-01-15T10:00:00.000Z",
},
name: "target-1",
recentSamples: [],
stats: { availability: 100, downChecks: 0, totalChecks: 10, upChecks: 10 },
target: "https://example.com",
type: "http",
},
{
currentStreak: null,
description: null,
group: "default",
id: "2",
interval: "30s",
latestCheck: {
detail: "500 Internal Server Error",
durationMs: 100,
failure: { kind: "error", message: "Failed", path: "$", phase: "status" },
matched: false,
observation: null,
timestamp: "2025-01-15T10:00:00.000Z",
},
name: "target-2",
recentSamples: [],
stats: { availability: 50, downChecks: 1, totalChecks: 2, upChecks: 1 },
target: "https://example.org",
type: "http",
},
];
const onTargetClick = vi.fn();
test("default 分组不崩溃", () => {
const { container } = render(
<TargetGroup columns={columns} name="default" onTargetClick={onTargetClick} targets={targets} />,
);
expect(container.firstChild).not.toBeNull();
});
test("非 default 分组不崩溃", () => {
const { container } = render(
<TargetGroup columns={columns} name="production" onTargetClick={onTargetClick} targets={targets} />,
);
expect(container.firstChild).not.toBeNull();
});
test("空 targets 不崩溃", () => {
const { container } = render(
<TargetGroup columns={columns} name="default" onTargetClick={onTargetClick} targets={[]} />,
);
expect(container.firstChild).not.toBeNull();
});
});