From 5740d28d1900bdf0776120cf70327457d70e57f2 Mon Sep 17 00:00:00 2001 From: dborup Date: Wed, 2 Dec 2026 12:56:34 +0000 Subject: [PATCH 1/5] test(live): reproduce the controls panel covering the map buttons (#1055) Owner report: with "Kommune: Aarhus" selected, the open MESH LIVE panel spans the full width and hides the zoom buttons, and its notice adds two rows. The new E2E checks, at 1920x870, 1280x800, 768x1024 and 375x560 in light and dark, that the panel meets no map button, bar or legend, that the notice is one line with a "why?" explanation, and that a DAGI selection adds at most one row. The unit tests pin the shared short strings and the notice's parts. Co-Authored-By: Claude Opus 5.5 --- scripts/e2e-shards.json | 1 + test-1055-live-dagi.js | 77 ++++++-- test-issue-1055-live-panel-e2e.js | 295 ++++++++++++++++++++++++++++++ tests/e2e-1055-live-server.js | 79 ++++++++ 4 files changed, 441 insertions(+), 11 deletions(-) create mode 100644 test-issue-1055-live-panel-e2e.js create mode 100644 tests/e2e-1055-live-server.js diff --git a/scripts/e2e-shards.json b/scripts/e2e-shards.json index c3755aaaa..17de7c452 100644 --- a/scripts/e2e-shards.json +++ b/scripts/e2e-shards.json @@ -359,6 +359,7 @@ {"file":"test-issue-740-m3b-boundary-layer-e2e.js","shard":1,"env":{"BASE_URL":"$BASE_URL"},"output":"e2e","meanSeconds":20,"measurementNote":"New suite; #740 M3b follow-up, one selected-boundary layer on the Map against the real server (only the two Area endpoints are fulfilled, with one Area near Aarhus): at 1440x900 in light and dark, an Area and a DAGI code both set draw only the Area outline and fetch no polygon, Area All brings the DAGI outline, the one Selected area outline checkbox and storage key hide and show it with no new request, both outlines are in --geo-filter-color and markup in the DAGI credit is shown as text; at 1440x600 the beside popover follows its trigger when the Map Controls panel scrolls; a reload draws the outline from the browser cache or a 304. About 20 s locally; no CI duration measured yet. Assigned to shard 1, the lightest by the sum of meanSeconds."}, {"file":"test-issue-740-m3c-dagi-analytics-e2e.js","shard":1,"env":{"BASE_URL":"$BASE_URL"},"output":"e2e","meanSeconds":30,"measurementNote":"New suite; #740 M3c the existing Analytics tabs honour the DAGI selection, against the real server unmocked: at 375x560 touch in light and dark from a cold #/analytics?tab=rf with real taps only, the DAGI control beside Region/Area opens its bottom sheet, aar and a tap on Aarhus put kommune=0751 in the hash next to tab=rf and on the RF request, the notice shows the server's GET /api/analytics/dagi-unpositioned count, a tap on Channels says the filter does not apply there, and the clear takes it all away with no sideways scroll; at 1440x900 every tab that honours Area sends kommune=0751 on all its requests (never an unfiltered one first) with no 400, the ten tabs that cannot honour it say so in light and dark and send no DAGI param of their own, an unknown code is never sent and leaves the hash, the hash keeps kommune across a tab and a window change, and a second selection is a new request while the hidden count is asked for once. About 30 s locally; no CI duration measured yet. Assigned to shard 1, the lightest by the sum of meanSeconds."}, {"file":"test-issue-1055-m2-live-dagi-e2e.js","shard":3,"env":{"CHROMIUM_REQUIRE":"1","CORESCOPE_SERVER_BIN":"./corescope-server","CORESCOPE_MIGRATE_BIN":"./corescope-migrate"},"output":"e2e","meanSeconds":30,"measurementNote":"New suite; #1055 M2 the DAGI filter on Live and the Area filter on the Live feed, on its own Go server (ports from 13900, a migrated copy of the fixture seeded with test-fixtures/seed-1055-live-dagi-nodes.sql: two nodes in Aarhus kommune, one in Copenhagen, one in Odense; one test area AARHUS): a cold #/live?kommune=0751 link selects Aarhus, filters the map nodes, draws the outline without moving the map and makes one member request; injected live packets: member ADVERTs shown, a non-member ADVERT and a non-advert dropped, no request per packet; the desktop popover is not covered by the feed; a perf bound on 30,000 Live-shaped messages; Area AARHUS filters the feed with its notice and outline, Area AND DAGI passes nobody and the Area outline keeps the slot; leaving Live leaves no listener; a pick and a clear keep follow= and kiosk=1, a saved choice is written into a kiosk link; at 375x560 with touch from a cold start on Home, real taps open the controls, the bottom sheet (not covered), pick Aarhus (the controls close over the fitted map) and clear it. About 30s locally; no CI duration measured yet. Assigned to shard 3, the lightest by meanSeconds.","secondsByExecution":[]}, + {"file":"test-issue-1055-live-panel-e2e.js","shard":2,"env":{"CHROMIUM_REQUIRE":"1","CORESCOPE_SERVER_BIN":"./corescope-server","CORESCOPE_MIGRATE_BIN":"./corescope-migrate"},"output":"e2e","meanSeconds":180,"measurementNote":"New suite; #1055 owner report, the Live controls panel and the map buttons, on its own Go server (tests/e2e-1055-live-server.js: ports from 13900, a migrated copy of the fixture seeded with test-fixtures/seed-1055-live-dagi-nodes.sql, one test area AARHUS): at 1920x870, 1280x800, 768x1024 and 375x560, light and dark, with the controls open, with no selection, Area only, Kommune Aarhus, and Aarhus plus Area AARHUS, the panel meets no map button, the VCR bar, the credit or the legend, and each button is the element at its centre; the notice is one line with the rule and the count and its explanation opens under why?; a DAGI selection grows the panel by at most one row; the open or closed controls survive a reload. About 6 min on a slow 4-vCPU local VM (16 page loads, 89 steps); no CI duration measured yet. Assigned to shard 2, the lightest by meanSeconds.","secondsByExecution":[]}, {"file":"test-issue-1076-recommended-adverts-e2e.js","shard":1,"env":{"BASE_URL":"$BASE_URL"},"output":"e2e","meanSeconds":40,"measurementNote":"New suite; #1076 M1 recommended advert settings check on the My Mesh card and the health panel for the #245 seed repeaters (seed-245-advert-intervals.sql), with nodes.recommendedAdverts added to the real /api/config/client response: meshguide.dk values give zero-hop on and flood shorter deviations with the CLI fix and the source link on both cards at 1280x900 and 375x560 (touch), and in the health panel after a real tap on Full health; floodIntervalHours 24 gives no deviation observed; minObservations 20 gives not enough data; the fixture's own config (off) has no nodes block and shows no check on the card or in the health panel. About 40s locally; no CI duration measured yet. Assigned to shard 1, the lightest by meanSeconds.","secondsByExecution":[]} ] } diff --git a/test-1055-live-dagi.js b/test-1055-live-dagi.js index efca6bfc0..6645a4faf 100644 --- a/test-1055-live-dagi.js +++ b/test-1055-live-dagi.js @@ -73,8 +73,16 @@ test('packets.js builds its DAGI notice from the shared text, for DAGI only (no assert.ok(!/only adverts are shown/.test(fn), 'packets.js still has its own copy of the text'); }); +// The notice (#1055 owner report): one short line (the rule, and the count +// for DAGI) whose title is the explanation, which "why?" opens below it. function noticeCtx(o) { const el = { textContent: '', hidden: true }; + const parts = { + liveScopeLine: { title: '' }, + liveScopeRule: { textContent: '' }, + liveScopeCount: { textContent: '' }, + liveScopeWhy: { textContent: '' }, + }; const chip = { textContent: '', hidden: true }; const placeholder = { textContent: 'Waiting for packets…' }; let hiddenCalls = 0; @@ -83,7 +91,7 @@ function noticeCtx(o) { ScopeMemberFilter: loadScopeFilter(), AreaFilter: { getAreaParam: () => o.area || '' }, document: { - getElementById: (id) => (id === 'liveScopeNotice' ? el : id === 'liveMemberLoading' ? chip : null), + getElementById: (id) => (id === 'liveScopeNotice' ? el : id === 'liveMemberLoading' ? chip : parts[id] || null), querySelector: (q) => (q === '#liveFeed .live-feed-empty' ? placeholder : null), }, liveNoticeGeneration: 0, @@ -95,6 +103,7 @@ function noticeCtx(o) { queryString: () => o.dagi, hiddenCount: () => { hiddenCalls++; return Promise.resolve(o.hidden || 0); }, hiddenNotice: (n) => (n > 0 ? n + ' nodes have no position.' : ''), + hiddenShort: (n) => (n > 0 ? n + ' nodes without position' : ''), }; } vm.createContext(ctx); @@ -102,16 +111,21 @@ function noticeCtx(o) { // declares the FEED_* texts and memberLoadingText that sit between them. vm.runInContext(liveFn('liveScopeSelection') + liveFn('liveMemberScopesReady') + liveFn('renderLiveScopeNotice') + liveFn('renderMemberLoading') + liveFn('feedEmptyText'), ctx); - return { ctx, el, chip, placeholder, hiddenCalls: () => hiddenCalls }; + return { + ctx, el, chip, placeholder, hiddenCalls: () => hiddenCalls, + why: parts.liveScopeWhy, line: parts.liveScopeLine, rule: parts.liveScopeRule, count: parts.liveScopeCount, + }; } test('Live notice: hidden with no selection', async () => { const t = noticeCtx({ dagi: '' }); - t.el.hidden = false; t.el.textContent = 'old'; + t.el.hidden = false; t.why.textContent = 'old'; t.rule.textContent = 'old'; t.count.textContent = 'old'; t.ctx.renderLiveScopeNotice(); await settle(); assert.strictEqual(t.el.hidden, true); - assert.strictEqual(t.el.textContent, ''); + assert.strictEqual(t.why.textContent, ''); + assert.strictEqual(t.rule.textContent, ''); + assert.strictEqual(t.count.textContent, ''); assert.strictEqual(t.hiddenCalls(), 0, 'no hidden-count request without DAGI'); }); @@ -120,15 +134,23 @@ test('Live notice: Area on the feed (decision 1) shows the Area text', async () t.ctx.renderLiveScopeNotice(); await settle(); assert.strictEqual(t.el.hidden, false); - assert.match(t.el.textContent, /^Area filter: only adverts are shown/); + assert.match(t.why.textContent, /^Area filter: only adverts are shown/); + assert.strictEqual(t.rule.textContent, 'Adverts only'); + assert.strictEqual(t.count.textContent, '', 'no DAGI, no count'); + assert.strictEqual(t.line.title, t.why.textContent); }); test('Live notice: a checked DAGI code shows the Packets text plus the hidden count', async () => { const t = noticeCtx({ dagi: '&kommune=0751', hidden: 4 }); t.ctx.renderLiveScopeNotice(); - assert.strictEqual(t.el.textContent, PACKETS_TEXT, 'the text shows before the count answers'); + assert.strictEqual(t.why.textContent, PACKETS_TEXT, 'the text shows before the count answers'); + assert.strictEqual(t.rule.textContent, 'Adverts only'); + assert.strictEqual(t.count.textContent, ''); await settle(); - assert.strictEqual(t.el.textContent, PACKETS_TEXT + ' 4 nodes have no position.'); + assert.strictEqual(t.why.textContent, PACKETS_TEXT + ' 4 nodes have no position.'); + assert.strictEqual(t.line.title, t.why.textContent, 'the explanation is the line\'s title'); + assert.strictEqual(t.rule.textContent, 'Adverts only'); + assert.strictEqual(t.count.textContent, '4 nodes without position'); assert.strictEqual(t.el.hidden, false); }); @@ -139,7 +161,8 @@ test('Live notice: a late hidden count of an older selection does not come back' t.ctx.renderLiveScopeNotice(); await settle(); assert.strictEqual(t.el.hidden, true); - assert.strictEqual(t.el.textContent, ''); + assert.strictEqual(t.why.textContent, ''); + assert.strictEqual(t.count.textContent, '', 'the late count came back'); }); test('advertsOnlyNotice: loading says no packet is shown yet (review F1)', () => { @@ -160,15 +183,46 @@ test('advertsOnlyNotice: an Area with no member says it filters nothing (review assert.strictEqual(S.advertsOnlyNotice({ dagi: true, areaEmpty: true }), PACKETS_TEXT, 'areaEmpty without an Area is ignored'); }); +test('advertsOnlyShort: the one-line rule for each state, \'\' for none (#1055 owner report)', () => { + const S = loadScopeFilter(); + assert.strictEqual(S.advertsOnlyShort({ dagi: true }), 'Adverts only'); + assert.strictEqual(S.advertsOnlyShort({ area: true }), 'Adverts only'); + assert.strictEqual(S.advertsOnlyShort({ area: true, dagi: true }), 'Adverts only'); + assert.strictEqual(S.advertsOnlyShort({ dagi: true, loading: true }), 'Loading member nodes…'); + assert.strictEqual(S.advertsOnlyShort({ area: true, areaEmpty: true }), 'Empty area: not filtering'); + assert.strictEqual(S.advertsOnlyShort({ area: true, dagi: true, areaEmpty: true }), 'Adverts only', 'DAGI still filters'); + assert.strictEqual(S.advertsOnlyShort({ loading: true }), ''); + assert.strictEqual(S.advertsOnlyShort({}), ''); + assert.strictEqual(S.advertsOnlyShort(null), ''); +}); + +test('advertsOnlyShort and advertsOnlyNotice agree on when there is a notice', () => { + const S = loadScopeFilter(); + for (const area of [false, true]) for (const dagi of [false, true]) for (const loading of [false, true]) for (const areaEmpty of [false, true]) { + const sel = { area, dagi, loading, areaEmpty }; + assert.strictEqual(!!S.advertsOnlyShort(sel), !!S.advertsOnlyNotice(sel), JSON.stringify(sel)); + } +}); + +test('DagiFilter.hiddenShort: the count for the one-line notice', () => { + const D = loadDagi('#/live').DF; + assert.strictEqual(D.hiddenShort(18), '18 nodes without position'); + assert.strictEqual(D.hiddenShort(1), '1 node without position'); + assert.strictEqual(D.hiddenShort(0), ''); + assert.strictEqual(D.hiddenShort('x'), ''); +}); + test('Live notice: loading while a set is not loaded, the Area text once it is', async () => { let ready = false; const scopes = { areaReady: () => ready, dagiReady: () => true, areaEmpty: () => false }; const t = noticeCtx({ area: 'AARHUS', scopes }); t.ctx.renderLiveScopeNotice(); - assert.match(t.el.textContent, /^Area filter: loading the member nodes/); + assert.match(t.why.textContent, /^Area filter: loading the member nodes/); + assert.strictEqual(t.rule.textContent, 'Loading member nodes…'); ready = true; t.ctx.renderLiveScopeNotice(); - assert.match(t.el.textContent, /^Area filter: only adverts are shown/); + assert.match(t.why.textContent, /^Area filter: only adverts are shown/); + assert.strictEqual(t.rule.textContent, 'Adverts only'); }); test('N2: while a set loads, the chip under the header and the feed placeholder say so; once loaded they go back', async () => { @@ -216,7 +270,8 @@ test('Live notice: an Area with no member says it does not filter the feed (F3)' const scopes = { areaReady: () => true, dagiReady: () => true, areaEmpty: () => true }; const t = noticeCtx({ area: 'EMPTY', scopes }); t.ctx.renderLiveScopeNotice(); - assert.strictEqual(t.el.textContent, 'Area filter: no node with a position lies in the selected area, so it does not filter the feed.'); + assert.strictEqual(t.why.textContent, 'Area filter: no node with a position lies in the selected area, so it does not filter the feed.'); + assert.strictEqual(t.rule.textContent, 'Empty area: not filtering'); }); // ---------- the member sets ---------- diff --git a/test-issue-1055-live-panel-e2e.js b/test-issue-1055-live-panel-e2e.js new file mode 100644 index 000000000..b04db6ec5 --- /dev/null +++ b/test-issue-1055-live-panel-e2e.js @@ -0,0 +1,295 @@ +#!/usr/bin/env node +/** + * E2E (#1055, owner bug report): with a Danish area (DAGI) and an Area + * selected, the Live controls panel ("MESH LIVE") covered the right-hand + * map buttons, and its long notice made it two lines taller. + * + * On its own Go server (tests/e2e-1055-live-server.js: the M2 seed, one + * test area AARHUS), at 1920x870, 1280x800, 768x1024 and 375x560, light and + * dark, with the controls open, for "Kommune: Aarhus" and for Aarhus plus + * Area AARHUS: + * 1. The panel's box meets no map button (every Leaflet control, the VCR + * bar's buttons, the feed's show button) and neither the VCR bar nor the + * map credit; each button is the element at its own centre. Again with + * the notice's explanation open. + * 2. The notice is one line (no wrap, nothing cut off) that names the rule + * and, for DAGI, the count of nodes with no position; the explanation + * (the Packets wording, ScopeMemberFilter.advertsOnlyNotice plus + * DagiFilter.hiddenNotice) is its title and opens and closes under a + * "why?" button. + * 3. A DAGI selection grows the controls body by at most one row (the + * taller of the notice line and the DAGI trigger, plus the row gap; + * where Area's label pushes the DAGI trigger onto a row of its own, + * that row plus one notice line), + * measured against the same page without it (no selection, or Area + * only for Area plus DAGI), and the open or + * closed controls are remembered across a reload. + * + * Usage: + * (cd cmd/server && go build -o ../../corescope-server .) + * (cd cmd/migrate && go build -o ../../corescope-migrate .) + * CORESCOPE_SERVER_BIN=./corescope-server CORESCOPE_MIGRATE_BIN=./corescope-migrate \ + * node test-issue-1055-live-panel-e2e.js + * Optional: E2E_PORT_BASE (default 13900), E2E_FIXTURE_DB, SCREENSHOT_DIR + * (writes one screenshot per size, theme and selection), E2E_PANEL_SIZES + * and E2E_PANEL_THEMES (a subset, comma-separated, e.g. 1280x800 and light). + */ +'use strict'; + +const assert = require('assert/strict'); +const fs = require('fs'); +const os = require('os'); +const path = require('path'); +const { chromium } = require('playwright'); +const { startServer, stop } = require('./tests/e2e-1055-live-server'); + +const SHOTS = process.env.SCREENSHOT_DIR || ''; +const AREA = { label: 'Aarhus test area', latMin: 56.0, latMax: 56.3, lonMin: 10.0, lonMax: 10.4 }; +// E2E_PANEL_SIZES ("1280x800,375x560") and E2E_PANEL_THEMES ("light") run a +// subset, for a quick local check; CI runs them all. +const pick = (env, all) => process.env[env] ? all.filter(v => process.env[env].split(',').includes(String(v).replace(',', 'x'))) : all; +const SIZES = pick('E2E_PANEL_SIZES', [[1920, 870], [1280, 800], [768, 1024], [375, 560]]); +const THEMES = pick('E2E_PANEL_THEMES', ['light', 'dark']); +const WHY_DAGI = 'Danish-area filter: only adverts are shown, because other packets do not name their sender.'; +const WHY_BOTH = 'Area and Danish-area filters: only adverts are shown, because other packets do not name their sender.'; + +let passed = 0, failed = 0; +async function step(name, fn) { + try { await fn(); passed++; console.log(' ✓ ' + name); } + catch (e) { failed++; console.error(' ✗ ' + name + ': ' + (e && e.stack || e)); } +} + +async function liveReady(page) { + await page.waitForFunction(() => window._liveWSHandler && window._liveWSHandler() && + window._liveMemberScopesReady && window._liveMemberScopesReady(), null, { timeout: 20000 }); + await page.waitForSelector('#liveControlsToggle', { state: 'attached', timeout: 20000 }); +} + +async function openControls(page) { + const open = await page.evaluate(() => document.getElementById('liveControlsToggle').getAttribute('aria-expanded') === 'true'); + if (!open) await page.click('#liveControlsToggle'); + await page.waitForSelector('#liveAreaFilter .region-dropdown-trigger', { state: 'visible' }); +} + +// Waits for the notice with the hidden-node count, then two frames for the +// layout (the rail and cap trackers run in animation frames). +async function noticeSettled(page, count = true) { + await page.waitForFunction((count) => { + const n = document.getElementById('liveScopeNotice'); + return n && !n.hidden && (!count || /position/.test(n.textContent)); + }, count, { timeout: 10000 }); + await frames(page); +} + +// The panel, the map buttons, the bottom bars, and whether each button is +// the element at its own centre. +function layout() { + const box = (el) => { const r = el.getBoundingClientRect(); return { x: r.left, y: r.top, w: r.width, h: r.height }; }; + const shown = (el) => el.checkVisibility({ visibilityProperty: true }) && el.getBoundingClientRect().width > 0; + const name = (el) => el.id ? '#' + el.id : el.className && typeof el.className === 'string' ? '.' + el.className.trim().split(/\s+/).join('.') : el.tagName; + const buttons = [].slice.call(document.querySelectorAll( + '#liveMap .leaflet-control-container .leaflet-control a, #liveMap .leaflet-control-container .leaflet-control button,' + + ' #vcrBar button, #feedShowBtn')) + .filter(el => !el.closest('.leaflet-control-attribution') && shown(el)) + .map(el => { + const b = box(el); + const hit = document.elementFromPoint(b.x + b.w / 2, b.y + b.h / 2); + return { name: name(el), box: b, hit: !!hit && el.contains(hit), at: hit ? name(hit) : null }; + }); + const bars = ['#vcrBar', '#liveMap .leaflet-control-attribution', '#liveLegend:not(.hidden)'] + .map(s => document.querySelector(s)).filter(el => el && shown(el)).map(el => ({ name: name(el), box: box(el) })); + return { panel: box(document.getElementById('liveHeader')), buttons, bars }; +} + +function overlaps(a, b) { + const x = Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x); + const y = Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y); + return x > 0.5 && y > 0.5; +} + +const frames = (page) => page.evaluate(() => new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)))); + +async function assertClear(page, where) { + await frames(page); // the rail and panel-bottom trackers run in a frame + const l = await page.evaluate(layout); + assert(l.buttons.length >= 8, where + ': only ' + l.buttons.length + ' map buttons found'); + for (const b of l.buttons) { + assert(!overlaps(l.panel, b.box), where + ': the panel ' + JSON.stringify(l.panel) + ' covers ' + b.name + ' ' + JSON.stringify(b.box)); + assert(b.hit, where + ': ' + b.name + ' is not clickable; ' + b.at + ' is at its centre'); + } + for (const b of l.bars) { + assert(!overlaps(l.panel, b.box), where + ': the panel ' + JSON.stringify(l.panel) + ' covers ' + b.name + ' ' + JSON.stringify(b.box)); + } +} + +// The notice's one line: its text rects share one top, and nothing is cut. +const noticeLine = (page) => page.evaluate(() => { + const line = document.querySelector('#liveScopeNotice .live-scope-notice-line'); + if (!line) return null; + const range = document.createRange(); + range.selectNodeContents(line); + const tops = new Set([].slice.call(range.getClientRects()).filter(r => r.width > 0).map(r => Math.round(r.top + r.height / 2))); + const cut = [].slice.call(line.querySelectorAll('*')).concat([line]).some(el => el.scrollWidth > el.clientWidth + 1); + const part = (id) => document.getElementById(id).textContent; + return { text: line.textContent, rule: part('liveScopeRule'), count: part('liveScopeCount'), title: line.title, rows: tops.size, cut, height: line.getBoundingClientRect().height }; +}); + +const bodyHeight = (page) => page.evaluate(() => document.getElementById('liveControlsBody').scrollHeight); + +async function shot(page, name) { + if (!SHOTS) return; + fs.mkdirSync(SHOTS, { recursive: true }); + await page.screenshot({ path: path.join(SHOTS, 'live-panel-' + name + '.png') }); +} + +async function main() { + const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'e2e-1055-panel-')); + const browser = await chromium.launch({ + executablePath: process.env.CHROMIUM_PATH || undefined, + args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'], + }); + let server = null; + const numbers = []; + try { + server = await startServer(path.join(scratch, 'srv'), { AARHUS: AREA }); + const BASE = server.base; + console.log('\n#1055 — the Live panel and the map buttons (' + BASE + ')\n'); + + for (const [width, height] of SIZES) { + for (const theme of THEMES) { + const size = width + 'x' + height + '-' + theme; + const ctx = await browser.newContext({ viewport: { width, height }, colorScheme: theme }); + await ctx.addInitScript(t => { + if (sessionStorage.getItem('e2e-seeded')) return; + sessionStorage.setItem('e2e-seeded', '1'); + localStorage.setItem('meshcore-theme', t); + localStorage.setItem('live-controls-expanded', 'true'); + }, theme); + const page = await ctx.newPage(); + const errors = []; + page.on('pageerror', e => errors.push(String(e))); + + // The baselines: the same page with no selection, and with Area only + // (Area's own trigger grows with its label; that is not DAGI's row). + const base = { dagi: 0, 'dagi+area': 0 }; + await step(size + ': no selection, the open panel clears every map button', async () => { + await page.goto(BASE + '/#/live'); + await liveReady(page); + await openControls(page); + await frames(page); + base.dagi = await bodyHeight(page); + await assertClear(page, size + ' no selection'); + }); + await step(size + ': Area only, the open panel clears every map button', async () => { + await page.evaluate(() => localStorage.setItem('meshcore-area-filter', 'AARHUS')); + await page.reload(); + await liveReady(page); + await openControls(page); + await noticeSettled(page, false); + base['dagi+area'] = await bodyHeight(page); + await assertClear(page, size + ' Area only'); + }); + + for (const sel of ['dagi', 'dagi+area']) { + const where = size + ' ' + sel; + await step(where + ': the panel clears every map button and bar; each button is clickable', async () => { + await page.evaluate(a => { if (a) localStorage.setItem('meshcore-area-filter', 'AARHUS'); else localStorage.removeItem('meshcore-area-filter'); }, sel === 'dagi+area'); + await page.goto(BASE + '/#/live?kommune=0751'); + await page.reload(); + await liveReady(page); + await openControls(page); + await noticeSettled(page); + await shot(page, width + 'x' + height + '-' + theme + '-' + sel.replace('+', '-')); + await assertClear(page, where); + }); + + await step(where + ': the notice is one line with the rule and the count; the explanation is its title', async () => { + const l = await noticeLine(page); + assert(l, 'no notice line'); + assert.equal(l.rows, 1, 'the notice runs over ' + l.rows + ' lines: ' + l.text); + assert(!l.cut, 'the notice is cut off: ' + l.text); + assert.equal(l.rule, 'Adverts only'); + assert.match(l.count, /^\d+ nodes? without position$/); + const why = sel === 'dagi' ? WHY_DAGI : WHY_BOTH; + assert(l.title.startsWith(why + ' '), 'title: ' + l.title); + assert(/no position, so no Danish-area filter can include/.test(l.title), 'title: ' + l.title); + }); + + await step(where + ': the "why?" button opens and closes the explanation, and the panel still clears the buttons', async () => { + const btn = page.locator('#liveScopeWhyBtn'); + assert.equal(await btn.getAttribute('aria-expanded'), 'false'); + assert.equal(await page.locator('#liveScopeWhy').isVisible(), false, 'the explanation shows before "why?"'); + await btn.click(); + assert.equal(await btn.getAttribute('aria-expanded'), 'true'); + await page.locator('#liveScopeWhy').waitFor({ state: 'visible' }); + const text = await page.locator('#liveScopeWhy').textContent(); + assert.equal(text, (await noticeLine(page)).title); + await assertClear(page, where + ' (explanation open)'); + await btn.click(); + assert.equal(await btn.getAttribute('aria-expanded'), 'false'); + await page.locator('#liveScopeWhy').waitFor({ state: 'hidden' }); + }); + + await step(where + ': the controls grow by at most one row', async () => { + const withSel = await bodyHeight(page); + // One row: the taller of the notice line and the DAGI trigger, + // plus the body's row gap. + // When Area's own label leaves no room beside it (375 px), the + // DAGI trigger takes a row of its own as well; only then does that + // row count, and the notice may still add one line, no more. + const m = await page.evaluate(() => { + const box = (s) => { const el = document.querySelector(s); return el ? el.getBoundingClientRect() : null; }; + const gap = parseFloat(getComputedStyle(document.getElementById('liveControlsBody')).rowGap) || 0; + const line = box('#liveScopeNotice .live-scope-notice-line'); + const trigger = box('#liveDagiFilter .dagi-trigger'); + const area = box('#liveAreaFilter .region-dropdown-trigger'); + return { + row: Math.max(line ? line.height : 16, trigger ? trigger.height : 0) + gap, + line: (line ? line.height : 16) + gap, + ownRow: !!(trigger && area && trigger.top >= area.bottom), + }; + }); + const bound = m.row + (m.ownRow ? m.line : 0); + const plain = base[sel]; + numbers.push(where + ': body ' + plain + ' -> ' + withSel + ' px (+' + (withSel - plain) + ', bound ' + Math.ceil(bound) + + (m.ownRow ? ': the DAGI trigger\'s own row plus one notice line' : ': one row') + ')'); + assert(withSel - plain <= bound + 1, 'grew ' + (withSel - plain) + ' px; the bound is ' + bound + ' px'); + }); + } + + await step(size + ': no page error', async () => { + assert.deepEqual(errors, []); + }); + await ctx.close(); + } + } + + await step('the open or closed controls are remembered across a reload', async () => { + const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 } }); + const page = await ctx.newPage(); + await page.goto(BASE + '/#/live?kommune=0751'); + await liveReady(page); + const expanded = () => page.evaluate(() => document.getElementById('liveControlsToggle').getAttribute('aria-expanded')); + assert.equal(await expanded(), 'false', 'a first visit opens the controls'); + await page.click('#liveControlsToggle'); + assert.equal(await expanded(), 'true'); + await page.reload(); + await liveReady(page); + assert.equal(await expanded(), 'true', 'the open controls were not remembered'); + await page.click('#liveControlsToggle'); + await page.reload(); + await liveReady(page); + assert.equal(await expanded(), 'false', 'the closed controls were not remembered'); + await ctx.close(); + }); + } finally { + await browser.close(); + await stop(server); + fs.rmSync(scratch, { recursive: true, force: true }); + } + console.log('\n ' + numbers.join('\n ')); + console.log('\n' + passed + ' passed, ' + failed + ' failed'); + process.exit(failed ? 1 : 0); +} + +main().catch(e => { console.error(e); process.exit(1); }); diff --git a/tests/e2e-1055-live-server.js b/tests/e2e-1055-live-server.js new file mode 100644 index 000000000..a83a1ca89 --- /dev/null +++ b/tests/e2e-1055-live-server.js @@ -0,0 +1,79 @@ +'use strict'; +/** + * A Go server for the #1055 Live E2E suites, on a migrated copy of + * test-fixtures/e2e-fixture.db (or E2E_FIXTURE_DB, a copy already prepared + * as in CI) seeded with test-fixtures/seed-1055-live-dagi-nodes.sql (two + * nodes in Aarhus kommune 0751, one in København, one in Odense) and the + * given test areas. Needs CORESCOPE_SERVER_BIN and CORESCOPE_MIGRATE_BIN. + * Ports from E2E_PORT_BASE (default 13900). Nothing leaves the machine. + */ +const assert = require('assert/strict'); +const fs = require('fs'); +const path = require('path'); +const net = require('net'); +const { spawn, execFileSync } = require('child_process'); + +const ROOT = path.join(__dirname, '..'); +const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + +function requiredFile(variable) { + assert(process.env[variable], variable + ' is required; see the test header'); + const file = path.resolve(process.env[variable]); + assert(fs.statSync(file).isFile(), file + ' must be a file'); + return file; +} + +async function freePort() { + const base = Number(process.env.E2E_PORT_BASE || 13900); + for (let port = base; port < base + 200; port++) { + const ok = await new Promise(resolve => { + const s = net.createServer(); + s.once('error', () => resolve(false)); + s.listen(port, '127.0.0.1', () => s.close(() => resolve(true))); + }); + if (ok) return port; + } + throw new Error('no free port from ' + base); +} + +async function stop(server) { + const child = server && server.child; + if (!child || child.exitCode !== null || child.signalCode !== null) return; + const ended = new Promise(resolve => child.once('exit', resolve)); + child.kill('SIGTERM'); + const timer = setTimeout(() => child.kill('SIGKILL'), 5000); + await ended; + clearTimeout(timer); +} + +/** Starts the server in `dir` with `areas` as config.areas: + * { child, base, log() }. */ +async function startServer(dir, areas) { + const serverBin = requiredFile('CORESCOPE_SERVER_BIN'); + fs.mkdirSync(dir, { recursive: true }); + const db = path.join(dir, 'fixture.db'); + fs.copyFileSync(process.env.E2E_FIXTURE_DB || path.join(ROOT, 'test-fixtures/e2e-fixture.db'), db); + execFileSync(requiredFile('CORESCOPE_MIGRATE_BIN'), ['-db', db], { stdio: 'pipe' }); + execFileSync('sqlite3', ['-cmd', '.timeout 5000', db], + { input: fs.readFileSync(path.join(ROOT, 'test-fixtures/seed-1055-live-dagi-nodes.sql')), stdio: ['pipe', 'pipe', 'pipe'] }); + fs.writeFileSync(path.join(dir, 'config.json'), JSON.stringify({ mqtt: { brokers: [] }, areas: areas || {} })); + const port = await freePort(); + const base = 'http://127.0.0.1:' + port; + let log = ''; + const child = spawn(serverBin, ['-config-dir', dir, '-db', db, '-public', path.join(ROOT, 'public'), '-port', String(port)], + { cwd: dir, stdio: ['ignore', 'pipe', 'pipe'] }); + child.stdout.on('data', c => { log = (log + c).slice(-60000); }); + child.stderr.on('data', c => { log = (log + c).slice(-60000); }); + for (let n = 0; n < 300; n++) { + assert(child.exitCode === null && child.signalCode === null, 'server exited: ' + log); + try { + const r = await fetch(base + '/api/config/client', { signal: AbortSignal.timeout(2000) }); + if (r.ok) return { child, base, log: () => log }; + } catch (_) { /* not up yet */ } + await delay(100); + } + await stop({ child }); + throw new Error('server startup timed out: ' + log); +} + +module.exports = { startServer, stop }; From 06dd54c309c9809dc3f0c127f19d2069e95601b7 Mon Sep 17 00:00:00 2001 From: dborup Date: Wed, 2 Dec 2026 12:56:55 +0000 Subject: [PATCH 2/5] fix(live): the controls panel never covers the map buttons, shorter area notice (#1055) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The panel stops short of the right-hand map button column at the column's measured width (--live-map-rail, from live.js), at every width where they share a band; the hard-coded 68/312/250px rails are gone. The 6px gap #664 kept is unchanged. - A legend in a bottom corner stops under the panel (--live-panel-bottom) instead of growing beneath it and hiding its right end. - The Area/DAGI notice is one line ("Adverts only · 18 nodes without position") at the start of the scope row, so a selection adds no row of its own. The Packets wording (advertsOnlyNotice + hiddenNotice) is the line's title and opens under "why?". The short strings are shared helpers: ScopeMemberFilter.advertsOnlyShort, DagiFilter.hiddenShort. - The M2 E2E reads the full text from the explanation; #664 and #875 pin the measured rail instead of the old constants. Co-Authored-By: Claude Opus 5.5 --- public/dagi-filter.js | 9 +++ public/live.css | 91 +++++++++++++++++++------ public/live.js | 91 +++++++++++++++++++++++-- public/scope-member-filter.js | 16 +++++ test-issue-1055-m2-live-dagi-e2e.js | 16 +++-- test-issue-664-live-gear-mobile-e2e.js | 17 ++++- test-issue-875-legend-toggle-control.js | 6 +- 7 files changed, 210 insertions(+), 36 deletions(-) diff --git a/public/dagi-filter.js b/public/dagi-filter.js index e593d57e9..7cb705fb4 100644 --- a/public/dagi-filter.js +++ b/public/dagi-filter.js @@ -174,6 +174,14 @@ '. The count covers all nodes, before the other filters.'; } + /** hiddenNotice's count in a few words, for a one-line notice (Live, + * #1055 owner report). '' for none. */ + function hiddenShort(n) { + n = Number(n) || 0; + if (n <= 0) return ''; + return (n === 1 ? '1 node' : n + ' nodes') + ' without position'; + } + /** GET /api/config/dagi/polygons as Leaflet rings: every feature's * rings, each [lon0, lat0, dlon, dlat, …] in quantum degrees with the * closing vertex implicit, summed and swapped to [lat, lon]. The rings @@ -990,6 +998,7 @@ selectedEntry: selectedEntry, creditElement: creditElement, hiddenNotice: hiddenNotice, + hiddenShort: hiddenShort, hiddenCount: hiddenCount, notAppliedNotice: notAppliedNotice, search: search, diff --git a/public/live.css b/public/live.css index c491dcac9..065f3a009 100644 --- a/public/live.css +++ b/public/live.css @@ -568,8 +568,7 @@ transform: translate(-50%, -50%); } /* #1055 M2: the Danish areas (DAGI) filter beside Area, at the same 30 px - row height with the same 48 px hit area, so the row does not grow; and the - feed's "only adverts are shown" notice on a line of its own. */ + row height with the same 48 px hit area, so the row does not grow. */ .live-controls-body .live-dagi-filter-container { font-size: 11px; } .live-controls-body .live-dagi-filter-container .dagi-trigger { font-size: inherit; @@ -590,7 +589,53 @@ } /* The clear's hit area stays inside the 4 px gap, off the trigger's. */ .live-controls-body .live-dagi-filter-container .dagi-clear::after { width: calc(100% + 8px); } -.live-controls-body .live-scope-notice { flex: 0 0 100%; padding: 0; font-size: 11px; } +/* #1055 owner report: the notice is one line at the start of the scope row + (the rule, and the count for DAGI), not a paragraph on a row of its own; + the explanation (the line's title) opens under "why?" on its own line. */ +.live-controls-body .live-scope-notice { + flex: 0 1 auto; + min-width: 0; + max-width: 100%; + display: flex; + flex-wrap: wrap; + align-items: center; + column-gap: 6px; + padding: 0; + font-size: 11px; +} +.live-controls-body .live-scope-notice[hidden], +.live-scope-notice-why[hidden] { display: none; } +.live-controls-body .live-scope-notice:has(.live-scope-notice-why:not([hidden])) { flex-basis: 100%; } +.live-scope-notice-line { + flex: 0 1 auto; + min-width: 0; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.live-scope-notice-count:not(:empty)::before { content: " \00b7 "; } +.live-scope-notice-why-btn { + flex: none; + position: relative; + padding: 0; + border: 0; + background: none; + color: var(--accent); + font: inherit; + text-decoration: underline; + cursor: pointer; +} +/* A 24px hit area inside the row, on a text-sized link. */ +.live-scope-notice-why-btn::after { + content: ""; + position: absolute; + top: 50%; + left: 50%; + width: max(100%, 24px); + height: 24px; + transform: translate(-50%, -50%); +} +.live-scope-notice-why { flex: 0 0 100%; white-space: normal; } /* #1108 — "Show all nodes" sibling of the region dropdown. Reuses the .live-controls-body label rhythm so it lines up with the other inline toggles. */ @@ -1005,6 +1050,15 @@ body.kiosk .live-node-detail:not(.hidden) ~ .live-kiosk-exit { display: none; } +/* #1055 owner report: the panel stops short of the map's right-hand button + column (zoom, layers, Fullscreen, Settings, Legend), which sits in the + same band above 640px. live.js publishes the column's measured width plus + a 6px gap as --live-map-rail (12px until it is measured). Fullscreen + keeps .live-header's own width: the controls are hidden there (#1572). */ +@media (min-width: 641px) { + body:not(.live-fullscreen) .live-header { max-width: calc(100vw - 12px - var(--live-map-rail, 12px)); } +} + /* ---- Medium breakpoint (#279) + collapse toggles (#1178, #1179) ---- */ @media (max-width: 768px) { .live-feed { width: 280px; max-height: 200px; } @@ -1058,13 +1112,13 @@ body.kiosk .live-node-detail:not(.hidden) ~ .live-kiosk-exit { display: none; } /* #664 — the gear (#liveControlsToggle) lives in the Leaflet top-right stack, outside #liveHeader. With region groups the expanded panel grew down over the gear and swallowed every tap, so it could not be closed. - While expanded, keep the panel out of the control rail (10px Leaflet - margin + 52px control + 6px gap) so no panel height can cover it. + While expanded, keep the panel out of the control rail (its measured + width, #1055: --live-map-rail) so no panel height can cover it; at + ≤ 640px the collapsed header sits above the rail and keeps its width. Not a max-height + scroll: overflow would clip the absolutely positioned region/area dropdown menus. */ body:not(.live-fullscreen) .live-header:has(.live-controls.is-expanded) { - --live-ctrl-rail: 68px; - max-width: calc(100vw - 12px - var(--live-ctrl-rail)); + max-width: calc(100vw - 12px - var(--live-map-rail, 68px)); } } @@ -1420,19 +1474,17 @@ body.live-fullscreen #liveFullscreenToggle:hover, gear ends under the VCR bar or below the .live-page clip. Lay the stack out as one row instead (y 74–174, gear still in the corner). The legend toggle is the last control of that row (#875), so nothing overlaps it. Short desktop windows (≤ 500px tall) get the row too. - The header stops short of the row (5 × 10px Leaflet margin + 52 + 48 + - 52 + 52 + 52px controls + 6px gap: zoom, layers, Fullscreen, Settings, - Legend) while expanded, so it cannot cover the controls either. At - ≤ 640px wide the legend control is hidden (#875), so the row is four - controls (250px) again. */ + The header stops short of the row while expanded, so it cannot cover the + controls either: --live-map-rail is the row's measured width (#1055), + four controls at ≤ 640px wide where the legend control is hidden (#875), + five above. */ @media (orientation: landscape) and (max-height: 500px) { .live-page .leaflet-top.leaflet-right { display: flex; align-items: flex-start; } body:not(.live-fullscreen) .live-header:has(.live-controls.is-expanded) { - --live-ctrl-rail: 312px; - max-width: calc(100vw - 12px - var(--live-ctrl-rail)); + max-width: calc(100vw - 12px - var(--live-map-rail, 312px)); } } /* #875: a narrow window (the bottom navigation takes 58px) 501-620px tall has @@ -1442,11 +1494,6 @@ body.live-fullscreen #liveFullscreenToggle:hover, @media (max-width: 768px) and (min-height: 501px) and (max-height: 620px) { .live-legend, .live-legend-toggle-ctl { display: none !important; } } -@media (orientation: landscape) and (max-height: 500px) and (max-width: 640px) { - body:not(.live-fullscreen) .live-header:has(.live-controls.is-expanded) { - --live-ctrl-rail: 250px; - } -} /* #875: just above the row breakpoint (501–540px) the five-control column is * 418px tall and its last control, Legend, ends under the credit that sits on @@ -1980,6 +2027,12 @@ input.live-node-filter-input:focus { * 10px control margin + ~50px control + gap, the same rail .live-header uses. */ .live-legend[data-position="tr"], .live-legend[data-position="br"] { right: var(--live-ctrl-rail-legend, 68px); } +/* #1055 owner report: a legend in a bottom corner grew up to the nav band, + * under the open MESH LIVE panel, and hid its right end. It now stops under + * the panel (live.js publishes the panel's bottom as --live-panel-bottom) + * and scrolls the rest, as it does on a short window. */ +.live-legend[data-position="bl"], +.live-legend[data-position="br"] { --live-legend-top: max(64px, var(--live-panel-bottom, 0px)); } /* #875: in short landscape viewports the control stack is a row across the top * right (see #666), not a column, so the right-hand corners keep below it diff --git a/public/live.js b/public/live.js index 9fdfa109e..d7ca4ff39 100644 --- a/public/live.js +++ b/public/live.js @@ -322,23 +322,34 @@ // #1055 M2 (owner decision 1): Area and DAGI filter the Live feed by the // Packets rule (the ADVERT sender is a member), so the feed says so, as // Packets does; with DAGI it adds the count of nodes no area can hold. + // #1055 owner report: the panel shows that in one line (the rule, the + // count); the Packets wording is the line's title and opens under "why?". function renderLiveScopeNotice() { const el = document.getElementById('liveScopeNotice'); if (!el) return; const sel = liveScopeSelection(); const text = ScopeMemberFilter.advertsOnlyNotice(sel); + const rule = ScopeMemberFilter.advertsOnlyShort(sel); const gen = ++liveNoticeGeneration; - const show = function (t) { - if (el.textContent !== t) el.textContent = t; - el.hidden = !t; + const setText = function (id, t) { + const part = document.getElementById(id); + if (part && part.textContent !== t) part.textContent = t; }; - show(text); + const show = function (why, count) { + setText('liveScopeRule', rule); + setText('liveScopeCount', count); + setText('liveScopeWhy', why); + const line = document.getElementById('liveScopeLine'); + if (line && line.title !== why) line.title = why; + el.hidden = !why; + }; + show(text, ''); renderMemberLoading(sel.loading && text ? text : ''); if (!sel.dagi) return; DagiFilter.hiddenCount().then(function (n) { if (gen !== liveNoticeGeneration) return; const hidden = DagiFilter.hiddenNotice(n); - show(hidden ? text + ' ' + hidden : text); + show(hidden ? text + ' ' + hidden : text, DagiFilter.hiddenShort(n)); }); } @@ -362,6 +373,19 @@ } function feedEmptyText() { return memberLoadingText ? FEED_LOADING_TEXT : FEED_EMPTY_TEXT; } + // "why?" opens and closes the notice's explanation (a button, so Enter and + // Space work too); the line's title carries the same text on hover. + function wireLiveScopeWhy() { + const btn = document.getElementById('liveScopeWhyBtn'); + const why = document.getElementById('liveScopeWhy'); + if (!btn || !why) return; + btn.addEventListener('click', function () { + const open = btn.getAttribute('aria-expanded') !== 'true'; + btn.setAttribute('aria-expanded', open ? 'true' : 'false'); + why.hidden = !open; + }); + } + // #1055 M2: one member set per selection (none fetched again for the same // one), made on the first selection, so Live with no filter keeps no set. // A set that failed to load is fetched again by the next call (setScope), @@ -914,6 +938,50 @@ }; } + // #1055 owner report: the MESH LIVE panel stops short of the map's + // right-hand button column (zoom, layers, Fullscreen, Settings, Legend; a + // row in short landscape, #666). Its width is measured here, from the + // page's right edge to the leftmost shown control, plus the 6px gap the + // panel kept from the column since #664, and published as --live-map-rail + // on the page (live.css), so the reserve follows whatever controls are + // shown. An open layers list is a + // menu over the map, not the column, and does not count. The panel's + // bottom edge is published too (--live-panel-bottom), so a legend in a + // bottom corner stops under the panel instead of growing beneath it. + var PANEL_RAIL_GAP = 6; + var _panelReserveCleanup = null; + function initPanelReserveTracker() { + if (_panelReserveCleanup) { try { _panelReserveCleanup(); } catch (_) {} _panelReserveCleanup = null; } + var page = document.querySelector('.live-page'); + var rail = page && page.querySelector('#liveMap .leaflet-top.leaflet-right'); + var header = document.getElementById('liveHeader'); + if (!rail || !header) return; + var raf = 0; + function measure() { + raf = 0; + var box = page.getBoundingClientRect(); + var reserve = 0; + for (var c = rail.firstElementChild; c; c = c.nextElementSibling) { + if (!c.getClientRects().length || c.classList.contains('leaflet-control-layers-expanded')) continue; + reserve = Math.max(reserve, box.right - c.getBoundingClientRect().left + PANEL_RAIL_GAP); + } + page.style.setProperty('--live-map-rail', Math.ceil(reserve) + 'px'); + page.style.setProperty('--live-panel-bottom', Math.ceil(header.getBoundingClientRect().bottom - box.top) + 'px'); + } + function schedule() { if (!raf) raf = requestAnimationFrame(measure); } + var ro = null; + if (typeof ResizeObserver === 'function') { + try { ro = new ResizeObserver(schedule); ro.observe(rail); ro.observe(header); } catch (_) { ro = null; } + } + window.addEventListener('resize', schedule); + measure(); + _panelReserveCleanup = function() { + if (raf) cancelAnimationFrame(raf); + if (ro) { try { ro.disconnect(); } catch (_) {} ro = null; } + window.removeEventListener('resize', schedule); + }; + } + var _controlsFitCleanup = null; function initControlsFitTracker() { if (_controlsFitCleanup) { try { _controlsFitCleanup(); } catch (_) {} _controlsFitCleanup = null; } @@ -1740,6 +1808,7 @@ */ function wireLiveControls() { resolveScopeParams(); + wireLiveScopeWhy(); const TOGGLES = [ { id: 'liveHeatToggle', restore: () => heatEnabled, onChange: (v) => { heatEnabled = v; @@ -2195,11 +2264,19 @@
-
+ + Color packet routes by their scope (region). Takes precedence over Color by hash; foreign-origin red still wins @@ -2603,6 +2680,7 @@ } }); map.addControl(new LiveLegendControl()); + initPanelReserveTracker(); // #1055: the panel stops short of these controls @@ -6809,6 +6887,7 @@ } if (_vcrHeightCleanup) { try { _vcrHeightCleanup(); } catch (_) {} _vcrHeightCleanup = null; } if (_controlsFitCleanup) { try { _controlsFitCleanup(); } catch (_) {} _controlsFitCleanup = null; } + if (_panelReserveCleanup) { try { _panelReserveCleanup(); } catch (_) {} _panelReserveCleanup = null; } if (_legendScrollCleanup) { try { _legendScrollCleanup(); } catch (_) {} _legendScrollCleanup = null; } // Restore #app height to CSS default const appEl = document.getElementById('app'); diff --git a/public/scope-member-filter.js b/public/scope-member-filter.js index 6b061ca10..ec3f5cef4 100644 --- a/public/scope-member-filter.js +++ b/public/scope-member-filter.js @@ -63,6 +63,9 @@ * areaEmpty the Area has no member, so it filters nothing: the line names * only the filters that still filter. * + * advertsOnlyShort(sel) is that line in a few words ("Adverts only"), for + * Live's one-line notice (#1055 owner report); '' where the line is ''. + * * packetSender(p, parseRow) is the shared sender key for both packet shapes: * a Live-shaped packet (a WS message or a replay packet) carries a parsed * decoded.payload; a row-shaped one (/api/packets, the Packets WS rows) only @@ -151,6 +154,18 @@ return filterName(area, dagi) + ': only adverts are shown, because other packets do not name their sender.'; } + // #1055 owner report: advertsOnlyNotice's state in a few words, for a + // page that shows one line and the full text on request. The trigger + // beside it names the filter; '' where advertsOnlyNotice is ''. + function advertsOnlyShort(sel) { + var area = !!(sel && sel.area); + var dagi = !!(sel && sel.dagi); + if (!area && !dagi) return ''; + if (sel.loading) return 'Loading member nodes\u2026'; + if (area && sel.areaEmpty && !dagi) return 'Empty area: not filtering'; + return 'Adverts only'; + } + function createScopes(opts) { var fetchAllNodes = opts.fetchAllNodes; var keyOf = opts.keyOf; @@ -206,5 +221,6 @@ advertSender: advertSender, packetSender: packetSender, advertsOnlyNotice: advertsOnlyNotice, + advertsOnlyShort: advertsOnlyShort, }; })(); diff --git a/test-issue-1055-m2-live-dagi-e2e.js b/test-issue-1055-m2-live-dagi-e2e.js index 5987d0c3b..0bbea44fa 100644 --- a/test-issue-1055-m2-live-dagi-e2e.js +++ b/test-issue-1055-m2-live-dagi-e2e.js @@ -198,7 +198,9 @@ async function liveReady(page) { window._liveMemberScopesReady && window._liveMemberScopesReady(), null, { timeout: 20000 }); } const hashParams = (page) => page.evaluate(() => Object.fromEntries(new URLSearchParams(location.hash.split('?')[1] || ''))); -const notice = (page) => page.evaluate(() => { const e = document.getElementById('liveScopeNotice'); return e.hidden ? '' : e.textContent; }); +// The notice's full text: since the #1055 owner report it is the +// explanation under the one-line notice ("why?"), word for word as before. +const notice = (page) => page.evaluate(() => { const e = document.getElementById('liveScopeNotice'); return e.hidden ? '' : document.getElementById('liveScopeWhy').textContent; }); const outlines = (page) => page.evaluate(() => { const out = { dagi: 0, area: 0 }; window._liveGetMap().eachLayer(l => { @@ -313,7 +315,7 @@ async function main() { assert.equal(req.members[0].get('kommune'), '0751'); await page.waitForFunction(() => { let n = 0; window._liveGetMap().eachLayer(l => { if (l.options && l.options.className === 'dagi-outline') n++; }); return n === 1; }, null, { timeout: 8000 }); assert(await page.evaluate(() => !window._liveGetMap().getBounds().contains([56.1572, 10.2107])), 'a cold link moved the map'); - await page.waitForFunction(t => document.getElementById('liveScopeNotice').textContent.startsWith(t), NOTICE_DAGI); + await page.waitForFunction(t => document.getElementById('liveScopeWhy').textContent.startsWith(t), NOTICE_DAGI); assert.equal(await page.evaluate(() => document.getElementById('liveScopeNotice').hidden), false); }); @@ -416,14 +418,14 @@ async function main() { await step('Area AND DAGI: nobody in both passes; the Area outline keeps the slot; clearing Area hands it to DAGI', async () => { await pickDagi(page, 'køb', 'København'); await liveReady(page); - await page.waitForFunction(t => document.getElementById('liveScopeNotice').textContent.startsWith(t), NOTICE_BOTH); + await page.waitForFunction(t => document.getElementById('liveScopeWhy').textContent.startsWith(t), NOTICE_BOTH); await expectNone(page, [advert(A1, 56.1572, 10.2107), advert(B1, 55.6761, 12.5683), grpTxt()]); assert.deepEqual(await outlines(page), { dagi: 0, area: 1 }); await page.click('#liveAreaFilter .region-dropdown-trigger'); await page.click('#liveAreaFilter [data-area="__all__"]'); await page.waitForFunction(() => { let d = 0, a = 0; window._liveGetMap().eachLayer(l => { if (!l.options) return; if (l.options.className === 'dagi-outline') d++; else if (l.options.dashArray === '2 4') a++; }); return d === 1 && a === 0; }); await expectFeed(page, [advert(A1, 56.1572, 10.2107)], advert(B1, 55.6761, 12.5683)); - await page.waitForFunction(t => document.getElementById('liveScopeNotice').textContent.startsWith(t), NOTICE_DAGI); + await page.waitForFunction(t => document.getElementById('liveScopeWhy').textContent.startsWith(t), NOTICE_DAGI); await page.click('#liveDagiFilter .dagi-clear'); }); @@ -513,7 +515,7 @@ async function main() { await p.goto(BASE + '/#/live?kommune=0751'); await p.waitForFunction(() => window._liveWSHandler && window._liveWSHandler()); // startsWith: the DAGI hidden-node count may follow the text. - await p.waitForFunction(t => document.getElementById('liveScopeNotice').textContent.startsWith(t), NOTICE_DAGI_LOADING, { timeout: 8000 }); + await p.waitForFunction(t => document.getElementById('liveScopeWhy').textContent.startsWith(t), NOTICE_DAGI_LOADING, { timeout: 8000 }); assert.equal(await p.evaluate(() => window._liveMemberScopesReady()), false); // Review N2: the panel is closed, so its notice is not seen; the chip // under the header bar and the feed's placeholder say it instead. @@ -561,7 +563,7 @@ async function main() { assert.equal(at.length, 3, 'no backoff retry of the failed member request'); release(); await p.waitForFunction(() => window._liveMemberScopesReady(), null, { timeout: 10000 }); - await p.waitForFunction(t => document.getElementById('liveScopeNotice').textContent.startsWith(t), NOTICE_DAGI, { timeout: 8000 }); + await p.waitForFunction(t => document.getElementById('liveScopeWhy').textContent.startsWith(t), NOTICE_DAGI, { timeout: 8000 }); const after = await p.evaluate(() => ({ chip: document.getElementById('liveMemberLoading').checkVisibility(), placeholder: document.querySelector('#liveFeed .live-feed-empty').textContent, @@ -684,7 +686,7 @@ async function main() { await p.click('#liveAreaFilter [data-area="EMPTY"]'); await liveReady(p); assert.equal(r.members.at(-1).get('area'), 'EMPTY'); - await p.waitForFunction(t => document.getElementById('liveScopeNotice').textContent === t, NOTICE_AREA_EMPTY, { timeout: 8000 }); + await p.waitForFunction(t => document.getElementById('liveScopeWhy').textContent === t, NOTICE_AREA_EMPTY, { timeout: 8000 }); await expectFeed(p, [], grpTxt()); await c.close(); }); diff --git a/test-issue-664-live-gear-mobile-e2e.js b/test-issue-664-live-gear-mobile-e2e.js index 7edcd3bcc..af1625a6d 100644 --- a/test-issue-664-live-gear-mobile-e2e.js +++ b/test-issue-664-live-gear-mobile-e2e.js @@ -15,7 +15,8 @@ // - close it with a real tap/click at the same point; the panel is // collapsed and aria-expanded="false" // - open → close twice -// Desktop also asserts the expanded header keeps its pre-#664 geometry. +// Desktop also asserts the expanded header keeps its origin and, since the +// #1055 owner report, stops short of the whole control column. // // Usage: BASE_URL=http://localhost:13581 node test-issue-664-live-gear-mobile-e2e.js 'use strict'; @@ -61,6 +62,11 @@ function gearState(page) { chips: body.querySelectorAll('.region-quick-pick').length, area: !!body.querySelector('#liveAreaFilter .region-dropdown-trigger'), vw: window.innerWidth, + // #1055: the header's reserve is the control column's measured width + // (live.js --live-map-rail), from the leftmost control plus a 6px gap. + rail: parseFloat(getComputedStyle(document.querySelector('.live-page')).getPropertyValue('--live-map-rail')), + railLeft: Math.min(...[...document.querySelectorAll('#liveMap .leaflet-top.leaflet-right > .leaflet-control')] + .filter((c) => c.getClientRects().length).map((c) => c.getBoundingClientRect().left)), maxWidth: getComputedStyle(header).maxWidth, }; }); @@ -110,8 +116,13 @@ async function runViewport(browser, w, h, touch) { assert(s.panel[0] >= 0 && s.panel[2] <= s.vw, `panel ${s.panel} outside viewport ${s.vw}`); }); if (!touch) { - await step(`${tag} round ${round}: desktop header geometry unchanged`, async () => { - assert(s.maxWidth === (s.vw - 24) + 'px', `max-width ${s.maxWidth}, expected ${s.vw - 24}px`); + // #1055 owner report: on desktop the expanded panel stops short of the + // whole control column (it covered the zoom buttons at full width). + await step(`${tag} round ${round}: desktop header keeps its origin and stops short of the control column`, async () => { + const expected = (s.vw - 12 - s.rail) + 'px'; + assert(s.maxWidth === expected, `max-width ${s.maxWidth}, expected ${expected}`); + assert(Math.abs(s.vw - s.railLeft + 6 - s.rail) <= 1, `rail ${s.rail}px, column starts at ${s.railLeft}`); + assert(s.panel[2] <= s.railLeft, `panel ${s.panel} reaches the column at ${s.railLeft}`); assert(s.panel[0] === 12 && s.panel[1] === 64, `panel origin ${s.panel}`); }); } diff --git a/test-issue-875-legend-toggle-control.js b/test-issue-875-legend-toggle-control.js index 9fb7d7b0c..87798bf6c 100644 --- a/test-issue-875-legend-toggle-control.js +++ b/test-issue-875-legend-toggle-control.js @@ -65,7 +65,11 @@ step('legend toggle control hidden on phone and in fullscreen like before', () = step('legend is height-capped with an internal scroll, and the landscape rail fits five controls', () => { assert(/\.live-legend\s*\{[^}]*max-height:\s*max\([^;]*calc\(100%/.test(css), 'no max-height on .live-legend'); - assert(/--live-ctrl-rail:\s*312px/.test(css), 'landscape rail not sized for five controls'); + // #1055: the header's reserve is the row's measured width (live.js), not + // a fixed 312px, so it fits five controls, or four where Legend is hidden. + assert(/@media \(orientation: landscape\) and \(max-height: 500px\) \{[\s\S]*?\.live-header:has\(\.live-controls\.is-expanded\) \{\s*max-width: calc\(100vw - 12px - var\(--live-map-rail/.test(css), + 'landscape header does not stop short of the measured control row'); + assert(/setProperty\('--live-map-rail'/.test(js), 'live.js does not publish --live-map-rail'); }); step('toggle title and aria-expanded follow the state; x hands focus to the toggle', () => { From 5367a3c0e47af03ec5d4d7e5dacda81579dd8e8a Mon Sep 17 00:00:00 2001 From: dborup Date: Wed, 2 Dec 2026 13:16:20 +0000 Subject: [PATCH 3/5] fix(live): keep the space after the notice's separator (#1055) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A CSS hex escape ends at one following space, so " \00b7 " rendered as "Adverts only ·18 nodes"; a second space keeps "· 18 nodes". Co-Authored-By: Claude Opus 5.5 --- public/live.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/live.css b/public/live.css index 065f3a009..07e355791 100644 --- a/public/live.css +++ b/public/live.css @@ -613,7 +613,7 @@ overflow: hidden; text-overflow: ellipsis; } -.live-scope-notice-count:not(:empty)::before { content: " \00b7 "; } +.live-scope-notice-count:not(:empty)::before { content: " \00b7 "; /* the escape takes one space */ } .live-scope-notice-why-btn { flex: none; position: relative; From e52bcca02a42bb30033ec058d7a3f91a00105756 Mon Sep 17 00:00:00 2001 From: dborup Date: Wed, 2 Dec 2026 16:44:24 +0000 Subject: [PATCH 4/5] test(live): reproduce the #1087 review nits on the panel (#1055) - N1: the area rule selector must be hidden by its computed display with no filter (M3 E2E after the clear, the panel E2E with no selection), and the CSS keeps its [hidden] rule (unit). - N2: the panel E2E runs 375x560 and 360x640 with touch; at 640 px and below the selector shares the DAGI control's row with short labels, and a selection with the selector shown grows the controls by at most one row (children's boxes, not scrollHeight, which counts the 48 px hit areas; no own-row allowance any more). The notice line is checked under Touches too, with "why?" on the same line, and the open explanation must not reach the map credit. - N3: roving tabindex and the arrow keys (unit and M3 E2E); the listener check expects the selector's click and keydown. - N5: the M2 phone step waits for the debounced DAGI search to apply before it picks Aarhus (right after fill() the row is still in the unfiltered list, y 4602, and moves to y 216), and tapInPlace waits for its control to hold still for three frames as the element at its centre. No fixed sleeps. - The notice's short texts: "From the area: adverts only", "Touches the area: any type", "N nodes not on map". - The panel suite uses the shared #1055 harness (tests/e2e-1055-live.js); tests/e2e-1055-live-server.js, a copy of it, is removed. Co-Authored-By: Claude Opus 5.5 --- scripts/e2e-shards.json | 2 +- test-1055-live-dagi.js | 14 ++- test-1055-m3-area-rule.js | 70 +++++++++++- test-issue-1055-live-panel-e2e.js | 169 +++++++++++++++++++--------- test-issue-1055-m2-live-dagi-e2e.js | 4 + test-issue-1055-m3-area-rule-e2e.js | 52 ++++++++- tests/e2e-1055-live-server.js | 79 ------------- tests/e2e-1055-live.js | 20 +++- 8 files changed, 263 insertions(+), 147 deletions(-) delete mode 100644 tests/e2e-1055-live-server.js diff --git a/scripts/e2e-shards.json b/scripts/e2e-shards.json index c7904d899..d64999782 100644 --- a/scripts/e2e-shards.json +++ b/scripts/e2e-shards.json @@ -362,7 +362,7 @@ {"file":"test-issue-740-m3b-boundary-layer-e2e.js","shard":1,"env":{"BASE_URL":"$BASE_URL"},"output":"e2e","meanSeconds":20,"measurementNote":"New suite; #740 M3b follow-up, one selected-boundary layer on the Map against the real server (only the two Area endpoints are fulfilled, with one Area near Aarhus): at 1440x900 in light and dark, an Area and a DAGI code both set draw only the Area outline and fetch no polygon, Area All brings the DAGI outline, the one Selected area outline checkbox and storage key hide and show it with no new request, both outlines are in --geo-filter-color and markup in the DAGI credit is shown as text; at 1440x600 the beside popover follows its trigger when the Map Controls panel scrolls; a reload draws the outline from the browser cache or a 304. About 20 s locally; no CI duration measured yet. Assigned to shard 1, the lightest by the sum of meanSeconds."}, {"file":"test-issue-740-m3c-dagi-analytics-e2e.js","shard":1,"env":{"BASE_URL":"$BASE_URL"},"output":"e2e","meanSeconds":30,"measurementNote":"New suite; #740 M3c the existing Analytics tabs honour the DAGI selection, against the real server unmocked: at 375x560 touch in light and dark from a cold #/analytics?tab=rf with real taps only, the DAGI control beside Region/Area opens its bottom sheet, aar and a tap on Aarhus put kommune=0751 in the hash next to tab=rf and on the RF request, the notice shows the server's GET /api/analytics/dagi-unpositioned count, a tap on Channels says the filter does not apply there, and the clear takes it all away with no sideways scroll; at 1440x900 every tab that honours Area sends kommune=0751 on all its requests (never an unfiltered one first) with no 400, the ten tabs that cannot honour it say so in light and dark and send no DAGI param of their own, an unknown code is never sent and leaves the hash, the hash keeps kommune across a tab and a window change, and a second selection is a new request while the hidden count is asked for once. About 30 s locally; no CI duration measured yet. Assigned to shard 1, the lightest by the sum of meanSeconds."}, {"file":"test-issue-1055-m2-live-dagi-e2e.js","shard":3,"env":{"CHROMIUM_REQUIRE":"1","CORESCOPE_SERVER_BIN":"./corescope-server","CORESCOPE_MIGRATE_BIN":"./corescope-migrate"},"output":"e2e","meanSeconds":30,"measurementNote":"New suite; #1055 M2 the DAGI filter on Live and the Area filter on the Live feed, on its own Go server (ports from 13900, a migrated copy of the fixture seeded with test-fixtures/seed-1055-live-dagi-nodes.sql: two nodes in Aarhus kommune, one in Copenhagen, one in Odense; one test area AARHUS): a cold #/live?kommune=0751 link selects Aarhus, filters the map nodes, draws the outline without moving the map and makes one member request; injected live packets: member ADVERTs shown, a non-member ADVERT and a non-advert dropped, no request per packet; the desktop popover is not covered by the feed; a perf bound on 30,000 Live-shaped messages; Area AARHUS filters the feed with its notice and outline, Area AND DAGI passes nobody and the Area outline keeps the slot; leaving Live leaves no listener; a pick and a clear keep follow= and kiosk=1, a saved choice is written into a kiosk link; at 375x560 with touch from a cold start on Home, real taps open the controls, the bottom sheet (not covered), pick Aarhus (the controls close over the fitted map) and clear it. About 30s locally; no CI duration measured yet. Assigned to shard 3, the lightest by meanSeconds.","secondsByExecution":[]}, - {"file":"test-issue-1055-live-panel-e2e.js","shard":2,"env":{"CHROMIUM_REQUIRE":"1","CORESCOPE_SERVER_BIN":"./corescope-server","CORESCOPE_MIGRATE_BIN":"./corescope-migrate"},"output":"e2e","meanSeconds":180,"measurementNote":"New suite; #1055 owner report, the Live controls panel and the map buttons, on its own Go server (tests/e2e-1055-live-server.js: ports from 13900, a migrated copy of the fixture seeded with test-fixtures/seed-1055-live-dagi-nodes.sql, one test area AARHUS): at 1920x870, 1280x800, 768x1024 and 375x560, light and dark, with the controls open, with no selection, Area only, Kommune Aarhus, and Aarhus plus Area AARHUS, the panel meets no map button, the VCR bar, the credit or the legend, and each button is the element at its centre; the notice is one line with the rule and the count and its explanation opens under why?; a DAGI selection grows the panel by at most one row; the open or closed controls survive a reload. About 6 min on a slow 4-vCPU local VM (16 page loads, 89 steps); no CI duration measured yet. Assigned to shard 2, the lightest by meanSeconds.","secondsByExecution":[]}, + {"file":"test-issue-1055-live-panel-e2e.js","shard":2,"env":{"CHROMIUM_REQUIRE":"1","CORESCOPE_SERVER_BIN":"./corescope-server","CORESCOPE_MIGRATE_BIN":"./corescope-migrate"},"output":"e2e","meanSeconds":270,"measurementNote":"New suite; #1055 owner report, the Live controls panel and the map buttons, on its own Go server through the #1055 harness (tests/e2e-1055-live.js: ports from 13900, a migrated copy of the fixture seeded with test-fixtures/seed-1055-live-dagi-nodes.sql, one test area AARHUS): at 1920x870, 1280x800, 768x1024, and with touch at 375x560 and 360x640, light and dark, with the controls open, with no selection, Area only, Kommune Aarhus, and Aarhus plus Area AARHUS, the panel meets no map button, the VCR bar, the credit or the legend, and each button is the element at its centre; the area rule selector (#1055 M3) has computed display none with no filter, is shown and clickable with one, and shares the DAGI row with short labels at 640 px and below; the notice is one line naming the rule and the count under From and Touches, and its explanation opens under why?; a DAGI selection with the selector shown grows the controls by at most one row; the open or closed controls survive a reload. About 9 min on a slow 4-vCPU local VM (20 page loads, 131 steps); no CI duration measured yet. Assigned to shard 2, the lightest by meanSeconds.","secondsByExecution":[]}, {"file":"test-issue-1055-m3-area-rule-e2e.js","shard":2,"env":{"CHROMIUM_REQUIRE":"1","CORESCOPE_SERVER_BIN":"./corescope-server","CORESCOPE_MIGRATE_BIN":"./corescope-migrate"},"output":"e2e","meanSeconds":30,"measurementNote":"New suite; #1055 M3 the area rule on Live (From the area / Touches the area), on its own Go server through the #1055 harness (tests/e2e-1055-live.js, ports from 13900, the M2 seed): a cold #/live?kommune=0751 shows the selector with From checked and the From notice; a click to Touches on the open feed needs no reload and no node request, writes areaRule=touches, names the rule, brings back a dropped member-hop packet and shows hop, observer and sender packets while one touching nothing is dropped; Area AARHUS under Touches; a perf bound on 30,000 Live-shaped messages with 64-hop paths; the hash round-trip with a DAGI clear and pick and follow=; kiosk defaults to Touches and keeps areaRule=from; no listener leak (CDP); Packets keeps the sender rule; at 375x560 with touch from a cold start on Home, real taps switch the rule. About 30s locally; no CI duration measured yet. Assigned to shard 2, the lightest by meanSeconds.","secondsByExecution":[]}, {"file":"test-issue-1076-recommended-adverts-e2e.js","shard":1,"env":{"BASE_URL":"$BASE_URL"},"output":"e2e","meanSeconds":40,"measurementNote":"New suite; #1076 M1 recommended advert settings check on the My Mesh card and the health panel for the #245 seed repeaters (seed-245-advert-intervals.sql), with nodes.recommendedAdverts added to the real /api/config/client response: meshguide.dk values give zero-hop on and flood shorter deviations with the CLI fix and the source link on both cards at 1280x900 and 375x560 (touch), and in the health panel after a real tap on Full health; floodIntervalHours 24 gives no deviation observed; minObservations 20 gives not enough data; the fixture's own config (off) has no nodes block and shows no check on the card or in the health panel. About 40s locally; no CI duration measured yet. Assigned to shard 1, the lightest by meanSeconds.","secondsByExecution":[]} ] diff --git a/test-1055-live-dagi.js b/test-1055-live-dagi.js index 9fb6172e2..ac11705f7 100644 --- a/test-1055-live-dagi.js +++ b/test-1055-live-dagi.js @@ -106,7 +106,7 @@ function noticeCtx(o) { queryString: () => o.dagi, hiddenCount: () => { hiddenCalls++; return Promise.resolve(o.hidden || 0); }, hiddenNotice: (n) => (n > 0 ? n + ' nodes have no position.' : ''), - hiddenShort: (n) => (n > 0 ? n + ' nodes without position' : ''), + hiddenShort: (n) => (n > 0 ? n + ' nodes not on map' : ''), }; } vm.createContext(ctx); @@ -153,7 +153,7 @@ test('Live notice: a checked DAGI code shows the Packets text (and its rule, #10 assert.strictEqual(t.why.textContent, LIVE_FROM_TEXT + ' 4 nodes have no position.'); assert.strictEqual(t.line.title, t.why.textContent, 'the explanation is the line\'s title'); assert.strictEqual(t.rule.textContent, 'From the area: adverts only'); - assert.strictEqual(t.count.textContent, '4 nodes without position'); + assert.strictEqual(t.count.textContent, '4 nodes not on map'); assert.strictEqual(t.el.hidden, false); }); @@ -191,7 +191,7 @@ test('advertsOnlyShort: the one-line rule for each state, named after the area r assert.strictEqual(S.advertsOnlyShort({ dagi: true }), 'From the area: adverts only', 'From unless a rule is given'); assert.strictEqual(S.advertsOnlyShort({ area: true, rule: 'from' }), 'From the area: adverts only'); assert.strictEqual(S.advertsOnlyShort({ area: true, dagi: true, rule: 'from' }), 'From the area: adverts only'); - assert.strictEqual(S.advertsOnlyShort({ dagi: true, rule: 'touches' }), 'Touches the area: any packet type'); + assert.strictEqual(S.advertsOnlyShort({ dagi: true, rule: 'touches' }), 'Touches the area: any type'); assert.strictEqual(S.advertsOnlyShort({ dagi: true, rule: 'bogus' }), 'From the area: adverts only'); assert.strictEqual(S.advertsOnlyShort({ dagi: true, loading: true }), 'From the area: loading member nodes…'); assert.strictEqual(S.advertsOnlyShort({ dagi: true, loading: true, rule: 'touches' }), 'Touches the area: loading member nodes…'); @@ -213,8 +213,8 @@ test('advertsOnlyShort and advertsOnlyNotice agree on when there is a notice', ( test('DagiFilter.hiddenShort: the count for the one-line notice', () => { const D = loadDagi('#/live').DF; - assert.strictEqual(D.hiddenShort(18), '18 nodes without position'); - assert.strictEqual(D.hiddenShort(1), '1 node without position'); + assert.strictEqual(D.hiddenShort(18), '18 nodes not on map'); + assert.strictEqual(D.hiddenShort(1), '1 node not on map'); assert.strictEqual(D.hiddenShort(0), ''); assert.strictEqual(D.hiddenShort('x'), ''); }); @@ -770,7 +770,9 @@ test('live.js markup: #liveDagiFilter right after #liveAreaFilter, and the notic const area = LIVE.indexOf('
0 && dagi > area, 'no #liveDagiFilter after #liveAreaFilter'); - assert.strictEqual(LIVE.slice(area, dagi).replace(/^
]*><\/div>/, '').trim(), '', + // Only the opening of its row with the area rule (#1087 review N2). + assert.strictEqual(LIVE.slice(area, dagi).replace(/^
]*><\/div>/, '') + .replace(//g, '').trim(), '
', 'something sits between the two controls'); assert.ok(/id="liveScopeNotice"[^>]*class="dagi-notice[^"]*"[^>]*role="status"[^>]*hidden/.test(LIVE), 'no hidden status notice'); }); diff --git a/test-1055-m3-area-rule.js b/test-1055-m3-area-rule.js index ede6ffa06..be8c7b404 100644 --- a/test-1055-m3-area-rule.js +++ b/test-1055-m3-area-rule.js @@ -41,6 +41,13 @@ function liveFn(name) { return (next ? rest.slice(0, next.index + 10) : rest) + '\n'; } +// One top-level one-line const of live.js, as a var for the vm context. +function liveConst(name) { + const m = new RegExp('\\n const ' + name + ' = [^\\n]*;\\n').exec(LIVE); + assert.ok(m, 'live.js has no const ' + name); + return m[0].replace('const ', 'var '); +} + function loadScopeFilter() { const ctx = { window: {}, Set, Promise, console }; vm.createContext(ctx); @@ -357,7 +364,7 @@ test('Live: setLiveAreaRule switches the rule, writes the hash, re-renders the n assert.deepStrictEqual(t.hashWrites, [['areaRule', 'touches']]); assert.strictEqual(t.ctx.rebuilds, 1); assert.ok(/Rule: Touches the area\.$/.test(t.els.liveScopeWhy.textContent), t.els.liveScopeWhy.textContent); - assert.strictEqual(t.els.liveScopeRule.textContent, 'Touches the area: any packet type', 'the one line names the rule'); + assert.strictEqual(t.els.liveScopeRule.textContent, 'Touches the area: any type', 'the one line names the rule'); t.ctx.setLiveAreaRule('touches'); assert.strictEqual(t.ctx.rebuilds, 1, 'the same rule again does nothing'); t.ctx.setLiveAreaRule('from'); @@ -392,6 +399,51 @@ test('Live: the selector is hidden with no filter and shows the active rule with assert.deepStrictEqual(checked(), ['false', 'true']); }); +test('Live: only the checked radio is a Tab stop (roving tabindex, #1087 review N3)', async () => { + const t = liveCtx({ area: () => '', dagi: () => '&kommune=0751' }); + t.ctx.syncLiveMemberScopes(); + await settle(); + t.ctx.renderLiveScopeNotice(); + const tabs = () => t.els.liveAreaRule.buttons.map(b => b.getAttribute('tabindex')); + assert.deepStrictEqual(tabs(), ['0', '-1']); + t.ctx.setLiveAreaRule('touches'); + assert.deepStrictEqual(tabs(), ['-1', '0']); +}); + +test('Live: the arrow keys check and focus the next radio, wrapping; other keys do nothing (#1087 review N3)', async () => { + const t = liveCtx({ area: () => '', dagi: () => '&kommune=0751' }); + const on = {}; + const el = t.els.liveAreaRule; + el.addEventListener = (type, fn) => { on[type] = fn; }; + let focused = null; + el.buttons.forEach(b => { b.focus = () => { focused = b; }; }); + vm.runInContext(liveConst('AREA_RULE_KEYS') + liveFn('wireAreaRule'), t.ctx); + t.ctx.syncLiveMemberScopes(); + await settle(); + t.ctx.wireAreaRule(); + assert.strictEqual(typeof on.keydown, 'function', 'no keydown listener on the selector'); + const [from, touches] = el.buttons; + const key = (k, target) => { const e = { key: k, target, prevented: false, preventDefault() { this.prevented = true; } }; on.keydown(e); return e; }; + assert.ok(key('ArrowRight', from).prevented); + assert.strictEqual(t.ctx.areaRule, 'touches'); + assert.strictEqual(focused, touches); + assert.deepStrictEqual(t.hashWrites.at(-1), ['areaRule', 'touches']); + key('ArrowRight', touches); + assert.strictEqual(t.ctx.areaRule, 'from', 'ArrowRight wraps from the last radio to the first'); + assert.strictEqual(focused, from); + key('ArrowLeft', from); + assert.strictEqual(t.ctx.areaRule, 'touches', 'ArrowLeft wraps from the first radio to the last'); + key('ArrowUp', touches); + assert.strictEqual(t.ctx.areaRule, 'from'); + key('ArrowDown', from); + assert.strictEqual(t.ctx.areaRule, 'touches'); + const rebuilds = t.ctx.rebuilds; + assert.strictEqual(key('Tab', touches).prevented, false, 'Tab leaves the group'); + assert.strictEqual(key('a', touches).prevented, false); + assert.strictEqual(key('ArrowLeft', el).prevented, false, 'a key on the group itself, not a radio'); + assert.strictEqual(t.ctx.rebuilds, rebuilds); +}); + test('Live init: the rule is read from the hash after kioskOn, before the first member sync', () => { const init = liveFn('init'); const kiosk = init.indexOf('kioskOn = !!'); @@ -408,8 +460,20 @@ test('Live markup: #liveAreaRule is a radiogroup of two radios between the DAGI assert.ok(a > 0 && r > a && n > r, 'order'); const block = LIVE.slice(r, n); assert.ok(/role="radiogroup"/.test(block)); - assert.ok(/role="radio" data-rule="from"[^>]*>From the area]*>Touches the area]*>From the area<\/span>]*>Touches the area<\/span> { + const CSS = fs.readFileSync(__dirname + '/public/live.css', 'utf8'); + assert.ok(/\.live-controls-body \.live-area-rule\[hidden\] \{ display: none; \}/.test(CSS), 'the class rule beats the [hidden] attribute'); + const phone = CSS.slice(CSS.indexOf('.live-dagi-rule { display: contents; }')); + assert.ok(/^\.live-dagi-rule \{ display: contents; \}\s*@media \(max-width: 640px\) \{/.test(phone), 'the row is not phone-only'); + const block = phone.slice(0, phone.indexOf('\n}\n') + 3); + assert.ok(/\.live-dagi-rule:has\(> \.live-area-rule:not\(\[hidden\]\)\) \{[^}]*display: flex;/.test(block), block); + assert.ok(/\.live-area-rule-more \{ display: none; \}/.test(block), block); }); test('Live: the selector listener is on its own element (gone with the page), none on window or document', () => { diff --git a/test-issue-1055-live-panel-e2e.js b/test-issue-1055-live-panel-e2e.js index b04db6ec5..23975eab2 100644 --- a/test-issue-1055-live-panel-e2e.js +++ b/test-issue-1055-live-panel-e2e.js @@ -4,26 +4,29 @@ * selected, the Live controls panel ("MESH LIVE") covered the right-hand * map buttons, and its long notice made it two lines taller. * - * On its own Go server (tests/e2e-1055-live-server.js: the M2 seed, one - * test area AARHUS), at 1920x870, 1280x800, 768x1024 and 375x560, light and - * dark, with the controls open, for "Kommune: Aarhus" and for Aarhus plus - * Area AARHUS: + * On its own Go server (the #1055 harness, tests/e2e-1055-live.js: the M2 + * seed, one test area AARHUS), at 1920x870, 1280x800, 768x1024, and with + * touch at 375x560 and 360x640, light and dark, with the controls open, for + * "Kommune: Aarhus" and for Aarhus plus Area AARHUS: * 1. The panel's box meets no map button (every Leaflet control, the VCR * bar's buttons, the feed's show button) and neither the VCR bar nor the * map credit; each button is the element at its own centre. Again with * the notice's explanation open. - * 2. The notice is one line (no wrap, nothing cut off) that names the rule - * and, for DAGI, the count of nodes with no position; the explanation - * (the Packets wording, ScopeMemberFilter.advertsOnlyNotice plus - * DagiFilter.hiddenNotice) is its title and opens and closes under a - * "why?" button. - * 3. A DAGI selection grows the controls body by at most one row (the - * taller of the notice line and the DAGI trigger, plus the row gap; - * where Area's label pushes the DAGI trigger onto a row of its own, - * that row plus one notice line), - * measured against the same page without it (no selection, or Area - * only for Area plus DAGI), and the open or - * closed controls are remembered across a reload. + * 2. The notice is one line (no wrap, nothing cut off) that names the area + * rule (#1055 M3) and, for DAGI, the count of nodes with no position, + * under From and under Touches; the explanation (the Packets wording, + * ScopeMemberFilter.advertsOnlyNotice plus DagiFilter.hiddenNotice) is + * its title and opens and closes under a "why?" button. + * 3. The area rule selector (#1055 M3) is not shown with no filter (its + * computed display, #1087 review N1) and shown with one, each radio the + * element at its centre; at 640 px and below it shares the DAGI + * control's row with its short labels (#1087 review N2). + * 4. A DAGI selection, with the selector shown, grows the controls by at + * most one row (the tallest of the notice line, the DAGI trigger and + * the selector, plus the row gap), measured on the children's boxes + * against the same page without it (no selection, or Area only for + * Area plus DAGI), and the open or closed controls are remembered + * across a reload. * * Usage: * (cd cmd/server && go build -o ../../corescope-server .) @@ -41,14 +44,14 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); const { chromium } = require('playwright'); -const { startServer, stop } = require('./tests/e2e-1055-live-server'); +const { requiredFile, startServer, stop } = require('./tests/e2e-1055-live'); const SHOTS = process.env.SCREENSHOT_DIR || ''; const AREA = { label: 'Aarhus test area', latMin: 56.0, latMax: 56.3, lonMin: 10.0, lonMax: 10.4 }; // E2E_PANEL_SIZES ("1280x800,375x560") and E2E_PANEL_THEMES ("light") run a // subset, for a quick local check; CI runs them all. const pick = (env, all) => process.env[env] ? all.filter(v => process.env[env].split(',').includes(String(v).replace(',', 'x'))) : all; -const SIZES = pick('E2E_PANEL_SIZES', [[1920, 870], [1280, 800], [768, 1024], [375, 560]]); +const SIZES = pick('E2E_PANEL_SIZES', [[1920, 870], [1280, 800], [768, 1024], [375, 560], [360, 640]]); const THEMES = pick('E2E_PANEL_THEMES', ['light', 'dark']); const WHY_DAGI = 'Danish-area filter: only adverts are shown, because other packets do not name their sender.'; const WHY_BOTH = 'Area and Danish-area filters: only adverts are shown, because other packets do not name their sender.'; @@ -76,7 +79,7 @@ async function openControls(page) { async function noticeSettled(page, count = true) { await page.waitForFunction((count) => { const n = document.getElementById('liveScopeNotice'); - return n && !n.hidden && (!count || /position/.test(n.textContent)); + return n && !n.hidden && (!count || /not on map/.test(n.textContent)); }, count, { timeout: 10000 }); await frames(page); } @@ -134,7 +137,40 @@ const noticeLine = (page) => page.evaluate(() => { return { text: line.textContent, rule: part('liveScopeRule'), count: part('liveScopeCount'), title: line.title, rows: tops.size, cut, height: line.getBoundingClientRect().height }; }); -const bodyHeight = (page) => page.evaluate(() => document.getElementById('liveControlsBody').scrollHeight); +// The controls' content height, from the boxes of the body's children (a +// display: contents wrapper counts by its own children). Not scrollHeight: +// that also counts the 48 px hit areas (::after) that stick out of the +// 30 px controls. +const bodyHeight = (page) => page.evaluate(() => { + let top = Infinity, bottom = -Infinity; + (function walk(el) { + for (let c = el.firstElementChild; c; c = c.nextElementSibling) { + if (getComputedStyle(c).display === 'contents') { walk(c); continue; } + if (!c.getClientRects().length) continue; + const r = c.getBoundingClientRect(); + top = Math.min(top, r.top); + bottom = Math.max(bottom, r.bottom); + } + })(document.getElementById('liveControlsBody')); + return Math.round(bottom - top); +}); + +// The area rule selector: shown, each radio's box, whether it is the +// element at its centre, its visible label, and the DAGI trigger's box. +const ruleSelector = (page) => page.evaluate(() => { + const el = document.getElementById('liveAreaRule'); + const box = (e) => { const r = e.getBoundingClientRect(); return { x: r.left, y: r.top, w: r.width, h: r.height }; }; + return { + display: getComputedStyle(el).display, + shown: el.checkVisibility(), + radios: [].slice.call(el.querySelectorAll('[data-rule]')).map(b => { + const r = box(b); + const hit = document.elementFromPoint(r.x + r.w / 2, r.y + r.h / 2); + return { rule: b.dataset.rule, box: r, hit: !!hit && b.contains(hit), label: b.innerText.trim(), name: b.getAttribute('aria-label') }; + }), + trigger: box(document.querySelector('#liveDagiFilter .dagi-trigger')), + }; +}); async function shot(page, name) { if (!SHOTS) return; @@ -143,6 +179,7 @@ async function shot(page, name) { } async function main() { + const serverBin = requiredFile('CORESCOPE_SERVER_BIN'); const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'e2e-1055-panel-')); const browser = await chromium.launch({ executablePath: process.env.CHROMIUM_PATH || undefined, @@ -151,14 +188,17 @@ async function main() { let server = null; const numbers = []; try { - server = await startServer(path.join(scratch, 'srv'), { AARHUS: AREA }); + server = await startServer(serverBin, path.join(scratch, 'srv'), { AARHUS: AREA }); const BASE = server.base; console.log('\n#1055 — the Live panel and the map buttons (' + BASE + ')\n'); for (const [width, height] of SIZES) { for (const theme of THEMES) { const size = width + 'x' + height + '-' + theme; - const ctx = await browser.newContext({ viewport: { width, height }, colorScheme: theme }); + // A phone has touch: the 48 px controls (#1087 review N2 measured + // the selector's row with touch). + const phone = width < 500; + const ctx = await browser.newContext({ viewport: { width, height }, colorScheme: theme, hasTouch: phone, isMobile: phone }); await ctx.addInitScript(t => { if (sessionStorage.getItem('e2e-seeded')) return; sessionStorage.setItem('e2e-seeded', '1'); @@ -179,6 +219,11 @@ async function main() { await frames(page); base.dagi = await bodyHeight(page); await assertClear(page, size + ' no selection'); + // #1087 review N1: [hidden] alone loses to the class's display. + const r = await ruleSelector(page); + assert.equal(r.display, 'none', 'the area rule selector shows with no filter'); + assert.equal(r.shown, false); + assert.equal(await page.locator('#liveAreaRule').isVisible(), false); }); await step(size + ': Area only, the open panel clears every map button', async () => { await page.evaluate(() => localStorage.setItem('meshcore-area-filter', 'AARHUS')); @@ -203,16 +248,48 @@ async function main() { await assertClear(page, where); }); - await step(where + ': the notice is one line with the rule and the count; the explanation is its title', async () => { - const l = await noticeLine(page); - assert(l, 'no notice line'); - assert.equal(l.rows, 1, 'the notice runs over ' + l.rows + ' lines: ' + l.text); - assert(!l.cut, 'the notice is cut off: ' + l.text); - assert.equal(l.rule, 'Adverts only'); - assert.match(l.count, /^\d+ nodes? without position$/); + await step(where + ': the area rule selector is shown and clickable' + (width <= 640 ? ', on the DAGI control\'s row' : ''), async () => { + const r = await ruleSelector(page); + assert(r.shown, 'the selector is not shown with a filter'); + assert.deepEqual(r.radios.map(b => b.name), ['From the area', 'Touches the area']); + for (const b of r.radios) assert(b.hit, b.rule + ' is covered at its centre ' + JSON.stringify(b.box)); + if (width <= 640) { + // #1087 review N2: no row of its own on a phone. + for (const b of r.radios) { + assert(Math.abs((b.box.y + b.box.h / 2) - (r.trigger.y + r.trigger.h / 2)) < 2, + b.rule + ' is not on the DAGI row: ' + JSON.stringify(b.box) + ' trigger ' + JSON.stringify(r.trigger)); + } + assert.deepEqual(r.radios.map(b => b.label), ['From', 'Touches']); + } else { + assert.deepEqual(r.radios.map(b => b.label), ['From the area', 'Touches the area']); + } + }); + + await step(where + ': the notice is one line with the rule and the count, under From and Touches; the explanation is its title', async () => { const why = sel === 'dagi' ? WHY_DAGI : WHY_BOTH; - assert(l.title.startsWith(why + ' '), 'title: ' + l.title); - assert(/no position, so no Danish-area filter can include/.test(l.title), 'title: ' + l.title); + const check = async (rule, title) => { + const l = await noticeLine(page); + assert(l, 'no notice line'); + assert.equal(l.rows, 1, 'the notice runs over ' + l.rows + ' lines: ' + l.text); + assert(!l.cut, 'the notice is cut off: ' + l.text); + assert.equal(l.rule, rule); + assert.match(l.count, /^\d+ nodes? not on map$/); + assert(l.title.startsWith(title), 'title: ' + l.title); + assert(/no position, so no Danish-area filter can include/.test(l.title), 'title: ' + l.title); + // The "why?" link stays on the line, not wrapped under it. + const tops = await page.evaluate(() => [document.getElementById('liveScopeLine'), document.getElementById('liveScopeWhyBtn')] + .map(e => { const r = e.getBoundingClientRect(); return Math.round(r.top + r.height / 2); })); + assert(Math.abs(tops[0] - tops[1]) <= 1, '"why?" wrapped: ' + tops); + }; + await check('From the area: adverts only', why + ' Rule: From the area. '); + await page.click('#liveAreaRule [data-rule="touches"]'); + await page.waitForFunction(() => document.getElementById('liveScopeRule').textContent.startsWith('Touches')); + await frames(page); + await check('Touches the area: any type', why.replace(/: only adverts are shown.*$/, ': a packet is shown when')); + await shot(page, width + 'x' + height + '-' + theme + '-' + sel.replace('+', '-') + '-touches'); + await page.click('#liveAreaRule [data-rule="from"]'); + await page.waitForFunction(() => document.getElementById('liveScopeRule').textContent.startsWith('From')); + await frames(page); }); await step(where + ': the "why?" button opens and closes the explanation, and the panel still clears the buttons', async () => { @@ -230,30 +307,18 @@ async function main() { await page.locator('#liveScopeWhy').waitFor({ state: 'hidden' }); }); - await step(where + ': the controls grow by at most one row', async () => { + await step(where + ': with the selector shown, the controls grow by at most one row', async () => { const withSel = await bodyHeight(page); - // One row: the taller of the notice line and the DAGI trigger, - // plus the body's row gap. - // When Area's own label leaves no room beside it (375 px), the - // DAGI trigger takes a row of its own as well; only then does that - // row count, and the notice may still add one line, no more. - const m = await page.evaluate(() => { - const box = (s) => { const el = document.querySelector(s); return el ? el.getBoundingClientRect() : null; }; + // One row: the tallest of the notice line, the DAGI trigger and + // the selector, plus the body's row gap. + const bound = await page.evaluate(() => { + const h = (s) => { const el = document.querySelector(s); return el && el.getClientRects().length ? el.getBoundingClientRect().height : 0; }; const gap = parseFloat(getComputedStyle(document.getElementById('liveControlsBody')).rowGap) || 0; - const line = box('#liveScopeNotice .live-scope-notice-line'); - const trigger = box('#liveDagiFilter .dagi-trigger'); - const area = box('#liveAreaFilter .region-dropdown-trigger'); - return { - row: Math.max(line ? line.height : 16, trigger ? trigger.height : 0) + gap, - line: (line ? line.height : 16) + gap, - ownRow: !!(trigger && area && trigger.top >= area.bottom), - }; + return Math.max(h('#liveScopeNotice .live-scope-notice-line'), h('#liveDagiFilter .dagi-trigger'), h('#liveAreaRule [data-rule]')) + gap; }); - const bound = m.row + (m.ownRow ? m.line : 0); const plain = base[sel]; - numbers.push(where + ': body ' + plain + ' -> ' + withSel + ' px (+' + (withSel - plain) + ', bound ' + Math.ceil(bound) + - (m.ownRow ? ': the DAGI trigger\'s own row plus one notice line' : ': one row') + ')'); - assert(withSel - plain <= bound + 1, 'grew ' + (withSel - plain) + ' px; the bound is ' + bound + ' px'); + numbers.push(where + ': controls ' + plain + ' -> ' + withSel + ' px (+' + (withSel - plain) + ', one row ' + Math.ceil(bound) + ')'); + assert(withSel - plain <= bound + 1, 'grew ' + (withSel - plain) + ' px; one row is ' + bound + ' px'); }); } @@ -284,7 +349,7 @@ async function main() { }); } finally { await browser.close(); - await stop(server); + if (server) await stop(server.child); fs.rmSync(scratch, { recursive: true, force: true }); } console.log('\n ' + numbers.join('\n ')); diff --git a/test-issue-1055-m2-live-dagi-e2e.js b/test-issue-1055-m2-live-dagi-e2e.js index 314870c7a..bbc1933f8 100644 --- a/test-issue-1055-m2-live-dagi-e2e.js +++ b/test-issue-1055-m2-live-dagi-e2e.js @@ -611,6 +611,10 @@ async function main() { assert(sheet.onTop, 'the sheet is covered: ' + JSON.stringify(sheet)); assert(sheet.left >= 0 && sheet.right <= 375, 'the sheet is off screen: ' + JSON.stringify(sheet)); await p.fill('#liveDagiFilter .dagi-search', 'aar'); + // The search applies after its debounce and lays the list out again + // (the tabs go, the rows filter), so the row is picked once it has; + // tapInPlace then waits for it to hold still (#1087 review N5). + await p.waitForFunction(() => { const t = document.querySelector('#liveDagiFilter .dagi-tabs'); return !!t && t.hidden; }); await p.evaluate(() => { const b = [...document.querySelectorAll('#liveDagiFilter .dagi-option')].find(x => !x.hidden && /^Aarhus\b/.test(x.textContent)); b.setAttribute('data-e2e-pick', '1'); diff --git a/test-issue-1055-m3-area-rule-e2e.js b/test-issue-1055-m3-area-rule-e2e.js index 7b31a8a85..ecbad2273 100644 --- a/test-issue-1055-m3-area-rule-e2e.js +++ b/test-issue-1055-m3-area-rule-e2e.js @@ -23,7 +23,12 @@ * new hop, observer and sender packets are shown; one touching nothing * (and one with only unknown hops) is dropped. Back to From: the param * goes and the hop packets leave the feed. - * 3. Area AARHUS under Touches: a hop in it passes, København does not. + * 2b. Keyboard (#1087 review N3): the selector is one Tab stop, on the + * checked radio; the arrow keys check and focus the other one, + * wrapping; Space keeps the focused one checked. + * 3. Area AARHUS under Touches: a hop in it passes, København does not; + * with the filter cleared the selector is hidden by its computed + * display, not only by its attribute (#1087 review N1). * 4. The hash round-trip: a cold #/live?kommune=0751&areaRule=touches * selects Touches; a DAGI clear and a pick keep areaRule=; follow= is * kept by a switch. @@ -31,7 +36,7 @@ * written; &areaRule=from is From; a switch to From there writes * areaRule=from and keeps kiosk=1. * 6. No listener leak: rule switches add none on window or document, and - * the selector keeps one; after leaving Live none of its own is left. + * the selector keeps its click and keydown; after leaving Live none of its own is left. * 7. Perf: Touches over 30,000 Live-shaped messages with 64-hop paths. * 8. Packets is unchanged: #/packets?kommune=0751&areaRule=touches shows * the sender-rule notice word for word, has no selector, and its member @@ -129,14 +134,15 @@ async function selectorBox(page, minHeight) { return r; } -// Event listeners on window and document (CDP), and on the selector. +// Event listeners on window and document (CDP): their counts; on the +// selector: their types. async function listenerCounts(page, cdp) { const out = {}; for (const expr of ['window', 'document', "document.getElementById('liveAreaRule')"]) { const { result } = await cdp.send('Runtime.evaluate', { expression: expr }); if (!result.objectId) { out[expr] = null; continue; } const { listeners } = await cdp.send('DOMDebugger.getEventListeners', { objectId: result.objectId }); - out[expr] = listeners.length; + out[expr] = expr === 'window' || expr === 'document' ? listeners.length : listeners.map(l => l.type).sort().join(','); await cdp.send('Runtime.releaseObject', { objectId: result.objectId }); } return { win: out.window, doc: out.document, sel: out["document.getElementById('liveAreaRule')"] }; @@ -218,6 +224,37 @@ async function main() { assert.equal(req.members.length + req.maps.length, before); }); + await step('keyboard: the selector is one Tab stop and the arrow keys switch the rule (#1087 review N3)', async () => { + const focused = () => page.evaluate(() => { + const a = document.activeElement; + return a && a.closest('#liveAreaRule') ? a.dataset.rule : (a && (a.id || a.className)) || null; + }); + await page.focus('#liveDagiFilter .dagi-clear'); + await page.keyboard.press('Tab'); + assert.equal(await focused(), 'from', 'Tab from the DAGI clear does not land on the checked radio'); + assert.deepEqual(await page.$$eval('#liveAreaRule [data-rule]', bs => bs.map(b => b.tabIndex)), [0, -1]); + await page.keyboard.press('ArrowRight'); + assert.equal(await page.evaluate(() => window._liveAreaRule()), 'touches'); + assert.equal(await focused(), 'touches'); + assert.deepEqual(await checked(page), ['touches']); + assert.equal((await hashParams(page)).areaRule, 'touches'); + await noticeStarts(page, TOUCHES_DAGI); + await page.keyboard.press('Tab'); + assert.notEqual(await focused(), 'from', 'Tab went to the unchecked radio'); + await page.keyboard.press('Shift+Tab'); + assert.equal(await focused(), 'touches', 'Shift+Tab does not come back to the checked radio'); + await page.keyboard.press('ArrowLeft'); + assert.equal(await page.evaluate(() => window._liveAreaRule()), 'from'); + assert.equal(await focused(), 'from'); + await page.keyboard.press('ArrowLeft'); + assert.equal(await page.evaluate(() => window._liveAreaRule()), 'touches', 'ArrowLeft does not wrap'); + await page.keyboard.press(' '); + assert.equal(await page.evaluate(() => window._liveAreaRule()), 'touches', 'Space unchecked the radio'); + await page.keyboard.press('ArrowRight'); + assert.equal(await page.evaluate(() => window._liveAreaRule()), 'from'); + assert(!('areaRule' in await hashParams(page)), 'From kept the param'); + }); + await step('Area AARHUS under Touches: a hop in the area passes, København does not', async () => { await page.click('#liveDagiFilter .dagi-clear'); await page.waitForFunction(() => !/kommune=/.test(location.hash)); @@ -232,6 +269,10 @@ async function main() { await page.click('#liveAreaFilter [data-area="__all__"]'); await page.waitForFunction(() => document.getElementById('liveScopeNotice').hidden); assert.equal(await page.evaluate(() => document.getElementById('liveAreaRule').hidden), true, 'the selector outlived the filter'); + // #1087 review N1: hidden on screen too, not only by its attribute + // (the class's display beats the UA [hidden] rule). + assert.equal(await page.evaluate(() => getComputedStyle(document.getElementById('liveAreaRule')).display), 'none'); + assert.equal(await page.locator('#liveAreaRule').isVisible(), false, 'the selector shows with no filter'); }); await step('perf: Touches over 30,000 Live-shaped messages with 64-hop paths', async () => { @@ -342,7 +383,8 @@ async function main() { const v3 = await visit(6); assert.equal(v3.afterSwitches.win, v3.inLive.win, 'switches added window listeners: ' + JSON.stringify(v3)); assert.equal(v3.afterSwitches.doc, v3.inLive.doc, 'switches added document listeners: ' + JSON.stringify(v3)); - assert.equal(v3.afterSwitches.sel, 1, 'the selector has ' + v3.afterSwitches.sel + ' listeners'); + // One click and one keydown (the arrow keys, #1087 review N3). + assert.equal(v3.afterSwitches.sel, 'click,keydown', 'the selector has listeners ' + v3.afterSwitches.sel); // A visit with switches leaves what a visit without them leaves. assert.equal(v3.left.win - v2.left.win, v2.left.win - v1.left.win, 'window: ' + JSON.stringify([v1.left, v2.left, v3.left])); assert.equal(v3.left.doc - v2.left.doc, v2.left.doc - v1.left.doc, 'document: ' + JSON.stringify([v1.left, v2.left, v3.left])); diff --git a/tests/e2e-1055-live-server.js b/tests/e2e-1055-live-server.js deleted file mode 100644 index a83a1ca89..000000000 --- a/tests/e2e-1055-live-server.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict'; -/** - * A Go server for the #1055 Live E2E suites, on a migrated copy of - * test-fixtures/e2e-fixture.db (or E2E_FIXTURE_DB, a copy already prepared - * as in CI) seeded with test-fixtures/seed-1055-live-dagi-nodes.sql (two - * nodes in Aarhus kommune 0751, one in København, one in Odense) and the - * given test areas. Needs CORESCOPE_SERVER_BIN and CORESCOPE_MIGRATE_BIN. - * Ports from E2E_PORT_BASE (default 13900). Nothing leaves the machine. - */ -const assert = require('assert/strict'); -const fs = require('fs'); -const path = require('path'); -const net = require('net'); -const { spawn, execFileSync } = require('child_process'); - -const ROOT = path.join(__dirname, '..'); -const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); - -function requiredFile(variable) { - assert(process.env[variable], variable + ' is required; see the test header'); - const file = path.resolve(process.env[variable]); - assert(fs.statSync(file).isFile(), file + ' must be a file'); - return file; -} - -async function freePort() { - const base = Number(process.env.E2E_PORT_BASE || 13900); - for (let port = base; port < base + 200; port++) { - const ok = await new Promise(resolve => { - const s = net.createServer(); - s.once('error', () => resolve(false)); - s.listen(port, '127.0.0.1', () => s.close(() => resolve(true))); - }); - if (ok) return port; - } - throw new Error('no free port from ' + base); -} - -async function stop(server) { - const child = server && server.child; - if (!child || child.exitCode !== null || child.signalCode !== null) return; - const ended = new Promise(resolve => child.once('exit', resolve)); - child.kill('SIGTERM'); - const timer = setTimeout(() => child.kill('SIGKILL'), 5000); - await ended; - clearTimeout(timer); -} - -/** Starts the server in `dir` with `areas` as config.areas: - * { child, base, log() }. */ -async function startServer(dir, areas) { - const serverBin = requiredFile('CORESCOPE_SERVER_BIN'); - fs.mkdirSync(dir, { recursive: true }); - const db = path.join(dir, 'fixture.db'); - fs.copyFileSync(process.env.E2E_FIXTURE_DB || path.join(ROOT, 'test-fixtures/e2e-fixture.db'), db); - execFileSync(requiredFile('CORESCOPE_MIGRATE_BIN'), ['-db', db], { stdio: 'pipe' }); - execFileSync('sqlite3', ['-cmd', '.timeout 5000', db], - { input: fs.readFileSync(path.join(ROOT, 'test-fixtures/seed-1055-live-dagi-nodes.sql')), stdio: ['pipe', 'pipe', 'pipe'] }); - fs.writeFileSync(path.join(dir, 'config.json'), JSON.stringify({ mqtt: { brokers: [] }, areas: areas || {} })); - const port = await freePort(); - const base = 'http://127.0.0.1:' + port; - let log = ''; - const child = spawn(serverBin, ['-config-dir', dir, '-db', db, '-public', path.join(ROOT, 'public'), '-port', String(port)], - { cwd: dir, stdio: ['ignore', 'pipe', 'pipe'] }); - child.stdout.on('data', c => { log = (log + c).slice(-60000); }); - child.stderr.on('data', c => { log = (log + c).slice(-60000); }); - for (let n = 0; n < 300; n++) { - assert(child.exitCode === null && child.signalCode === null, 'server exited: ' + log); - try { - const r = await fetch(base + '/api/config/client', { signal: AbortSignal.timeout(2000) }); - if (r.ok) return { child, base, log: () => log }; - } catch (_) { /* not up yet */ } - await delay(100); - } - await stop({ child }); - throw new Error('server startup timed out: ' + log); -} - -module.exports = { startServer, stop }; diff --git a/tests/e2e-1055-live.js b/tests/e2e-1055-live.js index ed37aa8a0..343877581 100644 --- a/tests/e2e-1055-live.js +++ b/tests/e2e-1055-live.js @@ -1,7 +1,8 @@ 'use strict'; /** * Shared harness of the #1055 Live area-filter E2E suites (M2: - * test-issue-1055-m2-live-dagi-e2e.js, M3: test-issue-1055-m3-area-rule-e2e.js): + * test-issue-1055-m2-live-dagi-e2e.js, M3: test-issue-1055-m3-area-rule-e2e.js, + * the panel: test-issue-1055-live-panel-e2e.js): * an own Go server on a migrated copy of the fixture seeded with * test-fixtures/seed-1055-live-dagi-nodes.sql, and the Live page helpers. * Moved here from the M2 suite unchanged (startServer takes the areas). @@ -101,10 +102,27 @@ async function openControls(page) { // own container (the gear sits in it) and shifts the map pane; here the // control must already be on screen, be the element at its centre, and be // tall enough (the 30 px Live clear has a 48 px hit area, so minHeight). +// Before the box is read the control must hold still for three animation +// frames as the element at its centre (#1087 review N5: a list still laying +// out or scrolling moved the row under the tap); polled per frame, no fixed +// sleep, and the asserts below report a control that never settles. async function tapInPlace(page, sel, minHeight) { const loc = page.locator(sel).first(); await loc.waitFor({ state: 'visible', timeout: 10000 }); await loc.scrollIntoViewIfNeeded(); + await loc.evaluate(el => new Promise(resolve => { + const end = performance.now() + 5000; + let last = '', still = 0; + (function tick() { + const r = el.getBoundingClientRect(); + const at = [r.left, r.top, r.width, r.height].map(Math.round).join(); + const hit = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); + still = at === last && !!hit && el.contains(hit) ? still + 1 : 0; + last = at; + if (still >= 3 || performance.now() > end) resolve(); + else requestAnimationFrame(tick); + })(); + })); const b = await loc.boundingBox(); const vp = page.viewportSize(); assert(b && b.x >= 0 && b.x + b.width <= vp.width && b.y >= 0 && b.y + b.height <= vp.height, sel + ' off screen ' + JSON.stringify(b)); From 873fbb8d23178e96b7370935e0bbb450c6c5f7f8 Mon Sep 17 00:00:00 2001 From: dborup Date: Wed, 2 Dec 2026 16:44:25 +0000 Subject: [PATCH 5/5] fix(live): the area rule selector fits the panel on phones, radio keys (#1055) Review of #1087 (N2-N4) on the panel branch: - N2: on 640 px and below the DAGI control and the area rule selector share one row (.live-dagi-rule, display: contents above 640 px): the radios show "From" / "Touches" (aria-label keeps the full name) and the DAGI label ellipsizes before the selector would wrap. A DAGI selection now grows the phone panel by 17 px at 375x560 (was 73) and 36 px at 360x640 (was 103). - The one-line notice names the rule and fits 360 px under both rules: "Touches the area: any type", "N nodes not on map". - A capped panel also stops above the map credit where the credit is under it, unless that leaves less than #672's 150 px scroll box. - N3: roving tabindex (only the checked radio is a Tab stop) and the arrow keys check and focus the next radio, wrapping. - N4: a comment on live (per observation) vs rebuilt (per group) judgement under Touches. Co-Authored-By: Claude Opus 5.5 --- public/dagi-filter.js | 5 +-- public/live.css | 21 ++++++++++++ public/live.js | 60 +++++++++++++++++++++++++++++------ public/scope-member-filter.js | 2 +- 4 files changed, 76 insertions(+), 12 deletions(-) diff --git a/public/dagi-filter.js b/public/dagi-filter.js index 268325dc4..40c03e69a 100644 --- a/public/dagi-filter.js +++ b/public/dagi-filter.js @@ -174,11 +174,12 @@ } /** hiddenNotice's count in a few words, for a one-line notice (Live, - * #1055 owner report). '' for none. */ + * #1055 owner report): short enough that the line, with the rule, fits + * a 360 px phone. '' for none. */ function hiddenShort(n) { n = Number(n) || 0; if (n <= 0) return ''; - return (n === 1 ? '1 node' : n + ' nodes') + ' without position'; + return (n === 1 ? '1 node' : n + ' nodes') + ' not on map'; } /** GET /api/config/dagi/polygons as Leaflet rings: every feature's diff --git a/public/live.css b/public/live.css index 7b8f02605..f1e2944ed 100644 --- a/public/live.css +++ b/public/live.css @@ -1590,6 +1590,27 @@ body.live-fullscreen #liveFullscreenToggle:hover, /* #1055 M3: the area rule selector at the house size. */ .live-area-rule button { height: 48px; } } +/* #1087 review N2: the DAGI control and the area rule sit in one wrapper. + Above 640px it lays nothing out (display: contents), so both stay items + of the controls row. At 640px and below they share one row instead of + the selector taking a 48 px row of its own: the radios show their short + labels ("From", "Touches"; the full name is each radio's aria-label, and + the notice line names the rule in full), and the DAGI label gives way + (its ellipsis) before the selector would wrap. */ +.live-dagi-rule { display: contents; } +@media (max-width: 640px) { + .live-controls-body .live-dagi-rule:has(> .live-area-rule:not([hidden])) { + display: flex; + align-items: center; + gap: 8px; + min-width: 0; + max-width: 100%; + } + .live-dagi-rule > .live-dagi-filter-container { min-width: 0; } + .live-dagi-rule > .live-area-rule { flex: none; } + .live-area-rule-more { display: none; } + .live-area-rule button { padding: 2px 6px; } +} .live-controls.is-expanded.is-capped .live-controls-body :is(.live-region-filter-container, .live-area-filter-container):has(.region-dropdown-menu:not([hidden])) { flex: 0 0 100%; } .live-controls.is-expanded.is-capped .live-controls-body .region-dropdown-wrap:has(> .region-dropdown-menu:not([hidden])) { flex: 0 0 100%; } .live-controls.is-expanded.is-capped .live-controls-body .region-dropdown-menu { min-width: 0; max-width: 100%; } diff --git a/public/live.js b/public/live.js index 54875d1ff..d0ab94337 100644 --- a/public/live.js +++ b/public/live.js @@ -393,14 +393,18 @@ } // #1055 M3: the selector shows while a filter is on, with the active rule - // checked. + // checked. Only the checked radio is a Tab stop (roving tabindex, the + // radio group pattern; #1087 review N3). function renderAreaRule(on) { const el = document.getElementById('liveAreaRule'); if (!el) return; el.hidden = !on; el.querySelectorAll('[data-rule]').forEach(function (b) { - const checked = b.dataset.rule === areaRule ? 'true' : 'false'; + const active = b.dataset.rule === areaRule; + const checked = active ? 'true' : 'false'; if (b.getAttribute('aria-checked') !== checked) b.setAttribute('aria-checked', checked); + const tab = active ? '0' : '-1'; + if (b.getAttribute('tabindex') !== tab) b.setAttribute('tabindex', tab); }); } @@ -417,7 +421,10 @@ rebuildFeedList(); } - // One click listener on the selector itself, so it goes with the page. + // The click and key listeners are on the selector itself, so they go with + // the page. The arrow keys check and focus the next radio, wrapping + // (#1087 review N3); Space and Enter click the focused one. + const AREA_RULE_KEYS = { ArrowLeft: -1, ArrowUp: -1, ArrowRight: 1, ArrowDown: 1 }; function wireAreaRule() { const el = document.getElementById('liveAreaRule'); if (!el) return; @@ -425,6 +432,17 @@ const b = e.target && e.target.closest ? e.target.closest('[data-rule]') : null; if (b && el.contains(b)) setLiveAreaRule(b.dataset.rule); }); + el.addEventListener('keydown', function (e) { + const step = AREA_RULE_KEYS[e.key]; + if (!step) return; + const radios = Array.prototype.slice.call(el.querySelectorAll('[data-rule]')); + const at = radios.indexOf(e.target); + if (at < 0) return; + e.preventDefault(); + const next = radios[(at + step + radios.length) % radios.length]; + setLiveAreaRule(next.dataset.rule); + next.focus(); + }); } // #1055 M2: one member set per selection (none fetched again for the same @@ -499,6 +517,10 @@ // Area AND DAGI under the active rule (#1055 M3). From: O(1), the first // observation names the sender for all. Touches: O(observations x hops) // Set lookups, as each observation has its own observer and path. + // Under Touches a WS observation is judged alone (without Realistic) while + // rebuildFeedList judges the whole hash group, so a transmission whose + // Area and DAGI are each touched only by different observations shows + // after a rebuild but not live (#1087 review N4). function passesLiveMemberFilters(packets) { return !memberScopes || memberScopes.acceptsGroup(packets); } @@ -1025,6 +1047,10 @@ }; } + // The capped body's least height (#672: 150 px in short landscape) and + // the least gutter under it (live.css --live-ctrl-gutter). + var CTRL_BOX_MIN = 150; + var CTRL_GUTTER_MIN = 12; var _controlsFitCleanup = null; function initControlsFitTracker() { if (_controlsFitCleanup) { try { _controlsFitCleanup(); } catch (_) {} _controlsFitCleanup = null; } @@ -1034,6 +1060,7 @@ var page = document.querySelector('.live-page'); var bar = document.getElementById('vcrBar'); if (!root || !body || !page) return; + function creditEl() { return page.querySelector('#liveMap .leaflet-control-attribution'); } var raf = 0; function fit() { raf = 0; @@ -1043,7 +1070,18 @@ } var top = body.getBoundingClientRect().top; var barH = bar && bar.getClientRects().length ? bar.getBoundingClientRect().height : 0; - var reserve = window.innerHeight - (page.getBoundingClientRect().bottom - barH); + var limit = page.getBoundingClientRect().bottom - barH; + // #1055: the map credit sits on the VCR bar; on a phone it wraps under + // the panel's x range, so a capped panel stops above it too, unless + // that leaves less than #672's minimum scroll box (short landscape): + // reaching the controls comes first. + var credit = creditEl(); + if (credit && credit.getClientRects().length && header) { + var cr = credit.getBoundingClientRect(), hr = header.getBoundingClientRect(); + if (cr.left < hr.right && cr.right > hr.left && cr.top < limit && + cr.top - top - CTRL_GUTTER_MIN >= CTRL_BOX_MIN) limit = cr.top; + } + var reserve = window.innerHeight - limit; page.style.setProperty('--live-ctrl-top', Math.round(top) + 'px'); page.style.setProperty('--live-ctrl-reserve', Math.max(0, Math.ceil(reserve)) + 'px'); // Measure under the cap; in-flow children only, so an open dropdown @@ -1089,7 +1127,7 @@ if (typeof ResizeObserver === 'function') { try { ro = new ResizeObserver(schedule); - [header, page, bar].concat([].slice.call(body.children)).forEach(function(el) { if (el) ro.observe(el); }); + [header, page, bar, creditEl()].concat([].slice.call(body.children)).forEach(function(el) { if (el) ro.observe(el); }); } catch (_) { ro = null; } } schedule(); @@ -2308,10 +2346,14 @@
- -