import { describe, expect, test } from "bun:test"; import type { TargetStatus } from "../../../src/shared/api"; import { getTargetDisplayName } from "../../../src/web/utils/target"; function makeTarget(overrides: Partial = {}): TargetStatus { return { currentStreak: null, description: null, group: "default", id: "api-health", interval: "30s", latestCheck: null, name: null, recentSamples: [], stats: { availability: 100, downChecks: 0, totalChecks: 0, upChecks: 0 }, target: "https://example.com", type: "http", ...overrides, }; } describe("getTargetDisplayName", () => { test("name 为 null 时返回 id", () => { expect(getTargetDisplayName(makeTarget())).toBe("api-health"); }); test("name 有值时返回 name", () => { expect(getTargetDisplayName(makeTarget({ name: "我的 API" }))).toBe("我的 API"); }); });