fix: unify stock semantics across planner and scheduler (#245)

* fix: unify stock semantics across planner and scheduler

* fix: stabilize dashboard hmr and align stock helper tests
This commit is contained in:
Daniel Volz
2026-02-21 15:24:53 +01:00
committed by GitHub
parent 02af93ec55
commit 612aa007aa
14 changed files with 846 additions and 285 deletions
@@ -1,15 +1,15 @@
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { DashboardPage } from "../../pages/DashboardPage";
import {
DashboardPage,
formatFullBlisters,
formatOpenBlisterAndLoose,
getBlisterStock,
getMedTotal,
getReminderStatusData,
userStorageKey,
} from "../../pages/DashboardPage";
} from "../../pages/dashboard-helpers";
// Mock data for tests with medications
const mockMeds = [
@@ -198,7 +198,7 @@ describe("DashboardPage helper functions", () => {
});
it("calculates blister stock breakdown", () => {
expect(getBlisterStock(27, 10, 0, 27)).toEqual({ fullBlisters: 2, openBlisterPills: 7, loosePills: 7 });
expect(getBlisterStock(27, 10, 0, 27)).toEqual({ fullBlisters: 2, openBlisterPills: 7, loosePills: 0 });
});
it("formats blister and open blister labels", () => {
@@ -206,7 +206,7 @@ describe("DashboardPage helper functions", () => {
expect(formatFullBlisters(1, t)).toBe("1 common.blister");
expect(formatFullBlisters(3, t)).toBe("3 common.blisters");
expect(formatOpenBlisterAndLoose(0, 0, 10, t)).toBe("-");
expect(formatOpenBlisterAndLoose(4, 4, 10, t)).toBe("4 common.of 10 common.pills");
expect(formatOpenBlisterAndLoose(4, 4, 10, t)).toBe("4 common.of 10 common.pills + 4 modal.loosePills");
});
it("computes total pills for blister and bottle types", () => {
+1 -1
View File
@@ -201,7 +201,7 @@ describe("getBlisterStock", () => {
const result = getBlisterStock(med);
expect(result.fullBlisters).toBe(2); // 25 / 10 = 2
expect(result.openBlisterPills).toBe(5); // 25 % 10 = 5
expect(result.openBlisterPills).toBe(0); // 20 % 10 = 0 after preserving loose tablets
expect(result.loosePills).toBe(5);
});