Files
HealthLog/src/components/labs/__tests__/lab-reference-range-bar.test.tsx
T
Marc-André Bombeck fe13fa966b fix(labs): print range bars and lab values in the reader's number format
Range bars and the lab list, detail rows, chart tooltip and reference
ranges printed numbers with a plain `String()`, so a German reader saw
"1.8 mIU/L" and "61.3 kg" under a German interface. The same was true
of the mean, GMI, eA1C and the advanced indices on the glucose panel.

`RangeBar` now prints value, bounds and delta through the locale number
formatter and takes an optional `formatValue` for surfaces with their
own precision. Lab values keep their trim rule (whole numbers bare, at
most two decimals) in `formatLabValue`, which now hands the digits to a
caller-supplied locale formatter; `useLabNumber` wires it to the
reader's locale for every lab surface. Inputs are unchanged.
2026-10-01 22:09:30 +02:00

61 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { I18nProvider } from "@/lib/i18n/context";
import { LabReferenceRangeBar } from "../lab-reference-range-bar";
function render(
props: Partial<React.ComponentProps<typeof LabReferenceRangeBar>> = {},
locale: "en" | "de" = "en",
) {
return renderToStaticMarkup(
<I18nProvider initialLocale={locale}>
<LabReferenceRangeBar
value={72}
referenceLow={60}
referenceHigh={100}
unit="bpm"
{...props}
/>
</I18nProvider>,
);
}
describe("<LabReferenceRangeBar>", () => {
it("renders the existing colored range bar for a complete numeric range", () => {
const html = render();
expect(html).toContain('data-slot="lab-reference-range-bar"');
expect(html).toContain('data-slot="target-range-bar"');
expect(html).toContain("bg-info/35");
expect(html).toContain("bg-warning/35");
expect(html).toContain("bg-success/35");
expect(html).toContain("left:0%;width:");
});
it.each([
["a qualitative value", { value: null }],
["a missing reference range", { referenceLow: null, referenceHigh: null }],
["an inverted range", { referenceLow: 100, referenceHigh: 60 }],
])("omits the bar for %s", (_label, props) => {
expect(render(props)).not.toContain('data-slot="lab-reference-range-bar"');
});
it("renders one-sided upper and lower reference limits", () => {
expect(render({ referenceLow: null })).toContain('aria-label="≤100 bpm"');
expect(render({ referenceHigh: null })).toContain('aria-label="≥60 bpm"');
});
it("prints the reading and its range in the reader's number format", () => {
const html = render(
{ value: 1.8333, referenceLow: 0.4, referenceHigh: 4.05, unit: "mIU/L" },
"de",
);
expect(html).toContain('aria-label="0,4–4,05 mIU/L"');
// Lab precision: at most two decimals, then the locale's separator.
expect(html).toContain("1,83 mIU/L");
expect(html).not.toMatch(/\d\.\d+ mIU\/L/);
});
});