mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
The `<ErrorDetails>` panel — rendered by every Next.js `error.tsx` boundary in HealthLog — surfaces a "Report bug" button that links to `/bugreport`. When the admin flips `bugReportEnabled = false`, that page renders a "Bug reports are disabled" notice. Showing the button in that state is dead-end UX. Reuse the `useAppSettings()` hook introduced for the sidebar nav (Fix 1) and gate the button on the same flag. The other escape hatches (retry, copy diagnostic payload) stay visible so the panel remains useful even when in-app submission is disabled. Tests: SSR-render `<ErrorDetails>` with both flag states and assert the `/bugreport` href appears / disappears accordingly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
|
|
// `<ErrorDetails>` is a client component used by every Next.js
|
|
// `error.tsx` boundary. It surfaces a "Report bug" link whose
|
|
// visibility must mirror the admin's `bugReportEnabled` toggle —
|
|
// otherwise the user lands on a `/bugreport` page that immediately
|
|
// renders a "Bug reports are disabled" notice.
|
|
|
|
const mockSettingsRef = { value: { bugReportEnabled: true } };
|
|
vi.mock("@/components/app-settings-provider", () => ({
|
|
useAppSettings: () => mockSettingsRef.value,
|
|
}));
|
|
|
|
import { I18nProvider } from "@/lib/i18n/context";
|
|
import { ErrorDetails } from "../error-details";
|
|
|
|
function render({
|
|
bugReportEnabled = true,
|
|
}: { bugReportEnabled?: boolean } = {}) {
|
|
mockSettingsRef.value = { bugReportEnabled };
|
|
const error = Object.assign(new Error("test failure"), {
|
|
digest: "abc123",
|
|
});
|
|
return renderToStaticMarkup(
|
|
<I18nProvider initialLocale="en">
|
|
<ErrorDetails error={error} />
|
|
</I18nProvider>,
|
|
);
|
|
}
|
|
|
|
describe("<ErrorDetails> bug-report toggle", () => {
|
|
it("shows the Report bug button when the admin flag is enabled", () => {
|
|
const html = render({ bugReportEnabled: true });
|
|
expect(html).toContain('href="/bugreport"');
|
|
});
|
|
|
|
it("hides the Report bug button when the admin flag is disabled", () => {
|
|
const html = render({ bugReportEnabled: false });
|
|
expect(html).not.toContain('href="/bugreport"');
|
|
});
|
|
});
|