Files
TREK/client/tests/unit/mobile/trip/MTripShell.wide.test.tsx
T
Maurice c204a25a9c feat(mobile): the touch shell laid out for iPad and unfolded foldables
The app shows the touch shell at every size now, an iPad's and an unfolded
foldable's included, instead of switching to the desktop pages from 768px.
One route tree survives rotation, Split View, Stage Manager and folding, and
the app's own features (Wallet, sharing into a trip, the edge swipe back)
are there on the big screen too.

Two size classes drive the layout (hooks/sizeClass.ts, Tailwind variants
wide: and split:):

- wide (600pt and taller than a phone on its side): a glass navigation rail
  on the leading edge replaces the dock and holds every destination with its
  name; sheets become centred form sheets; the trip's More menu is a popover
  beside the rail; lists keep a readable measure; dashboard, journey and
  vacay get columns; full-bleed maps run under the floating rail.
- split (900pt): the trip's plan, places or road trip chain sit in a pane
  beside the map, which follows the plan's day; the list/map switch hides
  and shows the pane like a sidebar; on a foldable that reports its fold the
  pane ends at the fold. Settings show their sections beside the page and the
  dashboard keeps its widgets in a column of their own.

A hardware keyboard gets the shortcuts an iPad app has (⌘1 to ⌘9 for the
sections, ⌘N, ⌘, , ⌥←/⌥→ through the days, ⌃⌘S for the pane, ⌘[ back),
answered by the page or, with a binary that has the keyCommands feature,
handed to it as native key commands.

The day strip fades at an edge that runs on, journey cards grow on a wide
window and a card without a photo takes the day's colour, and the Leaflet
map measures itself again when its box changes size.
2026-11-07 23:25:12 +01:00

186 lines
8.3 KiB
TypeScript

import { http, HttpResponse } from 'msw';
import { useEffect } from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import MKeyboardHost from '../../../../src/mobile/keyboard/MKeyboardHost';
import { useShortcutRegistry } from '../../../../src/mobile/keyboard/shortcuts';
import type { MTripShellApi, TripPlanner } from '../../../../src/mobile/screens/trip/MTripShell';
import { useAuthStore } from '../../../../src/store/authStore';
import { useDocSyncOfferStore } from '../../../../src/store/docSyncOfferStore';
import type { Day } from '../../../../src/types';
import { buildPlanner } from '../../../helpers/mobileTrip';
import { server } from '../../../helpers/msw/server';
import { fireEvent, render, screen, within } from '../../../helpers/render';
import { setSizeClass } from '../../../helpers/sizeClass';
import { seedStore } from '../../../helpers/store';
// FE-MOB-SHELLW-001 onwards: the trip screen on a wide window (iPad, foldable unfolded).
const mocks = vi.hoisted(() => ({ planner: {} as TripPlanner }));
vi.mock('../../../../src/pages/tripPlanner/useTripPlanner', () => ({
useTripPlanner: () => mocks.planner,
}));
vi.mock('../../../../src/mobile/screens/trip/plan/MPlanTimeline', () => ({ default: () => null }));
vi.mock('../../../../src/mobile/screens/trip/map/MMapArea', () => ({ default: () => null }));
vi.mock('../../../../src/mobile/screens/trip/places/MPlacesBrowser', () => ({ default: () => null }));
vi.mock('../../../../src/mobile/screens/trip/tabs/MTripTabPanel', () => ({ default: () => null }));
vi.mock('../../../../src/mobile/screens/trip/sheets/MTripSheets', () => ({ default: () => null }));
import MTripShell from '../../../../src/mobile/screens/trip/MTripShell';
// Recorded through spies, not module variables a render would write to.
const seen = vi.fn<(shell: MTripShellApi) => void>();
const mapMounted = vi.fn();
const shellApi = () => seen.mock.lastCall?.[0] as MTripShellApi;
function slot(testId: string) {
return function Slot({ shell }: { planner: TripPlanner; shell: MTripShellApi }) {
seen(shell);
return <div data-testid={testId} />;
};
}
const PlanTimelineSlot = slot('plan-timeline');
const PlacesBrowserSlot = slot('places-browser');
const SheetsSlot = slot('sheets');
function MapAreaSlot({ shell }: { planner: TripPlanner; shell: MTripShellApi }) {
seen(shell);
useEffect(() => {
mapMounted();
}, []);
return <div data-testid="map-area" />;
}
function TabSlot({ shell, tab }: { planner: TripPlanner; shell: MTripShellApi; tab: string }) {
seen(shell);
return <div data-testid="tab-panel">{tab}</div>;
}
const TRIP_TABS = [
{ id: 'plan', label: 'Plan' },
{ id: 'transports', label: 'Transport' },
{ id: 'buchungen', label: 'Bookings' },
{ id: 'finanzplan', label: 'Budget' },
{ id: 'listen', label: 'Lists' },
{ id: 'dateien', label: 'Files' },
{ id: 'collab', label: 'Collaboration' },
];
const DAYS = [
{ id: 11, trip_id: 1, day_number: 1, date: '2026-05-02', title: null },
{ id: 12, trip_id: 1, day_number: 2, date: '2026-05-03', title: null },
{ id: 13, trip_id: 1, day_number: 3, date: '2026-05-04', title: null },
] as unknown as Day[];
function renderShell(overrides: Partial<TripPlanner> = {}) {
mocks.planner = buildPlanner({ days: DAYS, selectedDayId: 12, TRIP_TABS, ...overrides } as Partial<TripPlanner>);
return render(
<>
<MKeyboardHost />
<MTripShell
PlanTimeline={PlanTimelineSlot}
MapArea={MapAreaSlot}
PlacesBrowser={PlacesBrowserSlot}
TabPanel={TabSlot}
Sheets={SheetsSlot}
/>
</>
);
}
const tripRail = () => screen.getByRole('navigation', { name: 'Trip sections' });
const root = (container: HTMLElement) => container.querySelector('.m-trip') as HTMLElement;
describe('MTripShell on a wide window', () => {
beforeEach(() => {
sessionStorage.clear();
seen.mockClear();
mapMounted.mockClear();
useShortcutRegistry.setState({ lists: [] });
useDocSyncOfferStore.setState({ bound: {}, providers: null });
seedStore(useAuthStore, { user: null, isAuthenticated: false });
server.use(
http.get('/api/trips/:tripId/docsync/providers', () => HttpResponse.json([])),
http.get('/api/trips/:tripId/docsync/links', () => HttpResponse.json([]))
);
});
it('FE-MOB-SHELLW-001: the sections stand in a rail, every one of them, instead of the dock', () => {
setSizeClass('wide');
renderShell();
const labels = within(tripRail())
.getAllByRole('button')
.map((b) => b.getAttribute('title'));
expect(labels).toEqual(['Plan', 'Transport', 'Bookings', 'Budget', 'Lists', 'Files', 'Collaboration', 'More']);
fireEvent.click(within(tripRail()).getByRole('button', { name: 'Files' }));
expect(mocks.planner.handleTabChange).toHaveBeenCalledWith('dateien');
fireEvent.click(within(tripRail()).getByRole('button', { name: 'More' }));
expect(shellApi().sheet).toEqual({ id: 'mehr', payload: undefined });
});
it('FE-MOB-SHELLW-002: with room for two panes the plan sits beside the map, which follows its day', () => {
setSizeClass('split');
const { container } = renderShell();
expect(screen.getByTestId('plan-timeline')).toBeInTheDocument();
expect(shellApi().paneOpen).toBe(true);
// The map is on screen too, so its chrome is up and "show on map" has nowhere to go.
expect(shellApi().mapFront).toBe(true);
expect(root(container).style.getPropertyValue('--trip-pane')).toBe('var(--trip-pane-open)');
expect(mocks.planner.autoShowRoute).toHaveBeenCalled();
expect(mocks.planner.setExpandedDayIds).toHaveBeenCalledWith(new Set([12]));
});
it('FE-MOB-SHELLW-003: the switch hides and shows the pane like a sidebar, the map runs under the rail meanwhile', () => {
setSizeClass('split');
const { container } = renderShell();
fireEvent.click(screen.getByRole('button', { name: 'mobileTrip.hidePane' }));
expect(shellApi().paneOpen).toBe(false);
expect(screen.queryByTestId('plan-timeline')).not.toBeInTheDocument();
expect(root(container).style.getPropertyValue('--trip-map-start')).toBe('0px');
expect(root(container).style.getPropertyValue('--trip-map-inset')).toBe('var(--m-rail-w)');
fireEvent.click(screen.getByRole('button', { name: 'mobileTrip.showPane' }));
expect(shellApi().paneOpen).toBe(true);
expect(screen.getByTestId('plan-timeline')).toBeInTheDocument();
});
it('FE-MOB-SHELLW-004: folding to compact mid-plan keeps the map and the day, and brings the dock back', () => {
setSizeClass('split');
renderShell();
const mountsBefore = mapMounted.mock.calls.length;
setSizeClass('compact');
expect(screen.queryByRole('navigation', { name: 'Trip sections' })).not.toBeInTheDocument();
// The dock's More, named by the planner's t like the rest of the dock.
expect(screen.getByRole('button', { name: 'mobileTrip.more' })).toBeInTheDocument();
expect(shellApi().paneOpen).toBe(false);
expect(shellApi().view).toBe('plan');
expect(screen.getByTestId('plan-timeline')).toBeInTheDocument();
// The same map instance, not a new one: a remount reloads every tile.
expect(mapMounted).toHaveBeenCalledTimes(mountsBefore);
});
it('FE-MOB-SHELLW-005: a hardware keyboard switches sections, steps through days and toggles the pane', () => {
setSizeClass('split');
renderShell();
fireEvent.keyDown(document.body, { key: '3', metaKey: true });
expect(mocks.planner.handleTabChange).toHaveBeenCalledWith('buchungen');
fireEvent.keyDown(document.body, { key: 'ArrowRight', altKey: true });
expect(mocks.planner.handleSelectDay).toHaveBeenCalledWith(13, true);
fireEvent.keyDown(document.body, { key: 'ArrowLeft', altKey: true });
expect(mocks.planner.handleSelectDay).toHaveBeenCalledWith(11, true);
fireEvent.keyDown(document.body, { key: 's', metaKey: true, ctrlKey: true });
expect(shellApi().paneOpen).toBe(false);
fireEvent.keyDown(document.body, { key: '[', metaKey: true });
expect(mocks.planner.navigate).toHaveBeenCalledWith('/dashboard');
});
it('FE-MOB-SHELLW-006: the phone keeps its dock and its full-screen plan', () => {
renderShell();
expect(screen.queryByRole('navigation', { name: 'Trip sections' })).not.toBeInTheDocument();
expect(shellApi().paneOpen).toBe(false);
expect(shellApi().mapFront).toBe(false);
expect(screen.getByRole('button', { name: 'mobileTrip.mapView' })).toBeInTheDocument();
});
});