diff --git a/apps/web/src/components/admin/settings/appearance/__tests__/appearance-view.test.tsx b/apps/web/src/components/admin/settings/appearance/__tests__/appearance-view.test.tsx index c88f7cab1a..33bc7991e1 100644 --- a/apps/web/src/components/admin/settings/appearance/__tests__/appearance-view.test.tsx +++ b/apps/web/src/components/admin/settings/appearance/__tests__/appearance-view.test.tsx @@ -56,6 +56,12 @@ vi.mock('@/lib/server/functions/portal-design', () => ({ return { ok: true, revisionId: 'portal_design_revision_1', number: 1 } }, restorePortalDesignVersionFn: async () => ({ ok: true }), + getPortalDesignSwitchFn: async () => ({ + available: false, + canSwitchBack: false, + report: { errors: [], warnings: [], carried: [] }, + }), + switchBackPortalDesignFn: async () => ({ ok: true }), })) vi.mock('@/lib/client/analytics', () => ({ diff --git a/apps/web/src/components/admin/settings/appearance/__tests__/design-switch.test.tsx b/apps/web/src/components/admin/settings/appearance/__tests__/design-switch.test.tsx new file mode 100644 index 0000000000..a592c28bae --- /dev/null +++ b/apps/web/src/components/admin/settings/appearance/__tests__/design-switch.test.tsx @@ -0,0 +1,152 @@ +// @vitest-environment happy-dom +/** + * A portal with its own CSS is offered the switch on its old Settings › Portal + * page: the CSS report, today's portal beside the switched one, and Switch, + * held back while the CSS has refusals. Once switched, Versions offers the way + * back. + */ +import { afterEach, describe, expect, it, vi } from 'vitest' +import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' +import type { ReactNode } from 'react' +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import type { DesignSwitch } from '@/lib/server/domains/design/switch' + +const server = vi.hoisted(() => ({ + invalidations: 0, + switches: 0, + switchesBack: 0, + outcome: { ok: true } as { ok: true } | { ok: false; code: string; message: string }, +})) + +vi.mock('@tanstack/react-router', () => ({ + useRouter: () => ({ + invalidate: async () => { + server.invalidations++ + }, + }), + ClientOnly: ({ children }: { children: ReactNode }) => <>{children}>, +})) +vi.mock('@/components/admin/settings/branding/portal-preview', () => ({ + PortalPreview: ({ switched }: { switched: boolean }) => ( +
+ ), +})) +vi.mock('@/lib/server/functions/portal-design', () => ({ + getPortalDesignSwitchFn: async () => null, + listPortalDesignVersionsFn: async () => [], + switchPortalDesignFn: async () => { + server.switches++ + return server.outcome + }, + switchBackPortalDesignFn: async () => { + server.switchesBack++ + return server.outcome + }, +})) + +const { portalDesignQueries } = await import('@/lib/client/queries/portal-design') +const { DesignSwitchCard } = await import('../design-switch-card') +const { HistoryDialog } = await import('../history-dialog') + +const REPORT = { + errors: [] as Array<{ message: string; line?: number }>, + warnings: [{ message: '.portal-nav__item is internal and may change.', line: 3 }], + carried: [{ message: '--primary on :root becomes the accent.' }], +} + +function withClient(ui: ReactNode, state: DesignSwitch) { + const client = new QueryClient({ defaultOptions: { queries: { staleTime: Infinity } } }) + client.setQueryData(portalDesignQueries.switch().queryKey, state) + client.setQueryData(portalDesignQueries.versions().queryKey, []) + render(+ Your portal uses custom CSS. Switch to the new design system. +
+ + ++ {refusal} +
+ )} +
{refusal}
@@ -125,6 +149,21 @@ export function HistoryDialog({
+