import type { AttentionSummary, Decision } from "@umt/contracts"; import { describe, expect, it } from "vitest"; import { approvalHref, HEALTH_HREF } from "../console/inbox-bell.tsx"; import { attentionRows } from "./attention-summary.tsx"; // 首页 / 运行状态的「需要关注」汇总计数与铃铛跳转(2026-10-06 去掉待处理中心后)。 const id = (n: number) => `00000000-0000-4000-8000-${String(n).padStart(12, "0")}`; const dec = (n: number, over: Partial): Decision => ({ id: id(n), kind: "other", status: "open", severity: "warning", title: "t", summary: null, subjectType: null, subjectId: null, dedupeKey: `k${n}`, evidence: {}, options: [], resolution: null, taskId: null, agentRunId: null, attempts: 0, nextReviewAt: null, resolvedBy: null, resolvedAt: null, createdAt: "2026-10-06T00:00:00.000Z", updatedAt: "2026-10-06T00:00:00.000Z", ...over, }) as Decision; const empty: AttentionSummary = { organize: 0, approvals: { total: 0, items: [] }, health: { total: 0, items: [] } }; describe("需要关注汇总", () => { it("只列非零项", () => { expect(attentionRows(empty)).toEqual([]); expect(attentionRows(undefined)).toEqual([]); }); it("整理需要处理 / 等你批准 / 系统健康按问题归类,点进去到对应页面", () => { const rows = attentionRows({ organize: 3, approvals: { total: 1, items: [dec(1, { kind: "approval_required", subjectType: "agent_run", subjectId: id(9) })], }, health: { total: 3, items: [ dec(2, { kind: "source_unreachable" }), dec(3, { kind: "downloader_offline" }), dec(4, { kind: "other", dedupeKey: "library_root_offline:x" }), ], }, }); expect(rows.map((r) => [r.text, r.to])).toEqual([ ["3 条整理需要处理", "/console/organize?tab=records&attention=1"], ["1 个操作等你批准", `/console/agent/${id(9)}`], ["1 个站点不可达", HEALTH_HREF], ["1 个下载器离线", HEALTH_HREF], ["1 个媒体库目录离线", HEALTH_HREF], ]); }); it("健康问题超过列出的条数时补一行", () => { const rows = attentionRows({ ...empty, health: { total: 5, items: [dec(2, { kind: "space_insufficient" })] } }); expect(rows.map((r) => r.text)).toEqual(["1 个下载盘空间不足", "4 个系统问题"]); }); }); describe("铃铛跳转", () => { it("智能体会话 / 下载计划 / 下载任务", () => { expect(approvalHref({ subjectType: "agent_run", subjectId: id(1), agentRunId: null })).toBe( `/console/agent/${id(1)}`, ); expect(approvalHref({ subjectType: "acquisition_plan", subjectId: id(2), agentRunId: null })).toBe( `/console/downloads?plan=${id(2)}`, ); expect(approvalHref({ subjectType: "download_task", subjectId: id(3), agentRunId: null })).toBe( `/console/downloads?open=${id(3)}`, ); expect(approvalHref({ subjectType: null, subjectId: null, agentRunId: null })).toBe("/console/agent"); expect(HEALTH_HREF).toBe("/console/status#attention"); }); });