mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
fix(records): show the screening hints when one applies without a smoking answer
This commit is contained in:
1 parent
b3dcd428f6
commit
d66d3969cd
2 files changed
+86
-3
No files matched your search
@@ -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(
|
||||
<QueryClientProvider client={client}>
|
||||
<I18nProvider initialLocale="en">
|
||||
<ScreeningHintsCard />
|
||||
</I18nProvider>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
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"');
|
||||
});
|
||||
});
|
||||
@@ -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 (
|
||||
<SettingsCard data-slot="screening-hints-card">
|
||||
|
||||
Reference in new issue
Block a user