diff --git a/src/components/day/__tests__/day-title.test.ts b/src/components/day/__tests__/day-title.test.ts new file mode 100644 index 000000000..ee3ecb0a8 --- /dev/null +++ b/src/components/day/__tests__/day-title.test.ts @@ -0,0 +1,23 @@ +/** + * A cycle and a trip reach the day view under a sentinel title the client + * words in the reader's language. The record's kind decides that, so a + * medication or a document someone named "cycle" keeps its own name. + */ +import { describe, expect, it } from "vitest"; + +import { dayTitle } from "../day-sections"; + +const t = (key: string) => `t:${key}`; + +describe("dayTitle", () => { + it("words the cycle and travel sentinels", () => { + expect(dayTitle("cyclePhase", "cycle", t)).toBe("t:nav.cycle"); + expect(dayTitle("cycleDayLog", "cycle", t)).toBe("t:nav.cycle"); + expect(dayTitle("travel", "travel", t)).toBe("t:day.travel"); + }); + + it("keeps a record's own title that happens to read like a sentinel", () => { + expect(dayTitle("medication", "cycle", t)).toBe("cycle"); + expect(dayTitle("document", "travel", t)).toBe("travel"); + }); +}); diff --git a/src/components/day/day-sections.tsx b/src/components/day/day-sections.tsx index 6de9b09b9..f935f8f1c 100644 --- a/src/components/day/day-sections.tsx +++ b/src/components/day/day-sections.tsx @@ -165,11 +165,17 @@ const RUNNING_COLOR: Record = { * The server names a few records by a sentinel rather than by text it would * have to translate: a cycle is titled "cycle", a trip "travel", a cycle * day carries its flow level. They are worded here, in the reader's - * language; every other title is the record's own text. + * language; every other title is the record's own text. The record's kind + * decides, not the title: a medication or a document the person named + * "cycle" keeps its own name. */ -function dayTitle(title: string, t: (key: string) => string): string { - if (title === "cycle") return t("nav.cycle"); - if (title === "travel") return t("day.travel"); +export function dayTitle( + kind: string, + title: string, + t: (key: string) => string, +): string { + if (kind === "cyclePhase" || kind === "cycleDayLog") return t("nav.cycle"); + if (kind === "travel") return t("day.travel"); return title; } @@ -217,7 +223,7 @@ export function DayRunning({ items }: { items: readonly DayRunningItem[] }) { /> - {dayTitle(item.title, t)} + {dayTitle(item.kind, item.title, t)} {parts.join(" ยท ")} @@ -456,11 +462,11 @@ export function DayEvents({ events }: { events: readonly DayEvent[] }) { data-slot="day-event-link" className="focus-visible:ring-ring/50 block text-sm leading-5 font-medium after:absolute after:inset-0 after:rounded-md after:content-[''] focus-visible:outline-none focus-visible:after:ring-[3px] focus-visible:after:ring-inherit" > - {dayTitle(event.title, t)} + {dayTitle(event.kind, event.title, t)} ) : (

- {dayTitle(event.title, t)} + {dayTitle(event.kind, event.title, t)}

)} {event.meta ? (