import { describe, expect, test } from "bun:test"; import { renderToStaticMarkup } from "react-dom/server"; import { DisabledReason } from "./disabled-reason"; import { ErrorMessage } from "./error-message"; import { InlineHelp } from "./inline-help"; import { sparklinePoints, StatTile } from "./stat-tile"; describe("DisabledReason", () => { test("keeps the control focusable and links the reason", () => { const html = renderToStaticMarkup( , ); expect(html).toContain('aria-disabled="true"'); expect(html).not.toMatch(/]* disabled=""/); const describedBy = html.match(/aria-describedby="([^"]+)"/)?.[1]; expect(describedBy).toBeTruthy(); expect(html).toContain(`id="${describedBy}"`); expect(html).toContain("Only organization admins can invite people."); }); test("keeps an existing description", () => { const html = renderToStaticMarkup( , ); expect(html).toMatch(/aria-describedby="hint [^"]+"/); }); test("renders the control untouched when enabled", () => { const html = renderToStaticMarkup( , ); expect(html).toBe(''); }); }); describe("ErrorMessage", () => { const reference = "4b1d7e2a-93c5-4f08-b6de-2a91c0f7e5d3"; test("keeps the reference out of the message and in Technical details", () => { const html = renderToStaticMarkup( , ); const [message] = html.split("Technical details"); expect(message).not.toContain(reference); expect(html).toContain('aria-expanded="false"'); expect(html).toMatch(/]*hidden=""/); expect(html).toContain(reference); expect(html).toContain('aria-label="Copy reference"'); }); test("only announces when asked", () => { expect(renderToStaticMarkup()).not.toContain("role="); expect(renderToStaticMarkup()).toContain( 'role="alert"', ); }); test("has no Technical details without facts", () => { expect( renderToStaticMarkup(), ).not.toContain("Technical details"); }); }); describe("StatTile", () => { test("sparkline points fill the box, flat series sit in the middle", () => { expect(sparklinePoints([])).toBe(""); expect(sparklinePoints([1, 3])).toBe("0,30 100,2"); expect(sparklinePoints([5, 5, 5])).toBe("0,16 50,16 100,16"); expect(sparklinePoints([7])).toBe("50,16"); }); test("the trend is spoken, not only drawn", () => { const html = renderToStaticMarkup( , ); expect(html).toContain('Down '); expect(html).toContain("text-status-idle"); expect(html).toContain("vs previous 7 days"); }); test("empty and loading states replace the value", () => { expect(renderToStaticMarkup()).toContain( "No runs yet", ); const loading = renderToStaticMarkup(); expect(loading).toContain('aria-busy="true"'); expect(loading).not.toContain("1,284"); }); }); describe("InlineHelp", () => { test("is one muted line", () => { const html = renderToStaticMarkup(People come from Acme Robotics.); expect(html).toMatch(/^