fix(insights): scope generation guard to prompt fields, clear cache on restore

This commit is contained in:
Marc-André Bombeck committed 2026-07-28 21:11:43 +02:00
1 parent 666a85d311
commit 3aff2c16db
104 files changed
+8082 -651

No files matched your search

@@ -0,0 +1,69 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { I18nProvider } from "@/lib/i18n/context";
import { AnamnesisSection } from "../anamnesis-section";
const moduleState = vi.hoisted(() => ({
coach: true,
insights: true,
}));
vi.mock("@/hooks/use-module-enabled", () => ({
useModuleEnabled: (key: "coach" | "insights") => moduleState[key],
}));
vi.mock("@/components/records/ai-profile-inclusion-manager", () => ({
AiProfileInclusionManager: () => <div data-slot="ai-inclusion" />,
}));
vi.mock("@/components/records/conditions-manager", () => ({
ConditionsManager: () => <div data-slot="conditions" />,
}));
vi.mock("@/components/records/health-profile-facts-manager", () => ({
HealthProfileFactsManager: () => null,
}));
vi.mock("@/components/records/allergy-manager", () => ({
AllergyManager: () => null,
}));
vi.mock("@/components/records/family-history-manager", () => ({
FamilyHistoryManager: () => null,
}));
function renderSection(): string {
return renderToStaticMarkup(
<I18nProvider initialLocale="en">
<AnamnesisSection />
</I18nProvider>,
);
}
beforeEach(() => {
moduleState.coach = true;
moduleState.insights = true;
});
describe("Anamnesis AI inclusion availability", () => {
it("keeps inclusion controls available to Insights-only users", () => {
moduleState.coach = false;
const html = renderSection();
expect(html).toContain('data-slot="ai-inclusion"');
expect(html).not.toContain('data-slot="conditions"');
});
it("hides inclusion controls when no self-context AI consumer is enabled", () => {
moduleState.coach = false;
moduleState.insights = false;
expect(renderSection()).not.toContain('data-slot="ai-inclusion"');
});
it("retains the Coach-only conditions manager gate", () => {
moduleState.insights = false;
const html = renderSection();
expect(html).toContain('data-slot="ai-inclusion"');
expect(html).toContain('data-slot="conditions"');
});
});
+29 -1
View File
@@ -18,7 +18,13 @@
* record where it belongs.
*/
import { HeartPulse, ShieldAlert, Users } from "lucide-react";
import {
ClipboardList,
EyeOff,
HeartPulse,
ShieldAlert,
Users,
} from "lucide-react";
import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardHeader } from "@/components/settings/_card-header";
@@ -28,12 +34,26 @@ import { useModuleEnabled } from "@/hooks/use-module-enabled";
import { AllergyManager } from "@/components/records/allergy-manager";
import { ConditionsManager } from "@/components/records/conditions-manager";
import { FamilyHistoryManager } from "@/components/records/family-history-manager";
import { AiProfileInclusionManager } from "@/components/records/ai-profile-inclusion-manager";
import { HealthProfileFactsManager } from "@/components/records/health-profile-facts-manager";
export function AnamnesisSection() {
const { t } = useTranslations();
const coachEnabled = useModuleEnabled("coach");
const insightsEnabled = useModuleEnabled("insights");
return (
<div className="space-y-6">
{(coachEnabled || insightsEnabled) && (
<SettingsCard className="space-y-4">
<SettingsCardHeader
icon={EyeOff}
title={t("records.aiInclusion.cardTitle")}
description={t("records.aiInclusion.cardDescription")}
/>
<AiProfileInclusionManager />
</SettingsCard>
)}
{coachEnabled && (
<SettingsCard className="space-y-4">
<SettingsCardHeader
@@ -44,6 +64,14 @@ export function AnamnesisSection() {
<ConditionsManager />
</SettingsCard>
)}
<SettingsCard className="space-y-4">
<SettingsCardHeader
icon={ClipboardList}
title={t("records.profileFacts.cardTitle")}
description={t("records.profileFacts.cardDescription")}
/>
<HealthProfileFactsManager />
</SettingsCard>
<SettingsCard className="space-y-4">
<SettingsCardHeader