Files
TREK/client/tests/unit/mobile/MNavRail.test.tsx
T
Maurice 0b7cee0b0d feat(mobile): the trip's tabs, administration, collections and the journal use the large screen
On an iPad or an unfolded foldable the list screens kept one phone-wide
column in the middle of the page. They now lay out for the room they have:

- Transports, bookings, polls and tasks put their cards in a grid of as many
  phone-wide columns as the page holds (CardGrid), three on a 13" iPad on
  its side, two upright, one in a narrow Split View.
- Costs: with room for two panes (split size class) the summary (total,
  owe and owed, settle up, final budget, categories) stands in a pane of its
  own beside the expenses, each scrolling on its own (TabPanes). The search
  field sits in the expenses' column again instead of running past it.
- Files: a grid of tiles with each photo's picture; with room for two panes
  the picked file is previewed beside the grid with what it belongs to and
  its actions, the way Files on an iPad does. The signed preview address
  comes through fileRepo.previewUrl.
- Packing: the categories stand in columns, each card whole in its column;
  the action menu drops from its button at a popover's width.
- To-dos: the four smart filters as tiles and the trip's lists in a pane
  beside the tasks, which take the filter's name as their head.
- Collab: the chat stays in view at the trailing edge beside the notes,
  links or polls, and the header switches only the board. The chat keeps its
  place in the tree, so a fold or a rotation into two panes keeps the draft;
  a chat at its newest message stays there when its box changes size. Notes
  stand as a board in columns.
- Administration and settings share a section list beside the page
  (MSectionNav); the stats grid takes four columns.
- Collections: the lists stand in a column beside the places, which take two
  columns, and the head names the list on show.
- Journal: the entries become a feed beside the map, under their days, with
  photo, place and the start of the story, in step with the map like the
  strip of cards it replaces; it fades out under the header.
- The assistant opens as a tall panel at the trailing edge over a dimmed
  page, as Slide Over would, instead of covering the whole screen.
- The rail fits every name: a word too wide for it shrinks the label before
  it is hyphenated, and the admin entry uses its short name.
- The journeys and notifications headers keep to their column.
- The address screen of the native shell sets the photo as a panel beside
  the choices on a large screen on its side.

On a foldable that reports its fold, a leading pane ends at the fold and a
trailing one starts there. Phones keep their layout.
2026-11-07 23:25:12 +01:00

176 lines
6.7 KiB
TypeScript

import { FolderOpen, Map as MapIcon } from 'lucide-react';
import { useLocation } from 'react-router';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import MNavRail from '../../../src/mobile/components/MNavRail';
import MobileShell from '../../../src/mobile/MobileShell';
import MTripRail from '../../../src/mobile/screens/trip/MTripRail';
import { useAddonStore } from '../../../src/store/addonStore';
import { useAuthStore } from '../../../src/store/authStore';
import { usePluginStore } from '../../../src/store/pluginStore';
import { buildUser } from '../../helpers/factories';
import { fireEvent, render, screen, within } from '../../helpers/render';
import { setSizeClass } from '../../helpers/sizeClass';
// FE-MOB-RAIL-001 onwards
function LocationEcho() {
const location = useLocation();
return <span data-testid="loc">{location.pathname + location.search}</span>;
}
function seedAddons(ids: string[]) {
useAddonStore.setState({
addons: ids.map((id) => ({ id, name: id, type: 'global', icon: 'globe', enabled: true })),
loaded: true,
});
}
const rail = () => screen.getByRole('navigation', { name: 'Navigation' });
describe('MNavRail', () => {
beforeEach(() => {
useAddonStore.setState({ addons: [], loaded: true });
usePluginStore.setState({ plugins: [], loaded: true });
useAuthStore.setState({ user: buildUser({ role: 'user' }) });
});
it('FE-MOB-RAIL-001: holds every destination at once, the ones the dock keeps under More included', () => {
seedAddons(['vacay', 'journey', 'atlas', 'collections']);
render(<MNavRail />, { initialEntries: ['/dashboard'] });
for (const name of ['My Trips', 'Vacay', 'Journey', 'Atlas', 'Collections', 'Settings']) {
expect(within(rail()).getByRole('button', { name })).toBeInTheDocument();
}
expect(within(rail()).queryByRole('button', { name: 'More' })).not.toBeInTheDocument();
expect(within(rail()).queryByRole('button', { name: 'Admin Settings' })).not.toBeInTheDocument();
});
it('FE-MOB-RAIL-002: marks the current section and navigates on a tap', () => {
seedAddons(['atlas']);
render(
<>
<MNavRail />
<LocationEcho />
</>,
{ initialEntries: ['/atlas'] }
);
expect(within(rail()).getByRole('button', { name: 'Atlas' })).toHaveAttribute('aria-current', 'page');
fireEvent.click(within(rail()).getByRole('button', { name: 'My Trips' }));
expect(screen.getByTestId('loc').textContent).toBe('/dashboard');
fireEvent.click(within(rail()).getByRole('button', { name: 'Settings' }));
expect(screen.getByTestId('loc').textContent).toBe('/settings');
});
it('FE-MOB-RAIL-003: administration sits at the foot for an admin, under its short name', () => {
useAuthStore.setState({ user: buildUser({ role: 'admin' }) });
render(<MNavRail />, { initialEntries: ['/dashboard'] });
// The rail names it "Admin" (nav.admin): the avatar menu's "Admin Settings"
// ran to two lines in English and was cut in German.
expect(within(rail()).getByRole('button', { name: 'Admin' })).toBeInTheDocument();
});
it("FE-MOB-RAIL-004: the create button keeps the dock's meaning and its exceptions", () => {
const { unmount } = render(
<>
<MNavRail />
<LocationEcho />
</>,
{ initialEntries: ['/dashboard'] }
);
const create = within(rail()).getAllByRole('button')[0];
fireEvent.click(create);
expect(screen.getByTestId('loc').textContent).toContain('create');
unmount();
render(<MNavRail />, { initialEntries: ['/settings'] });
expect(within(rail()).getAllByRole('button')[0]).toHaveAccessibleName('My Trips');
});
});
describe('MTripRail', () => {
const tabs = [
{ id: 'plan', label: 'Plan' },
{ id: 'transports', label: 'Transport' },
{ id: 'dateien', label: 'Files', icon: FolderOpen },
{ id: 'plugin:x', label: 'Plugin', icon: MapIcon },
];
it('FE-MOB-RAIL-005: every section is in the rail with its name, More keeps the actions', () => {
const onSelect = vi.fn();
const onMore = vi.fn();
render(
<MTripRail
tabs={tabs}
active="transports"
onSelect={onSelect}
onMore={onMore}
labelOf={(id) => tabs.find((x) => x.id === id)?.label ?? id}
/>
);
const nav = screen.getByRole('navigation', { name: 'Trip sections' });
expect(
within(nav)
.getAllByRole('button')
.map((b) => b.getAttribute('title'))
).toEqual(['Plan', 'Transport', 'Files', 'Plugin', 'More']);
expect(within(nav).getByRole('button', { name: 'Transport' })).toHaveAttribute('aria-current', 'page');
fireEvent.click(within(nav).getByRole('button', { name: 'Files' }));
expect(onSelect).toHaveBeenCalledWith('dateien');
fireEvent.click(within(nav).getByRole('button', { name: 'More' }));
expect(onMore).toHaveBeenCalledOnce();
});
});
describe('MobileShell on a wide window', () => {
beforeEach(() => {
useAddonStore.setState({ addons: [], loaded: true });
usePluginStore.setState({ plugins: [], loaded: true });
});
it("FE-MOB-RAIL-006: the rail takes the dock's place and the page column starts after it", () => {
setSizeClass('wide');
const { container } = render(
<MobileShell isPhone>
<p>page body</p>
</MobileShell>,
{ initialEntries: ['/dashboard'] }
);
expect(rail()).toBeInTheDocument();
expect(container.querySelector('.m-dock-vt')?.tagName).toBe('NAV');
expect(container.querySelector('.m-shell')).toBeInTheDocument();
expect(screen.getByText('page body').parentElement?.className).toContain('wide:ps-[var(--m-rail-w)]');
});
it('FE-MOB-RAIL-007: folding back to compact brings the dock back, the page stays mounted', () => {
setSizeClass('wide');
render(
<MobileShell isPhone>
<input aria-label="note" defaultValue="" />
</MobileShell>,
{ initialEntries: ['/dashboard'] }
);
const field = screen.getByLabelText('note') as HTMLInputElement;
fireEvent.change(field, { target: { value: 'typed before the fold' } });
setSizeClass('compact');
expect(screen.queryByRole('navigation', { name: 'Navigation' })).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'My Trips' })).toBeInTheDocument();
expect((screen.getByLabelText('note') as HTMLInputElement).value).toBe('typed before the fold');
expect(screen.getByLabelText('note')).toBe(field);
});
it('FE-MOB-RAIL-008: no rail inside a trip, which brings its own', () => {
setSizeClass('wide');
render(
<MobileShell isPhone>
<p>page body</p>
</MobileShell>,
{ initialEntries: ['/trips/7'] }
);
expect(screen.queryByRole('navigation', { name: 'Navigation' })).not.toBeInTheDocument();
});
});