fix(settings): make delegated module rows read-only managed deep-links

The Module hub rendered live switches for the delegated keys cycle and coach,
but the gate resolves those from their own sources (cycle from CycleProfile,
coach from the operator flag + disableCoach), so a toggle wrote an inert entry
to modulePreferencesJson, snapped back, and still fired a success toast. Render
delegated modules as read-only rows that deep-link to their real control, strip
delegated keys from the modules PATCH schema so no inert value is stored, drop
the duplicate cycle control, and surface an operator-disabled state with the
previously orphaned hint string.
This commit is contained in:
Marc-André Bombeck committed 2026-06-16 00:51:16 +02:00
1 parent 7c8d82f565
commit 91d01d154a
14 files changed
+216 -36

No files matched your search

@@ -20,7 +20,11 @@ import { renderToStaticMarkup } from "react-dom/server";
import { I18nProvider } from "@/lib/i18n/context";
import type { AuthUser } from "@/hooks/use-auth";
import { queryKeys } from "@/lib/query-keys";
import { MODULE_KEYS, CORE_DOMAIN_KEYS } from "@/lib/modules/registry";
import {
MODULE_KEYS,
CORE_DOMAIN_KEYS,
moduleDelegatesTo,
} from "@/lib/modules/registry";
// Capture the latest useMutation config + a shared mutate spy so we can
// invoke `mutationFn` / `onSuccess` by hand (the SSR pass can't fire a
@@ -104,12 +108,22 @@ afterEach(() => {
});
describe("<ModulesSection>", () => {
it("renders a Switch for every toggleable + core module", () => {
it("renders a Switch for every non-delegated toggleable module, a managed deep-link for delegated ones, and locked switches for core", () => {
const html = render();
for (const key of MODULE_KEYS) {
expect(html, `toggleable switch ${key}`).toContain(
`id="module-toggle-${key}"`,
);
if (moduleDelegatesTo(key) !== undefined) {
// Delegated modules (cycle/coach) are owned by their real control
// elsewhere — they render as a read-only "manage in X" deep-link,
// never a live Switch that would write an inert disabled-allowlist
// entry the gate ignores.
expect(html, `delegated has no switch ${key}`).not.toContain(
`id="module-toggle-${key}"`,
);
} else {
expect(html, `toggleable switch ${key}`).toContain(
`id="module-toggle-${key}"`,
);
}
}
for (const key of CORE_DOMAIN_KEYS) {
expect(html, `core switch ${key}`).toContain(`id="module-toggle-${key}"`);