From d068d6c9e63f4781633bfaba065d269007b5fcae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 9 Oct 2026 18:55:34 +0200 Subject: [PATCH] fix(day,timeline): put an intake's dose in its name and set a lab day's count apart Under "What happened" an intake now reads "Ramipril 5mg" on one line, as the same medication does under Running that day, instead of the name over a muted dose line. A lab day's analyte count moves from the run-on second part to the entry's tag: a chip of its own in the selection bar, brackets in the screen-reader line and the hover title, the muted line in the chronicle. --- .../day/__tests__/day-events-dose.test.tsx | 63 ++++++++++++ src/components/day/day-sections.tsx | 24 +++-- .../timeline/__tests__/lab-day-chip.test.tsx | 96 +++++++++++++++++++ src/components/timeline/item-words.ts | 26 +++-- src/components/timeline/selection-bar.tsx | 4 +- src/components/timeline/timeline-chart.tsx | 4 +- 6 files changed, 197 insertions(+), 20 deletions(-) create mode 100644 src/components/day/__tests__/day-events-dose.test.tsx create mode 100644 src/components/timeline/__tests__/lab-day-chip.test.tsx diff --git a/src/components/day/__tests__/day-events-dose.test.tsx b/src/components/day/__tests__/day-events-dose.test.tsx new file mode 100644 index 000000000..9f27d1f21 --- /dev/null +++ b/src/components/day/__tests__/day-events-dose.test.tsx @@ -0,0 +1,63 @@ +/** + * An intake under "What happened" reads as its name and the dose taken on + * one line, "Ramipril 5mg", as the same medication does under Running that + * day. The dose on a muted line of its own under the name read as + * "Ramipril / 5mg". + */ +import { describe, expect, it } from "vitest"; +import { renderToStaticMarkup } from "react-dom/server"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; + +import { I18nProvider } from "@/lib/i18n/context"; +import type { DayEvent } from "@/lib/day/contract"; + +import { DayEvents } from "../day-sections"; + +function event( + kind: DayEvent["kind"], + title: string, + meta: string | null, +): DayEvent { + return { + at: null, + kind, + section: "medications", + id: `${kind}-1`, + title, + meta, + note: null, + docs: [], + href: null, + }; +} + +/** The text of each line under the event's time and icon: its

s. */ +function lines(events: DayEvent[]): string[] { + const html = renderToStaticMarkup( + + + + + , + ); + return [...html.matchAll(/]*>(.*?)<\/p>/g)].map((m) => m[1]); +} + +describe("DayEvents dose", () => { + it("names an intake with its dose on one line", () => { + expect(lines([event("intake", "Ramipril", "5mg")])).toEqual([ + "Ramipril 5mg", + ]); + }); + + it("names an intake without a dose by its name alone", () => { + expect(lines([event("intake", "Ramipril", null)])).toEqual(["Ramipril"]); + }); + + it("keeps a dose change's new dose on its own line", () => { + expect(lines([event("doseChange", "Ramipril", "10 mg")])).toEqual([ + "Ramipril", + "10 mg", + ]); + }); +}); diff --git a/src/components/day/day-sections.tsx b/src/components/day/day-sections.tsx index 6f9993464..d41c63600 100644 --- a/src/components/day/day-sections.tsx +++ b/src/components/day/day-sections.tsx @@ -589,6 +589,13 @@ const EVENT_ICON: Record = { lifeEvent: Flag, }; +/** + * Event kinds whose meta is the dose taken. It reads as part of the name, + * "Ramipril 5 mg", as under Running that day, not as a second line of its + * own under the name. + */ +const DOSE_META_EVENT_KINDS: ReadonlySet = new Set(["intake"]); + export function DayEvents({ events }: { events: readonly DayEvent[] }) { const { t } = useTranslations(); const fmt = useFormatters(); @@ -599,9 +606,14 @@ export function DayEvents({ events }: { events: readonly DayEvent[] }) {