From bde167df7529ec60cf6850726a8ecd78606527ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sat, 9 May 2026 20:19:09 +0200 Subject: [PATCH] fix(feedback): hide user-facing feedback link when admin disables the feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `` 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 `` with both flag states and assert the `/bugreport` href appears / disappears accordingly. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../__tests__/error-details.test.tsx | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/components/__tests__/error-details.test.tsx diff --git a/src/components/__tests__/error-details.test.tsx b/src/components/__tests__/error-details.test.tsx new file mode 100644 index 000000000..7c945e131 --- /dev/null +++ b/src/components/__tests__/error-details.test.tsx @@ -0,0 +1,42 @@ +import { describe, expect, it, vi } from "vitest"; +import { renderToStaticMarkup } from "react-dom/server"; + +// `` 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( + + + , + ); +} + +describe(" 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"'); + }); +});