mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
fix(medications): localise the dose unit and lift it onto its own line
A medication's dose is stored as free text the wizard composes from an
amount and a unit token ("1 pieces", "2 tablets"), and the card rendered
that token verbatim glued onto the name — so the unit showed in English
on every locale and the title read "Test ABC 1 pieces".
Translate the dose at display time: a formatDose helper splits the stored
string and runs a known unit token through the existing unit messages, so
"1 pieces" reads "1 Stück" / "1 piece(s)" per locale while a custom
free-text dose passes through untouched. The card header now carries the
name alone on its title line with the dose on a muted line beneath it,
above the category badge; the detail view, table and intake dialogs
localise the same way. Vorsorge and lab rows pass an empty dose so they
render no extra line.
This commit is contained in:
1 parent
a31711699c
commit
6fe552ffdf
14 files changed
+180
-43
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import { formatDose } from "@/lib/medications/format-dose";
|
||||
|
||||
/**
|
||||
* The unit keys translate via `medications.wizard.steps.step3.unit.<key>`.
|
||||
* The stub mirrors a German bundle for the keys under test and echoes the
|
||||
* key for anything else so a wrong lookup is visible.
|
||||
*/
|
||||
const t = (key: string): string =>
|
||||
({
|
||||
"medications.wizard.steps.step3.unit.pieces": "Stück",
|
||||
"medications.wizard.steps.step3.unit.mg": "mg",
|
||||
"medications.wizard.steps.step3.unit.tablets": "Tablette(n)",
|
||||
})[key] ?? key;
|
||||
|
||||
describe("formatDose", () => {
|
||||
it("translates a raw unit key glued to an amount", () => {
|
||||
expect(formatDose("1 pieces", t)).toBe("1 Stück");
|
||||
});
|
||||
|
||||
it("keeps a numeric amount and translates the unit", () => {
|
||||
expect(formatDose("5 mg", t)).toBe("5 mg");
|
||||
expect(formatDose("2 tablets", t)).toBe("2 Tablette(n)");
|
||||
});
|
||||
|
||||
it("passes a custom free-text dose through unchanged", () => {
|
||||
expect(formatDose("1 puff morning", t)).toBe("1 puff morning");
|
||||
});
|
||||
|
||||
it("returns an empty string for empty / null / undefined input", () => {
|
||||
expect(formatDose("", t)).toBe("");
|
||||
expect(formatDose(null, t)).toBe("");
|
||||
expect(formatDose(undefined, t)).toBe("");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user