mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
Slice 3 of phase 3 of #1095. The scan review no longer treats every reading in another unit as unwritable. The server tells it which analyte the matched marker is (markerAnalyteKey on each extracted row); a row whose unit differs but can be converted starts selected and carries a badge saying what Save will store and what the report stated ("Saved as 100.9 mg/dL, converted from 5.6 mmol/L"). A row that cannot be converted keeps the existing blocked badge and error. Save still sends what the report printed; the server converts, as in slice 2. The review's duplicate flag also recognises a re-scan of a reading that was stored converted, by what the report printed, the same rule the commit applies. A converted reading carries a quiet "converted from 5.6 mmol/L" on the lab list (row and tile) and the history list (phone and table), so a number nobody typed can always be traced back to what the report printed. Strings in all seven locales. Refs #1095
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { I18nProvider } from "@/lib/i18n/context";
|
|
|
|
import { LabConvertedNote } from "../lab-converted-note";
|
|
|
|
function render(
|
|
reading: Parameters<typeof LabConvertedNote>[0]["reading"],
|
|
locale: "en" | "de" = "en",
|
|
) {
|
|
return renderToStaticMarkup(
|
|
<I18nProvider initialLocale={locale}>
|
|
<LabConvertedNote reading={reading} />
|
|
</I18nProvider>,
|
|
);
|
|
}
|
|
|
|
describe("<LabConvertedNote>", () => {
|
|
it("says what the report printed beside a converted reading", () => {
|
|
const html = render({
|
|
converted: true,
|
|
sourceValue: 5.6,
|
|
sourceUnit: "mmol/L",
|
|
});
|
|
expect(html).toContain('data-slot="lab-converted-note"');
|
|
expect(html).toContain("converted from 5.6 mmol/L");
|
|
});
|
|
|
|
it("formats the number for the reader's language", () => {
|
|
expect(
|
|
render({ converted: true, sourceValue: 5.6, sourceUnit: "mmol/L" }, "de"),
|
|
).toContain("umgerechnet aus 5,6 mmol/L");
|
|
});
|
|
|
|
it("trims a long fraction the way the reading itself is trimmed", () => {
|
|
expect(
|
|
render({ converted: true, sourceValue: 5.6123456, sourceUnit: "mmol/L" }),
|
|
).toContain("converted from 5.61 mmol/L");
|
|
});
|
|
|
|
it.each([
|
|
[{ converted: false, sourceValue: null, sourceUnit: null }],
|
|
[{ converted: true, sourceValue: null, sourceUnit: "mmol/L" }],
|
|
[{ converted: true, sourceValue: 5.6, sourceUnit: null }],
|
|
])("renders nothing for %j", (reading) => {
|
|
expect(render(reading)).toBe("");
|
|
});
|
|
});
|