- 新增顶层 variables 段支持 string/number/boolean 字面量
- target 字符串字段支持 、、{...} 转义语法
- 变量解析优先级: variables -> process.env -> 默认值 -> 报错
- 完整引用保留原始类型,部分引用拼接为字符串
- 变量替换在 YAML 解析后、AJV 校验前执行
- 替换仅作用于 targets,跳过 id/type 字段
- target 新增必填 id 字段作为唯一标识,name 改为可选展示名称
- 数据库存储/API/前端全面迁移到 id 标识
- 统一 checker 运行时类型检查为 es-toolkit predicates
- 同步 delta specs 到主 specs,归档 config-variables 变更
77 lines
2.2 KiB
TypeScript
77 lines
2.2 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,
|
|
group: "default",
|
|
id: "1",
|
|
interval: "30s",
|
|
latestCheck: {
|
|
durationMs: 100,
|
|
failure: null,
|
|
matched: true,
|
|
statusDetail: "200 OK",
|
|
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,
|
|
group: "default",
|
|
id: "2",
|
|
interval: "30s",
|
|
latestCheck: {
|
|
durationMs: 100,
|
|
failure: { kind: "error", message: "Failed", path: "$", phase: "status" },
|
|
matched: false,
|
|
statusDetail: "500 Internal Server Error",
|
|
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();
|
|
});
|
|
});
|