mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 13:52:20 +00:00
SettingsSectionFrame re-rendered the page heading and subtitle that SettingsShell already paints from the section slug. No route used it; only the per-section smoke tests rendered bodies through it to assert the visible heading and its id. Remove the component and move the heading wrapper those tests rely on into a test-only harness that reproduces the shell's heading markup, so the smoke tests keep asserting what the user actually sees.
76 lines
2.9 KiB
TypeScript
76 lines
2.9 KiB
TypeScript
/**
|
|
* v1.18.0 (S5) — Settings → Coach section.
|
|
*
|
|
* The Coach preference cards (disable toggle, preferences, memory) moved
|
|
* out of the AI / Assistant section into their own dedicated, module-gated
|
|
* entry. SSR-only smoke test — interactive contracts live in the cards'
|
|
* own suites (`disable-coach-card.test.tsx`, `coach-memory-section.test.tsx`).
|
|
*/
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
|
|
vi.mock("next/navigation", () => ({
|
|
useRouter: () => ({ push: vi.fn(), replace: vi.fn() }),
|
|
usePathname: () => "/settings/coach",
|
|
}));
|
|
|
|
vi.mock("@tanstack/react-query", () => ({
|
|
useQuery: () => ({ data: null, isLoading: false, refetch: vi.fn() }),
|
|
useMutation: () => ({ mutate: vi.fn(), isPending: false }),
|
|
useQueryClient: () => ({ invalidateQueries: vi.fn() }),
|
|
}));
|
|
|
|
const authState: { disableCoach: boolean } = { disableCoach: false };
|
|
vi.mock("@/hooks/use-auth", () => ({
|
|
useAuth: () => ({
|
|
user: { id: "u1", role: "USER", disableCoach: authState.disableCoach },
|
|
isAuthenticated: true,
|
|
isLoading: false,
|
|
refetch: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
import { I18nProvider } from "@/lib/i18n/context";
|
|
import { SettingsSectionFrame } from "./section-frame-harness";
|
|
import { CoachSection } from "../coach-section";
|
|
|
|
function render(locale: "en" | "de" = "en") {
|
|
// v1.18.6 (W9) — the visible heading lives in the shared frame the route
|
|
// wraps the section in; render through it so the heading id is present.
|
|
return renderToStaticMarkup(
|
|
<I18nProvider initialLocale={locale}>
|
|
<SettingsSectionFrame slug="coach">
|
|
<CoachSection />
|
|
</SettingsSectionFrame>
|
|
</I18nProvider>,
|
|
);
|
|
}
|
|
|
|
describe("<CoachSection> — SSR smoke", () => {
|
|
it("renders the section scaffold + the Activate-Coach toggle card", () => {
|
|
authState.disableCoach = false;
|
|
const html = render();
|
|
expect(html).toContain('id="settings-section-coach-title"');
|
|
expect(html).toContain('data-testid="settings-disable-coach-card"');
|
|
expect(html).toContain('data-testid="settings-disable-coach-switch"');
|
|
// v1.18.1 (D7) — polarity flipped to activate/default-on.
|
|
expect(html).toContain("Activate Coach");
|
|
expect(html).toContain("Show the Coach button and drawer. On by default");
|
|
// v1.18.6 (W9) — the proactive Coach nudge card moved here from
|
|
// Benachrichtigungen; its anchor renders under the enabled-coach gate.
|
|
expect(html).toContain('id="coach-nudge"');
|
|
// Raw key never leaks past i18n.
|
|
expect(html).not.toContain("settings.sections.coach.");
|
|
expect(html).not.toContain("settings.coach.activate.");
|
|
});
|
|
|
|
it("renders the German Activate-Coach copy", () => {
|
|
authState.disableCoach = false;
|
|
const html = render("de");
|
|
expect(html).toContain("Coach aktivieren");
|
|
expect(html).toContain("Standardmäßig an");
|
|
expect(html).not.toContain("settings.sections.coach.");
|
|
expect(html).not.toContain("settings.coach.activate.");
|
|
});
|
|
});
|