Improve coverage for image upload and schedule helper logic with focused unit tests (#551)

Agent-Logs-Url: https://github.com/DanielVolz/medassist-ng/sessions/a5af7c91-2dd4-4a79-838e-dbb79fc08f6d

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com>
This commit is contained in:
Copilot
2026-04-21 09:12:36 +02:00
committed by GitHub
parent cdfb19bde2
commit c7be73786b
3 changed files with 198 additions and 0 deletions
@@ -0,0 +1,76 @@
import { describe, expect, it } from "vitest";
import { formatScheduleDoseUsageLabel, formatScheduleTotalUsageLabel } from "../../../features/schedule/formatters";
const t = (key: string, options?: Record<string, unknown>): string => {
switch (key) {
case "form.packageAmountUnitMl":
return "ml";
case "form.blisters.teaspoons":
return Number(options?.count) === 1 ? "teaspoon" : "teaspoons";
case "form.blisters.tablespoons":
return Number(options?.count) === 1 ? "tablespoon" : "tablespoons";
case "form.blisters.applications":
return Number(options?.count) === 1 ? "application" : "applications";
case "common.pill":
return "pill";
case "common.pills":
return "pills";
case "common.pillsTotal":
return `${options?.count ?? 0} pills total`;
default:
return key;
}
};
describe("schedule formatters", () => {
it("formats liquid dose labels in base and converted units", () => {
expect(formatScheduleDoseUsageLabel({ packageType: "liquid_container" }, 0, t, "ml")).toBe("0 ml");
expect(formatScheduleDoseUsageLabel({ packageType: "liquid_container" }, 2, t, "tsp")).toBe("2 teaspoons 10 ml");
});
it("formats tube doses as applications by default and ml for liquid forms", () => {
expect(formatScheduleDoseUsageLabel({ packageType: "tube" }, 1, t)).toBe("1 application");
expect(formatScheduleDoseUsageLabel({ packageType: "tube", medicationForm: "liquid" }, 3, t)).toBe("3 ml");
});
it("formats liquid totals from dose units and mixed-unit conversion", () => {
expect(
formatScheduleTotalUsageLabel(
{ packageType: "liquid_container" },
0,
t,
[
{ usage: 1, intakeUnit: "tsp" },
{ usage: 2, intakeUnit: "tsp" },
],
"ml"
)
).toBe("3 teaspoons 15 ml");
expect(
formatScheduleTotalUsageLabel(
{ packageType: "liquid_container" },
0,
t,
[
{ usage: 1, intakeUnit: "tsp" },
{ usage: 1, intakeUnit: "tbsp" },
],
"ml"
)
).toBe("20 ml");
});
it("falls back to total and non-liquid totals when dose list is not usable", () => {
expect(
formatScheduleTotalUsageLabel(
{ packageType: "liquid_container" },
4,
t,
[{ usage: -1, intakeUnit: "ml" }],
"tbsp"
)
).toBe("4 tablespoons 60 ml");
expect(formatScheduleTotalUsageLabel({ packageType: "blister" }, 3, t)).toBe("3 pills total");
});
});
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import {
areAllDoseIdsTaken,
countTakenDoseIds,
resolveCollapsedState,
toggleDateInSet,
} from "../../../features/schedule/interactions";
describe("schedule interactions", () => {
it("toggles dates without mutating the original set", () => {
const previous = new Set(["2026-01-01"]);
const added = toggleDateInSet(previous, "2026-01-02");
const removed = toggleDateInSet(added, "2026-01-01");
expect(previous).toEqual(new Set(["2026-01-01"]));
expect(added).toEqual(new Set(["2026-01-01", "2026-01-02"]));
expect(removed).toEqual(new Set(["2026-01-02"]));
});
it("resolves auto and manual collapsed states", () => {
expect(resolveCollapsedState(true, "2026-01-01", new Set(), new Set())).toBe(true);
expect(resolveCollapsedState(true, "2026-01-01", new Set(["2026-01-01"]), new Set())).toBe(false);
expect(resolveCollapsedState(false, "2026-01-01", new Set(), new Set(["2026-01-01"]))).toBe(true);
});
it("counts and checks taken dose ids", () => {
const taken = new Set(["a", "c"]);
const isDoseTaken = (doseId: string) => taken.has(doseId);
expect(countTakenDoseIds(["a", "b", "c"], isDoseTaken)).toBe(2);
expect(areAllDoseIdsTaken(["a", "c"], isDoseTaken)).toBe(true);
expect(areAllDoseIdsTaken(["a", "b"], isDoseTaken)).toBe(false);
expect(areAllDoseIdsTaken([], isDoseTaken)).toBe(false);
});
});