fix(demo): the phone welcome lives with the phone dashboard, not under components

components/ may not import from mobile/ (lint:layers). The phone dashboard
mounts the sheet itself, as it already mounted the welcome, and the desktop
dialog no longer asks which shell it is in.
This commit is contained in:
Maurice
2026-11-07 00:33:16 +01:00
parent 55e4bfa11e
commit 7797a9a562
5 changed files with 57 additions and 63 deletions
@@ -1,4 +1,4 @@
import { act, fireEvent, waitFor, within } from '@testing-library/react';
import { act, fireEvent, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { render, screen } from '../../../tests/helpers/render';
@@ -6,10 +6,6 @@ import { resetAllStores, seedStore } from '../../../tests/helpers/store';
import { useAuthStore } from '../../store/authStore';
import DemoWelcome from './DemoWelcome';
// useIsPhone follows matchMedia, which the global stub always answers with false.
const phone = vi.hoisted(() => ({ value: false }));
vi.mock('../../mobile/useIsPhone', () => ({ useIsPhone: () => phone.value }));
beforeEach(() => {
resetAllStores();
seedStore(useAuthStore, { serverTimezone: 'UTC' });
@@ -17,7 +13,6 @@ beforeEach(() => {
afterEach(() => {
vi.useRealTimers();
phone.value = false;
});
describe('DemoWelcome', () => {
@@ -151,18 +146,4 @@ describe('DemoWelcome', () => {
'https://creativecommons.org/licenses/by-sa/3.0/'
);
});
it('FE-COMP-DEMOWELCOME-030: on a phone it is a sheet with the same content and a full-width start', async () => {
phone.value = true;
render(<DemoWelcome />);
const sheet = screen.getByRole('dialog', { name: 'Live demo' });
expect(sheet).toHaveTextContent('Welcome to TREK');
expect(within(sheet).getByTestId('demo-countdown')).toBeInTheDocument();
expect(within(sheet).getByText('Everything resets every hour')).toBeInTheDocument();
expect(within(sheet).getByText('Trip planner')).toBeInTheDocument();
expect(within(sheet).getByText('Automatic backups')).toBeInTheDocument();
expect(within(sheet).getByRole('link', { name: /source code/i })).toHaveAttribute('target', '_blank');
await userEvent.click(within(sheet).getByRole('button', { name: /start exploring/i }));
await waitFor(() => expect(screen.queryByText('Trip planner')).not.toBeInTheDocument());
});
});
@@ -1,7 +1,6 @@
import { ArrowLeft, ArrowRight, Clock, ExternalLink, Images, RotateCcw } from 'lucide-react';
import { lazy, Suspense, useId } from 'react';
import { useTranslation } from '../../i18n';
import { useIsPhone } from '../../mobile/useIsPhone';
import {
DialogButton,
DialogFooter,
@@ -17,7 +16,6 @@ import {
import ErrorBoundary from '../shared/ErrorBoundary';
import TrekIcon from '../shared/TrekIcon';
import { DEMO_FEATURES, DEMO_FULL_VERSION, DEMO_LIMITS, TREK_REPO_URL, type DemoLine } from './demoWelcomeModel';
import MDemoWelcome from './MDemoWelcome';
import { useDemoWelcome } from './useDemoWelcome';
// The credits and their photo list load when a visitor opens them, not with the dashboard.
@@ -140,20 +138,6 @@ export default function DemoWelcome() {
const { t } = useTranslation();
const labelId = useId();
const { open, close, countdown, creditsOpen, backFromCredits, openCredits, closeCredits } = useDemoWelcome();
const phone = useIsPhone();
// On a phone the welcome is a sheet of the phone shell, not the desktop dialog made narrow.
if (phone)
return (
<MDemoWelcome
open={open}
close={close}
countdown={countdown}
creditsOpen={creditsOpen}
openCredits={openCredits}
closeCredits={closeCredits}
/>
);
return (
<DialogShell
@@ -14,7 +14,7 @@ import { useInAppNotificationStore } from '../../../store/inAppNotificationStore
import { useDashboardPlugins } from '../../../components/Dashboard/useDashboardPlugins'
import { useAssistantHomeLauncher } from '../../../components/Assistant/useAssistantHome'
import type { TripCardBadge } from '../../../api/client'
import DemoWelcome from '../../../components/Demo/DemoWelcome'
import MDemoWelcome from './MDemoWelcome'
import { IcsSubscribeModal } from '../../../components/Planner/IcsSubscribeModal'
import PluginWidgets from '../../../components/Plugins/PluginWidgets'
import { entityGradient } from '../../../utils/gradients'
@@ -253,7 +253,7 @@ export default function MDashboard(): React.ReactElement {
<MUserMenu open={menuOpen} onClose={() => setMenuOpen(false)} />
{demoMode && <DemoWelcome />}
{demoMode && <MDemoWelcome />}
<MPullIndicator state={pull} label={t('common.loading')} />
<div ref={contentRef} className="px-4 pb-[calc(var(--bottom-nav-h,84px)+32px)] pt-[calc(var(--m-safe-top,12px)+82px)]">
@@ -0,0 +1,37 @@
import { waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { beforeEach, describe, expect, it } from 'vitest';
import { render, screen } from '../../../../tests/helpers/render';
import { resetAllStores, seedStore } from '../../../../tests/helpers/store';
import { useAuthStore } from '../../../store/authStore';
import MDemoWelcome from './MDemoWelcome';
beforeEach(() => {
resetAllStores();
seedStore(useAuthStore, { serverTimezone: 'UTC' });
});
describe('MDemoWelcome', () => {
it('FE-COMP-DEMOWELCOME-030: on a phone it is a sheet with the same content and a full-width start', async () => {
render(<MDemoWelcome />);
const sheet = screen.getByRole('dialog', { name: 'Live demo' });
expect(sheet).toHaveTextContent('Welcome to TREK');
expect(within(sheet).getByTestId('demo-countdown')).toBeInTheDocument();
expect(within(sheet).getByText('Everything resets every hour')).toBeInTheDocument();
expect(within(sheet).getByText('Trip planner')).toBeInTheDocument();
expect(within(sheet).getByText('Automatic backups')).toBeInTheDocument();
expect(within(sheet).getByRole('link', { name: /source code/i })).toHaveAttribute('target', '_blank');
await userEvent.click(within(sheet).getByRole('button', { name: /start exploring/i }));
await waitFor(() => expect(screen.queryByText('Trip planner')).not.toBeInTheDocument());
});
it('FE-COMP-DEMOWELCOME-031: the photo credits open in its place and lead back', async () => {
render(<MDemoWelcome />);
const sheet = screen.getByRole('dialog', { name: 'Live demo' });
await userEvent.click(within(sheet).getByRole('button', { name: /photo credits/i }));
const back = await within(sheet).findByRole('button', { name: /back/i });
expect(within(sheet).queryByText('Trip planner')).not.toBeInTheDocument();
await userEvent.click(back);
expect(within(sheet).getByText('Trip planner')).toBeInTheDocument();
});
});
@@ -1,26 +1,24 @@
import { ArrowLeft, ArrowRight, Clock, ExternalLink, Images, RotateCcw } from 'lucide-react';
import { lazy, Suspense } from 'react';
import { useTranslation } from '../../i18n';
import MSheet from '../../mobile/components/MSheet';
import { Eyebrow, SHEET_PRIMARY, SHEET_SECONDARY } from '../../mobile/screens/trip/sheets/MTripSheetUi';
import { FormSheetHeader } from '../../mobile/screens/trip/sheets/PlSheetChrome';
import ErrorBoundary from '../shared/ErrorBoundary';
import TrekIcon from '../shared/TrekIcon';
import { DEMO_FEATURES, DEMO_FULL_VERSION, DEMO_LIMITS, TREK_REPO_URL, type DemoLine } from './demoWelcomeModel';
import {
DEMO_FEATURES,
DEMO_FULL_VERSION,
DEMO_LIMITS,
TREK_REPO_URL,
type DemoLine,
} from '../../../components/Demo/demoWelcomeModel';
import { useDemoWelcome } from '../../../components/Demo/useDemoWelcome';
import ErrorBoundary from '../../../components/shared/ErrorBoundary';
import TrekIcon from '../../../components/shared/TrekIcon';
import { useTranslation } from '../../../i18n';
import MSheet from '../../components/MSheet';
import { Eyebrow, SHEET_PRIMARY, SHEET_SECONDARY } from '../trip/sheets/MTripSheetUi';
import { FormSheetHeader } from '../trip/sheets/PlSheetChrome';
const DemoCredits = lazy(() => import('./DemoCredits'));
const DemoCredits = lazy(() => import('../../../components/Demo/DemoCredits'));
type Translate = ReturnType<typeof useTranslation>['t'];
interface MDemoWelcomeProps {
open: boolean;
close: () => void;
countdown: string;
creditsOpen: boolean;
openCredits: () => void;
closeCredits: () => void;
}
const CARD = 'rounded-[18px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)]';
function Lines({ lines, accent, t }: { lines: readonly DemoLine[]; accent?: boolean; t: Translate }) {
@@ -90,15 +88,9 @@ function Welcome({ t }: { t: Translate }) {
* screen. The head stays small so the list gets the room, the start button
* runs the full width, and the two links sit under it.
*/
export default function MDemoWelcome({
open,
close,
countdown,
creditsOpen,
openCredits,
closeCredits,
}: MDemoWelcomeProps) {
export default function MDemoWelcome() {
const { t } = useTranslation();
const { open, close, countdown, creditsOpen, openCredits, closeCredits } = useDemoWelcome();
const title = t(creditsOpen ? 'demo.credits.title' : 'demo.welcome.title');
return (