|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { buildReportLayout, type LayoutViewModel } from "./report-layout"; |
| 3 | +import { reportMessages } from "./report-messages"; |
| 4 | + |
| 5 | +const livenessMetric = { |
| 6 | + id: "liveness", |
| 7 | + value: 21 * 60 * 1000, |
| 8 | + unit: "ms" as const, |
| 9 | + severity: "crit" as const, |
| 10 | +}; |
| 11 | + |
| 12 | +function vmWith(findings: LayoutViewModel["findings"]): LayoutViewModel { |
| 13 | + return { |
| 14 | + title: "health", |
| 15 | + scope: "prod", |
| 16 | + period: "last 60 min", |
| 17 | + windowMinutes: 60, |
| 18 | + summary: { severity: "crit", statements: [] }, |
| 19 | + findings, |
| 20 | + metrics: [livenessMetric], |
| 21 | + footer: [], |
| 22 | + }; |
| 23 | +} |
| 24 | + |
| 25 | +const livenessFinding = { |
| 26 | + type: "liveness", |
| 27 | + severity: "crit" as const, |
| 28 | + reason: "stale", |
| 29 | + metricIds: ["liveness"], |
| 30 | +}; |
| 31 | + |
| 32 | +describe("buildReportLayout self-evident findings", () => { |
| 33 | + it("drops the metric row of a non-hero finding whose only metric is its own line", () => { |
| 34 | + const layout = buildReportLayout( |
| 35 | + vmWith([ |
| 36 | + { type: "execution", severity: "crit", reason: "failures_up", metricIds: [] }, |
| 37 | + livenessFinding, |
| 38 | + ]), |
| 39 | + reportMessages("health") |
| 40 | + ); |
| 41 | + |
| 42 | + const liveness = layout.findings.find((f) => f.type === "liveness"); |
| 43 | + expect(liveness?.text).toContain("no telemetry in 21m"); |
| 44 | + expect(liveness?.expanded).toBe(false); |
| 45 | + expect(liveness?.metrics).toEqual([]); |
| 46 | + }); |
| 47 | + |
| 48 | + it("keeps the metric row when that finding is the hero", () => { |
| 49 | + const layout = buildReportLayout(vmWith([livenessFinding]), reportMessages("health")); |
| 50 | + |
| 51 | + expect(layout.hero?.type).toBe("liveness"); |
| 52 | + expect(layout.hero?.expanded).toBe(true); |
| 53 | + expect(layout.hero?.metrics.map((m) => m.id)).toEqual(["liveness"]); |
| 54 | + }); |
| 55 | +}); |
0 commit comments