Files
TREK/client/tests/unit/mobile/shellChrome.test.tsx
T
Maurice fd35f79c36 fix(mobile): keep every screen clear of an iPhone Duo's status capsule
TestFlight feedback: on an iPhone Duo the status capsule in the top right
corner covered the trip's controls, its day chips, the map's category bar and
the first cards of every trip tab, upright and on its side. The app has
measured the capsule since 0f42b8b8a, but only the shell's own bars and page
used it, and the trip, its map and the sheets place their own controls.

- Upright, a control row in the capsule's height stands beside it and the
  content starts below it: the trip's top row and day chips, the map's
  category bar, the road trip's stage bar, every trip tab's first row, the
  places browser, the plan timeline, docked and card sheets, the assistant,
  the account menu, the image viewer's close button, the atlas search,
  vacay's header and a journey's content and map controls.
- On a wide window the page gives up the capsule's side over the whole
  height instead, as an iPhone on its side does for its camera: lifting each
  page below the capsule cost a quarter of the height of an unfolded Duo.
  The list tabs, the assistant panel and the form sheets end before it too.
- Screens whose first row is part of the page (settings, administration,
  collections) are lifted until that row is below the capsule; screens that
  keep clear of it by themselves (atlas, vacay, a journey) are not lifted.
- Right to left the rail stands on the capsule's side and takes it.

All of it reads the corner variables the app publishes, which are 0 on every
other device and before iOS 26, so nothing else moves. The rules for the
screens that place their own controls live in mobile/corner.css.
2026-11-18 21:23:14 +01:00

166 lines
9.5 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
import MGlassBar from '../../../src/mobile/components/MGlassBar';
import { render, screen } from '../../helpers/render';
// FE-MOB-CHROME-001 onwards: the touch shell's own chrome against what the
// desktop pages bring along.
const root = resolve(__dirname, '../../..');
describe('desktop chrome inside the touch shell', () => {
it('FE-MOB-CHROME-001: a page without a phone screen shows no desktop navbar over the rail, and keeps no room for it', () => {
// /plugins/:id, /help and a trip's files still render through PageShell. jsdom
// applies no stylesheet, so the rule and the mark it needs are read from source.
const css = readFileSync(resolve(root, 'src/mobile/mobile.css'), 'utf8');
expect(css).toMatch(/html:has\(\.m-shell\) \{\s*--nav-h: 0px;\s*\}/);
expect(css).toMatch(/html:has\(\.m-shell\) \[data-desktop-navbar\] \{\s*display: none;\s*\}/);
const navbar = readFileSync(resolve(root, 'src/components/Layout/Navbar.tsx'), 'utf8');
expect(navbar).toContain('data-desktop-navbar=""');
});
});
describe('MGlassBar', () => {
it('FE-MOB-CHROME-002: a floating bar stands in the content column, padded and capped like it', () => {
render(
<MGlassBar column="wide:max-w-[1280px]">
<span>bar</span>
</MGlassBar>
);
const bar = screen.getByText('bar').parentElement as HTMLElement;
const column = bar.parentElement as HTMLElement;
expect(column.className).toContain('px-4');
expect(column.className).toContain('wide:px-6');
expect(column.className).toContain('wide:max-w-[1280px]');
expect(column.parentElement?.className).toContain('m-span-x');
// The strip around the bar lets taps through to the page.
expect(column.parentElement?.className).toContain('pointer-events-none');
expect(bar.className).toContain('pointer-events-auto');
});
it('FE-MOB-CHROME-003: in flow it is the bar alone', () => {
const { container } = render(
<MGlassBar floating={false}>
<span>bar</span>
</MGlassBar>
);
expect(container.firstElementChild).toBe(screen.getByText('bar').parentElement);
});
});
describe('safe area in the touch shell', () => {
// jsdom applies no stylesheet and has no env(), so the rules are read from source.
const css = readFileSync(resolve(root, 'src/mobile/mobile.css'), 'utf8');
it('FE-MOB-CHROME-004: the top clearance takes env() with the measurement of the app as a floor, never in its place', () => {
expect(css).toContain('--m-safe-t: max(env(safe-area-inset-top, 0px), var(--trek-native-safe-top, 0px));');
expect(css).toContain('--m-safe-top: calc(var(--m-safe-t) + 12px);');
expect(css).toContain('--m-safe-l: max(env(safe-area-inset-left, 0px), var(--trek-native-safe-left, 0px));');
expect(css).toContain('--m-safe-r: max(env(safe-area-inset-right, 0px), var(--trek-native-safe-right, 0px));');
});
it('FE-MOB-CHROME-005: without the rail the floating bars keep clear of a side inset, such as a camera in a corner', () => {
const narrow = "html:not(:has(.m-shell[data-size='wide'], .m-shell[data-size='split'])) :is(.m-bar-x, .m-span-x) {";
const rule = css.split(narrow)[1]?.split('}')[0] ?? '';
expect(rule).toContain('margin-inline: var(--m-safe-l-gap, 0px) var(--m-safe-r-gap, 0px);');
// The insets are the screen's: right to left takes them the other way round.
const rtl = css.split(`html[dir='rtl']${narrow.slice('html'.length)}`)[1]?.split('}')[0] ?? '';
expect(rtl).toContain('margin-inline: var(--m-safe-r-gap, 0px) var(--m-safe-l-gap, 0px);');
// On a wide window the bars keep no side margin, so mx-auto still centres them.
for (const cls of ['m-bar-x', 'm-span-x']) {
expect(css.split(`\n.${cls} {`)[1]?.split('}')[0] ?? '').not.toContain('margin');
}
});
it('FE-MOB-CHROME-006: a side inset gets a little air, and none where there is no inset', () => {
expect(css).toContain('--m-safe-r-gap: calc(var(--m-bar-r) + min(var(--m-bar-r), 8px));');
expect(css).toContain('--m-safe-l-gap: calc(var(--m-bar-l) + min(var(--m-bar-l), 8px));');
});
it('FE-MOB-CHROME-007: on a wide window the bars end before the trailing inset, by their box, not a margin', () => {
const wide = "html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-bar-x {";
expect(css.split(wide)[1]?.split('}')[0] ?? '').toContain(
'inset-inline-end: calc(16px + var(--m-safe-r-gap, 0px));'
);
const rtl = `html[dir='rtl']:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-bar-x {`;
expect(css.split(rtl)[1]?.split('}')[0] ?? '').toContain(
'inset-inline-end: calc(16px + var(--m-safe-l-gap, 0px));'
);
});
it('FE-MOB-CHROME-008: the page keeps clear of the side insets, the leading one left to the rail on a wide window', () => {
expect(css.split('\n.m-page {')[1]?.split('}')[0] ?? '').toContain(
'margin-inline: var(--m-page-l, 0px) var(--m-page-r, 0px);'
);
expect(css.split("html[dir='rtl'] .m-page {")[1]?.split('}')[0] ?? '').toContain(
'margin-inline: var(--m-page-r, 0px) var(--m-page-l, 0px);'
);
const wide = "html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-page {";
expect(css.split(wide)[1]?.split('}')[0] ?? '').toContain('margin-inline-start: 0;');
});
it('FE-MOB-CHROME-009: an element in a top corner moves the bars beside it and the page below it, not a whole strip aside', () => {
// The bars avoid the wider of the side inset and the corner element.
expect(css).toContain('--m-bar-r: max(var(--m-safe-r), var(--trek-native-corner-right, 0px));');
expect(css).toContain('--m-bar-l: max(var(--m-safe-l), var(--trek-native-corner-left, 0px));');
// The page gives the corner's width back and starts below the corner instead.
expect(css).toContain('--m-page-r: max(0px, var(--m-safe-r) - var(--trek-native-corner-right, 0px));');
expect(css).toContain('--m-page-l: max(0px, var(--m-safe-l) - var(--trek-native-corner-left, 0px));');
expect(css.split('\n.m-page {')[1]?.split('}')[0] ?? '').toContain(
'padding-top: max(0px, calc(var(--m-corner-clear, 0px) + 2px - var(--m-safe-top, 12px) - 70px));'
);
expect(css).toContain('--m-corner-clear: calc(var(--m-corner-b) + min(var(--m-corner-b), 10px));');
// Without a corner element (every other device, iOS before 26) nothing moves.
expect(css).toContain('--m-corner-b: var(--trek-native-corner-bottom, 0px);');
});
it('FE-MOB-CHROME-010: on a wide window the page ends before a corner element instead of starting below it', () => {
const wideRoot = "html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-root {";
const block = css.split(wideRoot)[1]?.split('}')[0] ?? '';
expect(block).toContain('--m-corner-clear: 0px;');
expect(block).toContain('--m-corner-side-r: var(--m-corner-r-gap);');
expect(block).toContain('--m-rail-w: calc(var(--m-bar-l) + 100px);');
const widePage = "html:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-page {";
expect(css.split(widePage)[1]?.split('}')[0] ?? '').toContain(
'margin-inline-end: max(var(--m-page-r, 0px), var(--m-corner-side-r, 0px));'
);
// Right to left the rail stands on the corner's side and takes it.
const rtlRoot = "html[dir='rtl']:has(.m-shell[data-size='wide'], .m-shell[data-size='split']) .m-root {";
const rtl = css.split(rtlRoot)[1]?.split('}')[0] ?? '';
expect(rtl).toContain('--m-rail-w: calc(var(--m-bar-r) + 100px);');
expect(rtl).toContain('--m-corner-side-r: 0px;');
});
it('FE-MOB-CHROME-011: the screens that place their own controls keep them beside a corner element and their content below it', () => {
const corner = readFileSync(resolve(root, 'src/mobile/corner.css'), 'utf8');
expect(corner).toMatch(
/\.m-corner-beside \{\s*margin-inline: var\(--m-corner-l-gap, 0px\) var\(--m-corner-r-gap, 0px\);/
);
// The element stays where the hardware has it, so right to left swaps the sides back.
expect(corner).toMatch(
/html\[dir='rtl'\] \.m-corner-beside \{\s*margin-inline: var\(--m-corner-r-gap, 0px\) var\(--m-corner-l-gap, 0px\);/
);
expect(corner).toMatch(
/\.m-corner-side \{\s*margin-inline: var\(--m-corner-side-l, 0px\) var\(--m-corner-side-r, 0px\);/
);
expect(css).toMatch(/\.m-page:has\(\.m-corner-own\) \{\s*padding-top: 0;/);
expect(readFileSync(resolve(root, 'src/mobile/MobileShell.tsx'), 'utf8')).toContain("import './corner.css'");
const src = (file: string) => readFileSync(resolve(root, 'src', file), 'utf8');
const shell = src('mobile/screens/trip/MTripShell.tsx');
// The top row and the day chips stand beside it, a list tab ends before it on a wide window.
expect(src('mobile/screens/trip/MTripShellParts.tsx')).toContain("CHROME_ROW = 'm-corner-beside absolute end-4");
expect(shell.match(/\$\{CHROME_ROW\}/g)).toHaveLength(2);
expect(shell).toContain('<div className="m-corner-side relative h-full">');
expect(src('mobile/screens/trip/map/MMapArea.tsx')).toContain('m-corner-beside pointer-events-none absolute end-4');
// A list tab's first row and a docked sheet start below it.
expect(src('mobile/screens/trip/tabs/tabChrome.tsx')).toContain(
'pt-[max(calc(var(--m-safe-top,12px)+58px),var(--m-corner-clear,0px))]'
);
expect(src('mobile/components/MSheet.tsx')).toContain(
'top-[max(calc(var(--m-safe-top,12px)+56px),var(--m-corner-clear,0px))]'
);
expect(src('mobile/components/MSectionNav.tsx')).toContain("'m-corner-flow px-4 ");
});
});