将 type/configKey 从 "command" 统一为 "cmd",源码目录 runner/command/ → runner/cmd/, spec 目录 command-checker/ → cmd-checker/,测试全部改用 bun -e 替代 Unix 系统命令, 归档 cmd-checker-enhancement 变更并同步 delta spec 到主 spec。
85 lines
2.5 KiB
TypeScript
85 lines
2.5 KiB
TypeScript
import type { PrimaryTableCellParams, PrimaryTableCol } from "tdesign-react";
|
|
|
|
import { describe, expect, test } from "bun:test";
|
|
|
|
import type { TargetStatus } from "../../../src/shared/api";
|
|
|
|
import { createTargetTableColumns } from "../../../src/web/constants/target-table-columns";
|
|
|
|
interface TableFilter {
|
|
list?: Array<{ label: string; value: string }>;
|
|
type?: string;
|
|
}
|
|
|
|
function getColumn(columns: Array<PrimaryTableCol<TargetStatus>>, colKey: string): PrimaryTableCol<TargetStatus> {
|
|
const column = columns.find((item) => item.colKey === colKey);
|
|
expect(column).toBeDefined();
|
|
return column!;
|
|
}
|
|
|
|
function makeTarget(overrides: Partial<TargetStatus> = {}): TargetStatus {
|
|
return {
|
|
group: "default",
|
|
id: 1,
|
|
interval: "5s",
|
|
latestCheck: null,
|
|
name: "test",
|
|
recentSamples: [],
|
|
stats: { availability: 100, totalChecks: 0 },
|
|
target: "https://example.com",
|
|
type: "http",
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("createTargetTableColumns", () => {
|
|
test("生成 7 个目标表格列", () => {
|
|
const columns = createTargetTableColumns(["http", "cmd"]);
|
|
|
|
expect(columns.map((column) => column.colKey)).toEqual([
|
|
"latestCheck.matched",
|
|
"name",
|
|
"type",
|
|
"stats.availability",
|
|
"recentSamples",
|
|
"latestCheck.durationMs",
|
|
"interval",
|
|
]);
|
|
});
|
|
|
|
test("根据 checkerTypes 生成类型筛选器", () => {
|
|
const typeColumn = getColumn(createTargetTableColumns(["http", "cmd", "tcp"]), "type");
|
|
const filter = typeColumn.filter as TableFilter;
|
|
|
|
expect(filter.type).toBe("single");
|
|
expect(filter.list).toEqual([
|
|
{ label: "全部", value: "" },
|
|
{ label: "http", value: "http" },
|
|
{ label: "cmd", value: "cmd" },
|
|
{ label: "tcp", value: "tcp" },
|
|
]);
|
|
});
|
|
|
|
test("checkerTypes 为空时只保留全部选项", () => {
|
|
const typeColumn = getColumn(createTargetTableColumns([]), "type");
|
|
const filter = typeColumn.filter as TableFilter;
|
|
|
|
expect(filter.list).toEqual([{ label: "全部", value: "" }]);
|
|
});
|
|
|
|
test("类型列直接渲染原始 type 文本", () => {
|
|
const typeColumn = getColumn(createTargetTableColumns(["tcp"]), "type");
|
|
const renderCell = typeColumn.cell as (params: PrimaryTableCellParams<TargetStatus>) => {
|
|
props: { children: unknown };
|
|
};
|
|
const element = renderCell({
|
|
col: typeColumn,
|
|
colIndex: 2,
|
|
row: makeTarget({ type: "tcp" }),
|
|
rowIndex: 0,
|
|
});
|
|
|
|
expect(element.props.children).toBe("tcp");
|
|
});
|
|
});
|