From d66d3969cd415b30a234de961afbc3d27627e049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 16 Oct 2026 05:28:53 +0200 Subject: [PATCH] fix(records): show the screening hints when one applies without a smoking answer --- .../__tests__/screening-hints-card.test.tsx | 76 +++++++++++++++++++ .../records/screening-hints-card.tsx | 13 +++- 2 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 src/components/records/__tests__/screening-hints-card.test.tsx diff --git a/src/components/records/__tests__/screening-hints-card.test.tsx b/src/components/records/__tests__/screening-hints-card.test.tsx new file mode 100644 index 000000000..029817595 --- /dev/null +++ b/src/components/records/__tests__/screening-hints-card.test.tsx @@ -0,0 +1,76 @@ +import { describe, expect, it } from "vitest"; +import { renderToStaticMarkup } from "react-dom/server"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; + +import { ScreeningHintsCard } from "@/components/records/screening-hints-card"; +import { I18nProvider } from "@/lib/i18n/context"; +import type { LifeCircumstancesDto } from "@/lib/profile/life-circumstances"; +import type { ScreeningHint } from "@/lib/profile/life-derived"; +import { queryKeys } from "@/lib/query-keys"; + +function hint( + id: ScreeningHint["id"], + status: ScreeningHint["status"], +): ScreeningHint { + return { + id, + status, + reasonKeys: [], + region: "DE", + sourceLabel: "source", + sourceUrl: "https://example.org/", + }; +} + +function render(tobaccoFacts: number, hints: ScreeningHint[]): string { + const dto = { + sections: [ + { + key: "tobacco", + facts: Array.from({ length: tobaccoFacts }, () => ({})), + }, + ], + derived: { screeningHints: hints }, + } as unknown as LifeCircumstancesDto; + const client = new QueryClient(); + client.setQueryData(queryKeys.lifeCircumstances(), dto); + return renderToStaticMarkup( + + + + + , + ); +} + +describe("ScreeningHintsCard", () => { + it("stays away while nothing applies and smoking is unanswered", () => { + expect( + render(0, [ + hint("lung_ldct", "unknown"), + hint("aaa_ultrasound", "not_eligible"), + ]), + ).toBe(""); + }); + + // The German abdominal-aorta ultrasound applies to every man from 65, + // whether he ever smoked or not: the hint must reach him without a + // smoking answer. + it("shows a hint that applies without a smoking answer", () => { + const html = render(0, [ + hint("lung_ldct", "unknown"), + hint("aaa_ultrasound", "suggested"), + ]); + expect(html).toContain('data-slot="screening-hints-card"'); + expect(html).toContain('data-slot="screening-hint-aaa_ultrasound"'); + }); + + it("shows once smoking is answered", () => { + expect( + render(1, [ + hint("lung_ldct", "not_eligible"), + hint("aaa_ultrasound", "not_eligible"), + ]), + ).toContain('data-slot="screening-hints-card"'); + }); +}); diff --git a/src/components/records/screening-hints-card.tsx b/src/components/records/screening-hints-card.tsx index e470a4bd4..76b7859c1 100644 --- a/src/components/records/screening-hints-card.tsx +++ b/src/components/records/screening-hints-card.tsx @@ -7,8 +7,10 @@ * source and country. A hint, never a reminder: nothing is scheduled here, * and the card says so. Resolved on the server; rendered as delivered. * - * The card stays away until the person has said something about smoking, - * because every hint would otherwise read "not enough information". + * The card stays away until it has something to say: the person has said + * something about smoking, or a hint already applies without it (the German + * abdominal-aorta ultrasound is offered to every man from 65, smoker or not). + * Before either, every hint would read "not enough information". */ import { useQuery } from "@tanstack/react-query"; import { Stethoscope } from "lucide-react"; @@ -29,7 +31,12 @@ export function ScreeningHintsCard() { }); const data = query.data; const tobacco = data?.sections.find((section) => section.key === "tobacco"); - if (!data || !tobacco || tobacco.facts.length === 0) return null; + if (!data) return null; + const answeredTobacco = (tobacco?.facts.length ?? 0) > 0; + const anySuggested = data.derived.screeningHints.some( + (hint) => hint.status === "suggested", + ); + if (!answeredTobacco && !anySuggested) return null; return (