Merge the medication adherence end-to-end journey

This commit is contained in:
Marc-André Bombeck committed 2026-09-10 04:20:01 +02:00
commit 89ec49cd42
10 files changed
+954 -8

No files matched your search

@@ -15,8 +15,16 @@ import {
* aggregation helper produces the correct rates.
*/
/**
* The daily points the mocked query serves. Mutable so one test can hand the
* chart a loaded window; every other test leaves it empty.
*/
const queryState = vi.hoisted(() => ({
data: [] as { date: string; scheduled: number; taken: number }[],
}));
vi.mock("@tanstack/react-query", () => ({
useQuery: () => ({ data: [], isLoading: false }),
useQuery: () => ({ data: queryState.data, isLoading: false }),
useQueryClient: () => ({
cancelQueries: () => Promise.resolve(),
getQueryData: () => undefined,
@@ -195,4 +203,24 @@ describe("<MedicationComplianceChart>", () => {
const html = render(<MedicationComplianceChart />);
expect(html).not.toContain('data-slot="medication-trend-chip"');
});
/**
* The tile's adherence number exists only as bar geometry, so the root's
* `data-latest-rate` is the one way to read it back — and the browser suite
* was its only reader, which put a production attribute's shape three
* minutes and a whole server away from the gate that should own it. Pinned
* here: the value is the LAST day's rate, as an integer.
*/
it("carries the last day's rate on the root as data-latest-rate", () => {
queryState.data = [
{ date: "2026-05-01", scheduled: 2, taken: 2 }, // 100 %
{ date: "2026-05-02", scheduled: 4, taken: 1 }, // 25 %
];
try {
const html = render(<MedicationComplianceChart />);
expect(html).toContain('data-latest-rate="25"');
} finally {
queryState.data = [];
}
});
});
@@ -393,10 +393,19 @@ export function MedicationComplianceChart({
// explicit user opt-in — silence would feel like a bug).
const hasData = chartData.length > 0;
// The tile's adherence number exists only as bar geometry, so nothing on
// this surface can be read back except by measuring pixels. The most
// recent day's rate — the one figure a reader takes off the tile — rides
// the root as a plain data attribute so the browser journey can assert the
// dashboard and the medication card agree on the same dose. Presentation
// is untouched; the value is the one `chartData` already carries.
const latestRate = hasData ? chartData[chartData.length - 1].rate : null;
return (
<div
className="bg-card border-border rounded-xl border p-4 md:p-6"
data-slot="medication-compliance-chart"
data-latest-rate={latestRate ?? undefined}
>
{/* v1.4.19 A2 — header layout split into title row + controls
row on small screens. Pre-fix the trend chip + 4 range tabs +