feat: add inhaler and injection package types

Closes #558

- add inhaler and injection as supported medication package types
- align refill, planner, dashboard, report, export, and notification wording for the new discrete package types
- include the validated CI repair for formatting and dashboard label parity
This commit is contained in:
Daniel Volz
2026-05-11 21:29:59 +02:00
committed by GitHub
parent 26e9b39f47
commit c5c75f65e4
32 changed files with 584 additions and 141 deletions
@@ -199,6 +199,24 @@ describe("useMedicationForm", () => {
expect(result.current.form.packageAmountUnit).toBe("g");
});
it.each([
{ packageType: "inhaler" as const, expectedDoseUnit: "puffs" },
{ packageType: "injection" as const, expectedDoseUnit: "injections" },
])("enforces discrete container defaults when packageType is $packageType", ({ packageType, expectedDoseUnit }) => {
const { result } = renderHook(() => useMedicationForm());
act(() => {
result.current.handleValueChange("packageType", packageType);
});
expect(result.current.form.packageType).toBe(packageType);
expect(result.current.form.medicationForm).toBe("tablet");
expect(result.current.form.pillForm).toBe("tablet");
expect(result.current.form.lifecycleCategory).toBe("refill_when_empty");
expect(result.current.form.doseUnit).toBe(expectedDoseUnit);
expect(result.current.form.packageAmountUnit).toBe("ml");
});
it("normalizes legacy tube records to grams in startEdit", () => {
const { result } = renderHook(() => useMedicationForm());
const openEditModal = vi.fn();
@@ -227,6 +245,41 @@ describe("useMedicationForm", () => {
expect(result.current.form.packageAmountUnit).toBe("g");
});
it.each([
{ packageType: "inhaler" as const, totalPills: 200, looseTablets: 120, expectedDoseUnit: "puffs" },
{ packageType: "injection" as const, totalPills: 12, looseTablets: 6, expectedDoseUnit: "injections" },
])("assigns $expectedDoseUnit when editing $packageType records without a stored dose unit", ({
packageType,
totalPills,
looseTablets,
expectedDoseUnit,
}) => {
const { result } = renderHook(() => useMedicationForm());
const openEditModal = vi.fn();
Object.defineProperty(window, "innerWidth", { value: 1024, writable: true });
const med: Medication = {
id: 13,
name: `${packageType} med`,
takenBy: [],
packageType,
packCount: 0,
blistersPerPack: 1,
pillsPerBlister: 1,
totalPills,
looseTablets,
blisters: [{ usage: 1, every: 1, start: "2026-01-01T08:00:00.000Z" }],
updatedAt: null,
};
act(() => {
result.current.startEdit(med, openEditModal);
});
expect(result.current.form.packageType).toBe(packageType);
expect(result.current.form.doseUnit).toBe(expectedDoseUnit);
});
it("adds, edits and removes blister rows", () => {
const { result } = renderHook(() => useMedicationForm());