import { ProgressBar } from "@chopin/visuals"; import type { ProgressBarProps } from "@chopin/visuals"; import { expect, test } from "bun:test"; import { renderToStaticMarkup } from "react-dom/server"; test("exports ProgressBar and its props from the public package entry", () => { let props: ProgressBarProps = { label: "Upload progress", value: 42 }; expect(typeof ProgressBar).toBe("function"); expect(props.value).toBe(42); }); test("renders an authoritative accessible shell and forwards span props", () => { let markup = renderToStaticMarkup( , ); expect(markup.startsWith("42%'); expect(markup.match(/aria-hidden="true"/g)).toHaveLength(3); }); test("normalizes every numeric input without emitting invalid progress values", () => { let cases = [ [42, 42], [37.5, 37.5], [0, 0], [100, 100], [-1, 0], [101, 100], [Number.MAX_VALUE, 100], [-Number.MAX_VALUE, 0], [Number.NaN, 0], [Number.POSITIVE_INFINITY, 0], [Number.NEGATIVE_INFINITY, 0], ] as const; for (let [value, normalized] of cases) { let markup = renderToStaticMarkup( , ); expect(markup).toContain(`aria-valuenow="${normalized}"`); expect(markup).toContain(`style="width:${normalized}%"`); expect(markup).toContain(`class="cv-progress-bar-value">${normalized}%`); expect(markup).not.toMatch(/NaN|Infinity/); } }); test("uses only existing tokens for the compact progress treatment", async () => { let css = await Bun.file(new URL("./progress-bar.css", import.meta.url)).text(); let styles = await Bun.file(new URL("../styles.css", import.meta.url)).text(); expect(styles).toContain('@import "./ui/progress-bar.css";'); expect(css).toContain("width: calc(var(--spacing) * 17);"); expect(css).toContain("height: calc(var(--spacing) * 2.5);"); expect(css).toContain("overflow: hidden;"); expect(css).toContain("border-radius: var(--radius-xl);"); expect(css).toContain("background: var(--color-brand);"); expect(css).toContain("font-size: var(--text-sm);"); expect(css).toContain("line-height: var(--text-sm--line-height);"); expect(css).toContain("font-variant-numeric: tabular-nums;"); expect(css).not.toMatch(/#[\da-f]{3,8}|(?:oklch|rgb|hsl)\(/i); });