]*><\/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 deeb5029a..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);
@@ -296,7 +303,10 @@ function liveCtx(o) {
});
els.liveAreaRule = { hidden: true, buttons: [button('from'), button('touches')],
querySelectorAll() { return this.buttons; } };
- els.liveScopeNotice = { hidden: true, textContent: '' };
+ els.liveScopeNotice = { hidden: true };
+ // The panel PR's one-line notice: the explanation (the full text) and the
+ // line (the rule in a few words) are its parts.
+ for (const id of ['liveScopeWhy', 'liveScopeRule', 'liveScopeCount', 'liveScopeLine']) els[id] = { textContent: '', title: '' };
const ctx = {
console, Promise, Set,
ScopeMemberFilter: S,
@@ -353,12 +363,14 @@ test('Live: setLiveAreaRule switches the rule, writes the hash, re-renders the n
assert.strictEqual(t.ctx.passesLiveMemberFilters([grpTxt(['a1'])]), true, 'the open feed switched without a reload');
assert.deepStrictEqual(t.hashWrites, [['areaRule', 'touches']]);
assert.strictEqual(t.ctx.rebuilds, 1);
- assert.ok(/Rule: Touches the area\.$/.test(t.els.liveScopeNotice.textContent), t.els.liveScopeNotice.textContent);
+ 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 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');
assert.deepStrictEqual(t.hashWrites[1], ['areaRule', ''], 'From (the default) leaves the hash');
- assert.ok(/Rule: From the area\.$/.test(t.els.liveScopeNotice.textContent));
+ assert.ok(/Rule: From the area\.$/.test(t.els.liveScopeWhy.textContent));
+ assert.strictEqual(t.els.liveScopeRule.textContent, 'From the area: adverts only');
await settle();
assert.strictEqual(t.requests.length, before, 'a rule switch sent a request');
});
@@ -387,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 = !!');
@@ -403,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
new file mode 100644
index 000000000..23975eab2
--- /dev/null
+++ b/test-issue-1055-live-panel-e2e.js
@@ -0,0 +1,360 @@
+#!/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 (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 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 .)
+ * (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 { 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], [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.';
+
+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 || /not on map/.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 };
+});
+
+// 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;
+ fs.mkdirSync(SHOTS, { recursive: true });
+ await page.screenshot({ path: path.join(SHOTS, 'live-panel-' + name + '.png') });
+}
+
+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,
+ args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
+ });
+ let server = null;
+ const numbers = [];
+ try {
+ 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;
+ // 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');
+ 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');
+ // #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'));
+ 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 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;
+ 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 () => {
+ 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 + ': with the selector shown, the controls grow by at most one row', async () => {
+ const withSel = await bodyHeight(page);
+ // 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;
+ return Math.max(h('#liveScopeNotice .live-scope-notice-line'), h('#liveDagiFilter .dagi-trigger'), h('#liveAreaRule [data-rule]')) + gap;
+ });
+ const plain = base[sel];
+ 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');
+ });
+ }
+
+ 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();
+ if (server) await stop(server.child);
+ 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/test-issue-1055-m2-live-dagi-e2e.js b/test-issue-1055-m2-live-dagi-e2e.js
index e152e4237..bbc1933f8 100644
--- a/test-issue-1055-m2-live-dagi-e2e.js
+++ b/test-issue-1055-m2-live-dagi-e2e.js
@@ -213,7 +213,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);
});
@@ -316,14 +316,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');
});
@@ -413,7 +413,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.
@@ -461,7 +461,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,
@@ -584,7 +584,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();
});
@@ -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 42875554c..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 () => {
@@ -300,7 +341,7 @@ async function main() {
assert.equal(await p.evaluate(() => window._liveAreaRule()), 'touches');
assert(!('areaRule' in await hashParams(p)), 'the kiosk default was written');
assert.deepEqual(await passes(p, [grp([B1, A1]), grp([B1])]), [true, false]);
- assert((await p.evaluate(() => document.getElementById('liveScopeNotice').textContent)).startsWith(TOUCHES_DAGI));
+ assert((await p.evaluate(() => document.getElementById('liveScopeWhy').textContent)).startsWith(TOUCHES_DAGI));
// A switch to From in kiosk mode names it, since absent means Touches.
await p.evaluate(() => document.querySelector('#liveAreaRule [data-rule="from"]').click());
let q = await hashParams(p);
@@ -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/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', () => {
diff --git a/tests/e2e-1055-live.js b/tests/e2e-1055-live.js
index e7ffcaf34..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).
@@ -85,7 +86,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 (the panel PR) 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; });
async function inject(page, pkts) {
await page.evaluate(ps => ps.forEach(p => window._liveBufferPacket(p)), pkts);
}
@@ -99,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));