Files
ukmesh/frontend/test/e2e/mobile.spec.ts

379 lines
16 KiB
TypeScript

import { publicOrigin, dashboardOrigin, devOrigin } from './localServers.js';
import { expect, test, type Page } from '@playwright/test';
import { installMapRoutes, installTerrainRoutes } from './mapFixtures.js';
const PHONE = { width: 375, height: 667 };
const repeaterNodes = Array.from({ length: 12 }, (_, index) => ({
node_id: `node-${index}`,
name: `Repeater ${String(index + 1).padStart(2, '0')}`,
lat: 54 + index * 0.01,
lon: -1 - index * 0.01,
iata: 'TST',
role: 2,
last_seen: '2026-07-18T12:00:00Z',
is_online: true,
public_key: `${String(index).padStart(2, '0')}${'a'.repeat(62)}`,
}));
async function installApiFixtures(page: Page) {
await installMapRoutes(page);
await installTerrainRoutes(page);
await page.addInitScript(() => {
localStorage.setItem('meshcore-cookie-consent-v1', '1');
localStorage.setItem('meshcore-disclaimer-dismissed', '1');
});
await page.route('**/api/**', async (route) => {
const { pathname, searchParams } = new URL(route.request().url());
if (pathname === '/api/runtime-config') return route.fulfill({ json: { version: 1, packetArcs: false, heatmap: false, privacyGeneration: 1, refreshAfterSeconds: 300 } });
if (pathname === '/api/feed/regions') return route.fulfill({ json: { network: 'ukmesh', observer: null, visibilityGeneration: 1, regions: ['LHR'] } });
if (pathname === '/api/stats') {
return route.fulfill({
json: {
packetsDay: 120,
totalNodes: 32,
internationalNodes: 1,
internationalLastSeen: '2026-07-18T12:00:00Z',
internationalLastCountry: 'France',
mqttNodes: 20,
mapNodes: 30,
staleNodes: 2,
},
});
}
if (pathname === '/api/repeaters/firmware') {
return route.fulfill({
json: {
total: 32,
versions: [
{
hardware_model: 'Heltec V3',
firmware_version: 'v1.12.0-public-release-with-long-label',
count: 32,
},
],
},
});
}
if (pathname.endsWith('/packets/recent')) return route.fulfill({ json: [] });
if (pathname.endsWith('/inferred-nodes')) {
return route.fulfill({ json: { inferredNodes: [], inferredActiveNodeIds: [] } });
}
if (pathname === '/api/nodes/map') {
const limit = Number(searchParams.get('limit') ?? 2000);
const nodes = repeaterNodes.slice(0, limit);
return route.fulfill({
json: {
nodes,
page: {
snapshot: '2026-07-18T12:00:00.000Z',
nextCursor: null,
complete: true,
returned: nodes.length,
rowLimit: limit,
},
},
});
}
if (pathname === '/api/node-status/latest') return route.fulfill({ json: [] });
if (pathname === '/api/companion-activity') return route.fulfill({ json: [] });
if (pathname === '/api/owner/session') return route.fulfill({ json: { ok: false } });
return route.fulfill({ json: {} });
});
}
async function expectNoViewportOverflow(page: Page) {
const dimensions = await page.evaluate(() => ({
viewportWidth: window.innerWidth,
documentWidth: document.documentElement.scrollWidth,
bodyWidth: document.body.scrollWidth,
}));
expect(dimensions.documentWidth).toBeLessThanOrEqual(dimensions.viewportWidth);
expect(dimensions.bodyWidth).toBeLessThanOrEqual(dimensions.viewportWidth);
}
const routedViews = [
['UK home', `${publicOrigin}/`],
['UK feed', `${publicOrigin}/feed`],
['UK packets', `${publicOrigin}/feed/packets`],
['UK repeaters', `${publicOrigin}/repeater`],
['UK companions', `${publicOrigin}/companion`],
['UK install', `${publicOrigin}/install`],
['UK open source', `${publicOrigin}/open-source`],
['UK login', `${publicOrigin}/login`],
['UK docs', `${publicOrigin}/docs`],
['test site home', `${devOrigin}/`],
] as const;
test('the documentation footer stays below the first viewport while the article loads', async ({ page }) => {
let release!: () => void;
const hold = new Promise<void>(resolve => { release = resolve; });
await page.route(url => /\/docs(?:-[\w-]+)?\.html$/.test(url.pathname), async route => {
if (route.request().resourceType() === 'fetch') await hold;
await route.continue();
});
try {
await page.goto(`${publicOrigin}/docs`, { waitUntil: 'domcontentloaded' });
await expect(page.getByRole('status').filter({ hasText: 'Loading' })).toBeVisible();
await expect(page.getByRole('contentinfo')).not.toBeInViewport();
} finally {
release();
}
await expect(page.getByRole('heading', { name: 'Radio settings & profile' })).toBeVisible();
await expect(page.getByRole('contentinfo')).not.toBeInViewport();
});
for (const [name, url] of routedViews) {
test(`${name} fits a phone viewport`, async ({ page }) => {
await page.setViewportSize(PHONE);
await installApiFixtures(page);
const pageErrors: string[] = [];
page.on('pageerror', (error) => pageErrors.push(error.message));
await page.goto(url, { waitUntil: 'networkidle' });
await expect(page.locator('body')).toBeVisible();
await expectNoViewportOverflow(page);
expect(pageErrors).toEqual([]);
});
}
test('shared navigation stays compact and dismisses without navigation', async ({ page }) => {
await page.setViewportSize(PHONE);
await installApiFixtures(page);
await page.goto(`${publicOrigin}/feed`, { waitUntil: 'networkidle' });
const openMenu = page.getByRole('button', { name: 'Open menu' });
await openMenu.click();
const menu = page.locator('#site-navigation');
await expect(menu).toBeVisible();
const box = await menu.boundingBox();
expect(box?.height ?? PHONE.height).toBeLessThan(PHONE.height * 0.45);
expect(box?.width ?? PHONE.width).toBeLessThan(PHONE.width);
await page.keyboard.press('Escape');
await expect(menu).toBeHidden();
await openMenu.click();
await page.locator('.site-main').click({ position: { x: 5, y: 5 } });
await expect(menu).toBeHidden();
});
test('shared navigation collapses before tablet links can wrap', async ({ page }) => {
await page.setViewportSize({ width: 768, height: 667 });
await installApiFixtures(page);
await page.goto(`${publicOrigin}/feed`, { waitUntil: 'networkidle' });
const menu = page.locator('#site-navigation');
const openMenu = page.getByRole('button', { name: 'Open menu' });
await expect(openMenu).toBeVisible();
await expect(menu).toBeHidden();
await openMenu.click();
await expect(menu).toBeVisible();
await page.getByRole('button', { name: 'Close menu' }).click();
await expect(menu).toBeHidden();
});
test('phone home and feed give primary content the full available width', async ({ page }) => {
await page.setViewportSize(PHONE);
await installApiFixtures(page);
await page.goto(`${publicOrigin}/`, { waitUntil: 'networkidle' });
const introBox = await page.locator('.site-home__intro').boundingBox();
const panelBox = await page.locator('.site-home__panel').boundingBox();
expect(introBox?.width ?? 0).toBeGreaterThan(330);
expect(panelBox?.width ?? 0).toBeGreaterThan(330);
expect(await page.locator('.site-home__grid').evaluate(
(element) => getComputedStyle(element).gridTemplateColumns.split(' ').length,
)).toBe(1);
await expectNoViewportOverflow(page);
await page.goto(`${publicOrigin}/feed`, { waitUntil: 'networkidle' });
const channelsBox = await page.locator('.uk-feed-channels').boundingBox();
const chatBox = await page.locator('.uk-feed-chat').boundingBox();
expect(channelsBox?.height ?? PHONE.height).toBeLessThan(64);
expect(chatBox?.width ?? 0).toBeGreaterThan(360);
await expect(page.locator('.uk-feed-map')).toBeHidden();
await expect(page.locator('.uk-feed-stats__row')).toBeVisible();
await expectNoViewportOverflow(page);
});
test('tablet home and feed avoid squeezed desktop columns', async ({ page }) => {
await page.setViewportSize({ width: 768, height: 667 });
await installApiFixtures(page);
await page.goto(`${publicOrigin}/`, { waitUntil: 'networkidle' });
expect(await page.locator('.site-home__grid').evaluate(
(element) => getComputedStyle(element).gridTemplateColumns.split(' ').length,
)).toBe(1);
expect((await page.locator('.site-home__intro').boundingBox())?.width ?? 0).toBeGreaterThan(720);
await page.goto(`${publicOrigin}/feed`, { waitUntil: 'networkidle' });
expect((await page.locator('.uk-feed-chat').boundingBox())?.width ?? 0).toBeGreaterThan(740);
await expect(page.locator('.uk-feed-map')).toBeHidden();
await expect(page.locator('.uk-feed-stats__row')).toBeVisible();
for (const width of [1024, 1440]) {
await page.setViewportSize({ width, height: 900 });
const map = (await page.locator('.uk-feed-map').boundingBox())!;
expect(map.width).toBeGreaterThan(250);
expect(map.x + map.width).toBeLessThanOrEqual(width);
await expectNoViewportOverflow(page);
}
});
test('map controls and disclaimer leave the map usable on a phone', async ({ page }) => {
await page.setViewportSize(PHONE);
await installApiFixtures(page);
await page.goto(`${dashboardOrigin}/`, { waitUntil: 'domcontentloaded' });
const find = page.getByRole('button', { name: 'Find', exact: true });
await find.click();
const search = page.getByRole('dialog', { name: 'Find on the map' });
await expect(search.getByRole('combobox', { name: 'Search map nodes' })).toBeVisible();
await page.keyboard.press('Escape');
await expect(search).toHaveCount(0);
await expect(find).toBeFocused();
const layers = page.getByRole('button', { name: 'Layers' });
await layers.click();
const lineOfSight = page.getByRole('button', { name: 'Line of sight' });
await expect(lineOfSight).toBeVisible();
expect((await lineOfSight.boundingBox())?.width ?? 0).toBeGreaterThan(100);
await expect(page.locator('.mobile-menu .watchlist-panel')).not.toHaveAttribute('open', '');
const controlsBox = await page.locator('.mobile-controls').boundingBox();
expect(controlsBox?.height ?? PHONE.height).toBeLessThan(PHONE.height * 0.42);
const mapBox = await page.locator('.map-area').boundingBox();
expect(mapBox?.height ?? 0).toBeGreaterThan(300);
await page.keyboard.press('Escape');
await expect(page.getByRole('dialog', { name: 'Map settings' })).toHaveCount(0);
await expect(layers).toBeFocused();
await page.getByRole('button', { name: 'Data disclaimer' }).click();
const dialog = page.getByRole('dialog', { name: 'Data disclaimer' });
await expect(dialog).toBeVisible();
const dialogBox = await page.locator('.disclaimer-modal').boundingBox();
expect(dialogBox?.y ?? -1).toBeGreaterThanOrEqual(0);
expect((dialogBox?.y ?? PHONE.height) + (dialogBox?.height ?? 1)).toBeLessThanOrEqual(PHONE.height);
await expect(dialog.getByRole('button', { name: 'Got it' })).toBeVisible();
});
test('mobile map menu floats over the map; feed hides behind the Live chip', async ({ page }) => {
await page.setViewportSize(PHONE);
await installApiFixtures(page);
await page.goto(`${dashboardOrigin}/`, { waitUntil: 'domcontentloaded' });
// Default state: compact floating bar, packet feed hidden.
const controlsBox = await page.locator('.mobile-controls').boundingBox();
expect(controlsBox?.height ?? 999).toBeLessThan(90);
await expect(page.locator('.packet-feed')).toBeHidden();
// Live chip reveals the packet feed (and turns Live Feed on if needed).
await page.getByRole('button', { name: /Live/ }).click();
await expect(page.locator('.packet-feed')).toBeVisible();
await page.getByRole('button', { name: /Live/ }).click();
await expect(page.locator('.packet-feed')).toBeHidden();
// Layers menu exposes the map toggles; toggling updates filter state.
await page.getByRole('button', { name: /Layers/ }).click();
await expect(page.locator('.mobile-menu')).toBeVisible();
const terrain = page.getByRole('button', { name: '3D Terrain' });
await page.locator('.mobile-menu .map-advanced-layers > summary').click();
await expect(terrain).toBeVisible();
await terrain.click();
await expect(terrain).toHaveAttribute('aria-pressed', 'true');
// Escape closes the menu.
await page.keyboard.press('Escape');
await expect(page.locator('.mobile-menu')).toBeHidden();
await expectNoViewportOverflow(page);
});
for (const width of [320, 375, 390, 640, 768, 820, 1024, 1280, 1440]) {
test(`live map stays inside the ${width}px viewport and remains UK-only`, async ({ page }) => {
test.setTimeout(60_000);
await installApiFixtures(page);
const apiRequests: string[] = [];
page.on('request', (request) => {
const url = new URL(request.url());
if (url.pathname.startsWith('/api/')) apiRequests.push(url.href);
});
await page.setViewportSize({ width, height: width <= 375 ? 667 : 800 });
await page.goto(`${dashboardOrigin}/?network=teesside`, { waitUntil: 'domcontentloaded' });
await expect(page.locator('.map-area')).toBeVisible({ timeout: 30_000 });
await expect(page.getByLabel('Network region')).toHaveCount(0);
for (const selector of ['.app-shell', '.topbar', '.map-layer', '.map-area']) {
const box = await page.locator(selector).boundingBox();
expect(box, `${selector} should have a box at ${width}px`).not.toBeNull();
expect(box!.x, `${selector} should start inside ${width}px`).toBeGreaterThanOrEqual(0);
expect(box!.x + box!.width, `${selector} should end inside ${width}px`).toBeLessThanOrEqual(width + 0.5);
}
if (width <= 640) {
const mobileControls = page.locator('.mobile-controls');
await expect(mobileControls).toBeVisible();
const controlsBox = await mobileControls.boundingBox();
expect(controlsBox!.x + controlsBox!.width).toBeLessThanOrEqual(width + 0.5);
}
await expectNoViewportOverflow(page);
await expect.poll(() => apiRequests.some((url) => new URL(url).searchParams.get('network') === 'ukmesh')).toBe(true);
expect(apiRequests.some((url) => new URL(url).searchParams.get('network') === 'teesside')).toBe(false);
expect(apiRequests.some((url) => new URL(url).pathname === '/api/observers/health')).toBe(false);
});
}
test('repeater search results stay bounded and scroll inside the menu', async ({ page }) => {
await page.setViewportSize(PHONE);
await installApiFixtures(page);
await page.goto(`${publicOrigin}/repeater`, { waitUntil: 'networkidle' });
await page.getByRole('combobox', { name: 'Search repeaters' }).fill('Repeater');
const results = page.locator('.repeater-search-box__results');
await expect(results.getByRole('option')).toHaveCount(10);
const box = await results.boundingBox();
expect(box?.height ?? PHONE.height).toBeLessThanOrEqual(PHONE.height * 0.47);
const listbox = results.locator('.ui-combobox__listbox');
expect(await listbox.evaluate((element) => element.scrollHeight)).toBeGreaterThan(
await listbox.evaluate((element) => element.clientHeight),
);
await expectNoViewportOverflow(page);
});
test('repeater-tree modal remains centred and fully reachable at every target width', async ({ page }) => {
await installApiFixtures(page);
await page.goto(`${publicOrigin}/feed`, { waitUntil: 'networkidle' });
await page.evaluate(() => {
const overlay = document.createElement('div');
overlay.className = 'disclaimer-overlay';
overlay.dataset.testid = 'path-modal-overlay';
const shell = document.createElement('div');
shell.className = 'ui-dialog-modal';
const dialog = document.createElement('section');
dialog.className = 'ui-dialog uk-feed-path-modal';
dialog.textContent = 'Predicted Repeater Tree';
shell.append(dialog);
overlay.append(shell);
document.body.append(overlay);
});
for (const width of [375, 850, 900, 1024, 1280, 1440]) {
await page.setViewportSize({ width, height: 800 });
const box = await page.locator('.uk-feed-path-modal').boundingBox();
expect(box).not.toBeNull();
expect(box!.x).toBeGreaterThanOrEqual(width <= 640 ? 10 : 16);
expect(box!.x + box!.width).toBeLessThanOrEqual(width - (width <= 640 ? 10 : 16) + 0.5);
expect(Math.abs((box!.x + box!.width / 2) - width / 2)).toBeLessThanOrEqual(0.5);
}
});
test('narrow 320px pages keep primary content inside the viewport', async ({ page }) => {
await page.setViewportSize({ width: 320, height: 568 });
await installApiFixtures(page);
await page.goto(`${publicOrigin}/`, { waitUntil: 'networkidle' });
await expectNoViewportOverflow(page);
const introBox = await page.locator('.site-home__intro').boundingBox();
expect(introBox?.width ?? 320).toBeLessThan(320);
});