import { health } from "@/lib/healthFixture"; import { diagnosticsBadge } from "./diagnosticsBadge"; test("a healthy box with nothing open wears no badge", () => { expect(diagnosticsBadge(health(), false)).toBeNull(); }); test("open episodes are the count, warnings and errors together", () => { const badge = diagnosticsBadge( health({ diagnostics: { state: "recording", active_warnings: 2, active_errors: 1 } }), false, ); expect(badge).toEqual({ text: "3", label: "3 active diagnostic events" }); }); /** Four digits of open episodes read as one number, grouped like every other count. */ test("a four-figure count is grouped", () => { const badge = diagnosticsBadge( health({ diagnostics: { state: "recording", active_warnings: 1200, active_errors: 34 } }), false, ); expect(badge).toEqual({ text: "1,234", label: "1,234 active diagnostic events" }); }); test("one open episode is counted in the singular", () => { const badge = diagnosticsBadge( health({ diagnostics: { state: "recording", active_warnings: 0, active_errors: 1 } }), false, ); expect(badge).toEqual({ text: "1", label: "1 active diagnostic event" }); }); test("a degraded rollup with no open episode still shows, so no degraded state is invisible", () => { const badge = diagnosticsBadge(health({ status: "degraded" }), false); expect(badge).toEqual({ text: "!", label: "Health degraded" }); }); test("a failed poll is not evidence of health, badge and all", () => { // Cached body says everything is fine; the poll that would have confirmed it // never landed. An unbadged item here claims health on no evidence. expect(diagnosticsBadge(health(), true)).toEqual({ text: "!", label: "Health unavailable" }); expect(diagnosticsBadge(undefined, true)).toEqual({ text: "!", label: "Health unavailable" }); }); test("the first poll being in flight is the one unknown that hides", () => { expect(diagnosticsBadge(undefined, false)).toBeNull(); });