1
0

feat: 新增 target description 字段,收紧 id/name 长度,调整延迟列和名称列

This commit is contained in:
2026-05-17 18:42:46 +08:00
parent 7926514986
commit f7193e98ff
36 changed files with 385 additions and 58 deletions

View File

@@ -20,6 +20,7 @@ function getColumn(columns: Array<PrimaryTableCol<TargetStatus>>, colKey: string
function makeTarget(overrides: Partial<TargetStatus> = {}): TargetStatus {
return {
currentStreak: null,
description: null,
group: "default",
id: "1",
interval: "5s",
@@ -119,7 +120,40 @@ describe("createTargetTableColumns", () => {
rowIndex: 0,
});
expect(element.props.children).toBe("9999+ms");
expect(element.props.children).toBe("9999+");
expect(element.props.className).toContain("latency-value");
});
test("延迟列标题为 延迟(ms)", () => {
const latencyColumn = getColumn(createTargetTableColumns(["http"]), "latestCheck.durationMs");
expect(latencyColumn.title).toBe("延迟(ms)");
});
test("延迟列正常值不包含 ms 单位", () => {
const latencyColumn = getColumn(createTargetTableColumns(["http"]), "latestCheck.durationMs");
const renderCell = latencyColumn.cell as (params: PrimaryTableCellParams<TargetStatus>) => {
props: { children: string; className: string };
};
const element = renderCell({
col: latencyColumn,
colIndex: 6,
row: makeTarget({
latestCheck: {
durationMs: 123,
failure: null,
matched: true,
statusDetail: "200",
timestamp: "2026-01-01T00:00:00.000Z",
},
}),
rowIndex: 0,
});
expect(element.props.children).toBe("123");
});
test("名称列无排序配置", () => {
const nameColumn = getColumn(createTargetTableColumns(["http"]), "name");
expect(nameColumn.sorter).toBeUndefined();
expect(nameColumn.sortType).toBeUndefined();
});
});

View File

@@ -2,16 +2,12 @@ import { describe, expect, test } from "bun:test";
import type { TargetStatus } from "../../../src/shared/api";
import {
availabilitySorter,
latencySorter,
nameSorter,
statusSorter,
} from "../../../src/web/constants/target-table-sorters";
import { availabilitySorter, latencySorter, statusSorter } from "../../../src/web/constants/target-table-sorters";
function makeTarget(overrides: Partial<TargetStatus> = {}): TargetStatus {
return {
currentStreak: null,
description: null,
group: "default",
id: "1",
interval: "5s",
@@ -97,18 +93,3 @@ describe("latencySorter", () => {
expect(latencySorter(noLatency, hasLatency)).toBeGreaterThan(0);
});
});
describe("nameSorter", () => {
test("按名称字母排序", () => {
const a = makeTarget({ name: "Alpha" });
const b = makeTarget({ name: "Beta" });
expect(nameSorter(a, b)).toBeLessThan(0);
});
test("中文名称排序", () => {
const a = makeTarget({ name: "百度" });
const b = makeTarget({ name: "谷歌" });
const result = nameSorter(a, b);
expect(typeof result).toBe("number");
});
});