diff --git a/client/scripts/feature-pairs.json b/client/scripts/feature-pairs.json index 2eb12b804..bcc35dc1b 100644 --- a/client/scripts/feature-pairs.json +++ b/client/scripts/feature-pairs.json @@ -665,21 +665,20 @@ "feature": "Settings / Demo account locks", "hooks": ["src/components/Demo/useDemoLock.ts"], "desktop": [ - "src/components/Settings/AccountTab.tsx", + "src/components/Settings/AccountDemoLock.tsx", "src/components/Settings/DisplaySettingsTab.tsx", "src/components/Settings/IntegrationsTab.tsx", "src/components/Settings/ai/AiConnectionSection.tsx" ], "mobile": [ "src/mobile/screens/settings/MAiConnectionSection.tsx", - "src/mobile/screens/settings/MSettingsAccount.tsx", "src/mobile/screens/settings/MSettingsGeneral.tsx", "src/mobile/screens/settings/MSettingsMcp.tsx" ] }, { "feature": "Settings / Account", - "hooks": ["src/components/Settings/useAccountSettings.ts"], + "hooks": ["src/components/Settings/AccountDemoLock.tsx", "src/components/Settings/useAccountSettings.ts"], "desktop": ["src/components/Settings/AccountTab.tsx"], "mobile": ["src/mobile/screens/settings/MSettingsAccount.tsx"] }, diff --git a/client/src/components/Settings/AccountDemoLock.test.tsx b/client/src/components/Settings/AccountDemoLock.test.tsx new file mode 100644 index 000000000..5635179e6 --- /dev/null +++ b/client/src/components/Settings/AccountDemoLock.test.tsx @@ -0,0 +1,43 @@ +import { beforeEach, describe, expect, it } from 'vitest'; +import { buildUser } from '../../../tests/helpers/factories'; +import { render, screen } from '../../../tests/helpers/render'; +import { resetAllStores, seedStore } from '../../../tests/helpers/store'; +import { useAuthStore } from '../../store/authStore'; +import AccountDemoLock from './AccountDemoLock'; + +beforeEach(() => resetAllStores()); + +function renderCards() { + return render( + + + + ); +} + +describe('AccountDemoLock', () => { + it('FE-COMP-ACCOUNTDEMOLOCK-001: the shared demo account sees its cards under the lock, with the reason', () => { + seedStore(useAuthStore, { demoMode: true, user: buildUser({ email: 'demo@trek.app' }) }); + const { container } = renderCards(); + expect(screen.getByRole('note')).toHaveTextContent('The shared demo account cannot be changed.'); + expect(screen.queryByRole('button', { name: 'Save profile' })).not.toBeInTheDocument(); + expect(container.querySelector('[data-demo-lock] [inert]')).toContainElement( + screen.getByRole('button', { hidden: true, name: 'Save profile' }) + ); + }); + + it('FE-COMP-ACCOUNTDEMOLOCK-002: the admin of a demo instance gets the cards as they are', () => { + seedStore(useAuthStore, { demoMode: true, user: buildUser({ email: 'admin@trek.app', role: 'admin' }) }); + const { container } = renderCards(); + expect(screen.queryByRole('note')).not.toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Save profile' })).toBeEnabled(); + expect(container.querySelector('[data-demo-lock]')).toBeNull(); + }); + + it('FE-COMP-ACCOUNTDEMOLOCK-003: the demo address on an instance that is not a demo is left alone', () => { + seedStore(useAuthStore, { demoMode: false, user: buildUser({ email: 'demo@trek.app' }) }); + renderCards(); + expect(screen.queryByRole('note')).not.toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Save profile' })).toBeEnabled(); + }); +}); diff --git a/client/src/components/Settings/AccountDemoLock.tsx b/client/src/components/Settings/AccountDemoLock.tsx new file mode 100644 index 000000000..8b7abfcab --- /dev/null +++ b/client/src/components/Settings/AccountDemoLock.tsx @@ -0,0 +1,23 @@ +import type { ReactNode } from 'react'; +import { useTranslation } from '../../i18n'; +import DemoLock from '../Demo/DemoLock'; +import { useDemoAccountLock } from '../Demo/useDemoLock'; + +/** + * The account cards under the demo lock, on the desktop tab and the phone + * screen alike. Every visitor of a demo instance signs in as the one shared + * demo account, so its profile, password, two factor setup and passkeys stay + * on view but out of reach, while the admin of a demo instance and every + * account of a real one get the cards as they are. Both views wrap their + * cards in this, so whom the lock holds and the reason it gives are written + * once. + */ +export default function AccountDemoLock({ children }: { children: ReactNode }) { + const { t } = useTranslation(); + const locked = useDemoAccountLock(); + return ( + + {children} + + ); +} diff --git a/client/src/components/Settings/AccountTab.tsx b/client/src/components/Settings/AccountTab.tsx index 0089d8050..d00dd6b5c 100644 --- a/client/src/components/Settings/AccountTab.tsx +++ b/client/src/components/Settings/AccountTab.tsx @@ -12,8 +12,7 @@ import { SETTINGS_BUTTON, SETTINGS_BUTTON_DANGER, SETTINGS_BUTTON_PRIMARY, SettingRow, SettingRows, SettingsHint, StatusPill, } from './settingsKit' import { stripTrailingSlashes, useAccountSettings } from './useAccountSettings' -import DemoLock from '../Demo/DemoLock' -import { useDemoAccountLock } from '../Demo/useDemoLock' +import AccountDemoLock from './AccountDemoLock' /** The small turning ring a button shows while its request is on the way. */ const SPINNER = 'h-3.5 w-3.5 flex-none animate-spin rounded-full border-2 border-current border-t-transparent' @@ -24,7 +23,6 @@ const EYEBROW = 'm-0 font-geist font-bold uppercase tracking-[.08em] text-conten export default function AccountTab(): React.ReactElement { const { t } = useTranslation() const blockedLabelId = useId() - const demoLocked = useDemoAccountLock() const { user, demoMode, @@ -75,7 +73,7 @@ export default function AccountTab(): React.ReactElement { return ( <> {/* The shared demo account: everything here is shown, nothing can be changed. */} - +
{/* Who is signed in: the picture with its two actions, the role and the SSO link. */}
@@ -364,7 +362,7 @@ export default function AccountTab(): React.ReactElement { {/* Passkeys */} - + {/* Delete Account Blocked */} {/* The shared demo account: everything here is shown, nothing can be changed. */} - + {/* ── Profile ─────────────────────────────────────────────── */}
@@ -293,7 +291,7 @@ export default function MSettingsAccount() { - +