tickets
All repositories: gitoria
10.1 KB
// tests/e2e-menu-current.mjs (tickets mission 023): the menu's current-page marker, the Inbox badge and the MdEditor's real keys in// LISBETH's real test Chrome over CDP. Real mouse clicks and real key events; no /json/new, no clipboard. ONE existing page tab,// picked fresh from /json, brought to front, left at about:blank. Run it only under the shared lock:// timeout 600 flock /media/STORAGE/claude-scratch/atlas/lisbeth.lock node tests/e2e-menu-current.mjs <port> <sid> <shotDir> [cdpPort=9223] [tag=new]// The app runs on loreana on a COPY of a tickets backup, reached from lisbeth through `ssh -R <port>:127.0.0.1:<port>`.// Walk at 390 (phone: the ☰ opens the sidebar with the menu) and 1280 (header menu): list → Inbox → a ticket; the marker moves, the// Inbox badge shows the count (= the rows of the inbox page); in the comment field a list and then a table are typed with real keys.import { writeFileSync } from 'node:fs';const [port, sid, shotDir, cdpPort = '9223', tag = 'new'] = process.argv.slice(2);const BASE = `http://127.0.0.1:${port}`, sleep = ms => new Promise(r => setTimeout(r, ms)), J = JSON.stringify;const list = await (await fetch(`http://127.0.0.1:${cdpPort}/json`)).json();const pages = list.filter(t => t.type === 'page');const tgt = pages.find(t => t.url === 'about:blank') || pages[0];if (!tgt) { console.log('NO PAGE TAB'); process.exit(2); }const ws = new WebSocket(tgt.webSocketDebuggerUrl.replace(/ws:\/\/[^/]+/, `ws://127.0.0.1:${cdpPort}`)); await new Promise(r => ws.onopen = r);let id = 0; const pend = new Map(), errors = [];ws.onmessage = m => { const d = JSON.parse(m.data); if (d.id && pend.has(d.id)) { const [ok, bad] = pend.get(d.id); pend.delete(d.id); d.error ? bad(new Error(J(d.error))) : ok(d.result); } else if (d.method === 'Runtime.exceptionThrown') errors.push(J(d.params.exceptionDetails).slice(0, 200)); else if (d.method === 'Runtime.consoleAPICalled' && d.params.type === 'error') errors.push(d.params.args.map(a => a.value || a.description).join(' ').slice(0, 200)); };const send = (method, params = {}) => new Promise((ok, bad) => { const i = ++id; pend.set(i, [ok, bad]); ws.send(J({ id: i, method, params })); });const ev = async x => { const r = await send('Runtime.evaluate', { expression: x, awaitPromise: true, returnByValue: true }); if (r.exceptionDetails) throw new Error(J(r.exceptionDetails).slice(0, 300)); return r.result.value; };const waitFor = async (x, label, t = 25000) => { for (const end = Date.now() + t; Date.now() < end;) { if (await ev(x).catch(() => false)) return true; await sleep(150); } console.log(' TIMEOUT', label); return false; };const rect = async sel => ev(`(() => { const e = document.querySelector(${J(sel)}); if (!e) return null; e.scrollIntoView({ block: 'center' }); const r = e.getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2 }; })()`);const click = async sel => { let r = await rect(sel); if (!r) throw new Error('no ' + sel); await sleep(150); r = await rect(sel); for (const [type, extra] of [['mouseMoved', {}], ['mousePressed', { button: 'left', clickCount: 1 }], ['mouseReleased', { button: 'left', clickCount: 1 }]]) await send('Input.dispatchMouseEvent', { type, x: r.x, y: r.y, ...extra }); };const shot = async name => { const r = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(`${shotDir}/e2e-${tag}-${name}.png`, Buffer.from(r.data, 'base64')); };let pass = 0, fail = 0; const check = (n, ok, d = '') => { ok ? pass++ : fail++; console.log((ok ? 'PASS ' : 'FAIL ') + n + (ok ? '' : ' ' + d)); };const hydrated = () => waitFor(`!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1`, 'hydrated');const key = async (k, code, vk, text, modifiers = 0) => { await send('Input.dispatchKeyEvent', { type: text !== undefined ? 'keyDown' : 'rawKeyDown', key: k, code, windowsVirtualKeyCode: vk, text, modifiers }); await send('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code, windowsVirtualKeyCode: vk, modifiers }); await sleep(30); };const enter = () => key('Enter', 'Enter', 13, '\r');const type = async t => { for (const ch of t) { if (ch === '\n') await enter(); else await key(ch, '', undefined, ch); } };const view = async W => { if (W === 390) { await send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true }); await send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 }); } else { await send('Emulation.setTouchEmulationEnabled', { enabled: false }); await send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false }); } await sleep(300); };const go = async (path, ready) => { await send('Page.navigate', { url: BASE + path }); await waitFor(`!!document.querySelector(${J(ready)})`, 'ready ' + ready + ' on ' + path); await hydrated(); await sleep(1500); };// the menu the user sees: at 390 the ☰ opens the sidebar (a real tap), from 60rem the header carries itconst menuScope = W => W === 390 ? '#sidebar main-menu' : 'application-header main-menu';const openMenu = async W => { if (W !== 390) return; if (await ev(`document.querySelector('#sidebar').matches(':popover-open')`)) return; await click('button.menu-toggle'); await waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, 'sidebar open'); await sleep(300); };const menuState = W => ev(`[...document.querySelectorAll(${J(menuScope(W) + ' a')})].map(a => ({ href: a.getAttribute('href'), aria: a.getAttribute('aria-current'), cls: a.className, label: a.firstChild && a.firstChild.nodeValue, badge: [...a.querySelectorAll('span.count')].map(x => x.textContent), shown: a.getBoundingClientRect().width > 0 }))`);const markedIs = async (W, href) => { await waitFor(`[...document.querySelectorAll(${J(menuScope(W) + ' a')})].some(a => a.getAttribute('aria-current') === 'page')`, 'a marker'); const m = await menuState(W); return { ok: m.length === 2 && m.every(x => x.shown) && m.filter(x => x.aria === 'page').map(x => x.href).join() === href && m.filter(x => x.cls === 'current').length === 1, m }; };await send('Page.enable'); await send('Runtime.enable'); await send('DOM.enable'); await send('Network.enable');await send('Target.activateTarget', { targetId: tgt.id }).catch(() => {});await send('Page.bringToFront');await send('Network.setCookie', { name: 'hlsid', value: sid, url: BASE, httpOnly: true });await send('Storage.clearDataForOrigin', { origin: BASE, storageTypes: 'service_workers,cache_storage' }).catch(() => {});try {for (const W of [390, 1280]) {await view(W); const T = `${W}: `;await go('/', '#tickets li'); await openMenu(W);let r = await markedIs(W, '/'); const badge = r.m[1].badge[0];check(T + 'list: All tickets has aria-current="page" + class current, Inbox not', r.ok, J(r.m));check(T + `list: the Inbox badge is its own span.count (${badge}), the label is the plain "Inbox"`, /^[1-9]\d*$/.test(badge || '') && r.m[1].label === 'Inbox' && r.m[0].badge.length === 0, J(r.m));await shot(`${W}-1-list`);// real click on the Inbox itemawait click(menuScope(W) + ' a[href="/inbox"]'); await waitFor(`location.pathname === '/inbox' && !!document.querySelector('#pendingbox, #reviewbox')`, 'inbox page'); await hydrated(); await sleep(1500);const rows = await ev(`document.querySelectorAll('#pending li, #review li').length`);await openMenu(W); r = await markedIs(W, '/inbox');check(T + 'inbox (clicked): the marker moved to Inbox, All tickets unmarked', r.ok, J(r.m));check(T + `inbox: the badge (${r.m[1].badge[0]}) = the rows of the page (${rows})`, rows > 0 && r.m[1].badge[0] === String(rows), J(r.m));await shot(`${W}-2-inbox`);// real click on a ticket of the inboxawait send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }); await sleep(300);await click('#pending li a.subject, #review li a.subject'); await waitFor(`!!document.querySelector('#subject')`, 'ticket page'); await hydrated(); await sleep(1500);const path = await ev('location.pathname');await openMenu(W); r = await markedIs(W, '/');check(T + `ticket (${path}, clicked from the inbox): the marker is on All tickets (no item path matches), Inbox unmarked, badge kept`, r.ok && /^[1-9]\d*$/.test(r.m[1].badge[0] || ''), J(r.m));await shot(`${W}-3-ticket`);await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }); await sleep(300);// MdEditor in the comment field: a list, then a table, with real keys (not posted)await waitFor(`!!document.querySelector('#commentform md-editor article')`, 'comment editor');await click('#commentform md-editor article'); await waitFor(`document.querySelector('#commentform md-editor article').contains(document.activeElement)`, 'editor focused'); await sleep(300);await type('- apples\npears\n'); await enter(); await sleep(250);await type('| Item | Qty |\n|:---|---:|\n'); await sleep(300);await type('milk'); await key('Tab', 'Tab', 9); await type('2'); await sleep(400);const doc = await ev(`(() => { const a = document.querySelector('#commentform md-editor article'); return { ul: a.querySelectorAll('ul li').length, table: a.querySelectorAll('table').length, cells: [...a.querySelectorAll('td')].map(c => c.textContent), val: document.querySelector('#commentform md-editor input.value').value }; })()`);check(T + 'comment field, real keys: a two-item list, then a table appears (list kept)', doc.ul === 2 && doc.table === 1 && doc.cells.join('|').startsWith('milk|2'), J(doc));check(T + 'comment field: the Markdown value holds the list and a pipe table', /- apples/.test(doc.val) && /\| Item/.test(doc.val) && /\| milk/.test(doc.val), J(doc.val));await shot(`${W}-4-comment-table`);}check('no console errors during the walk', errors.length === 0, errors.slice(0, 3).join(' | '));} catch (e) { console.log('E2E ERROR', e.stack || e); fail++; }console.log(`\nSUMMARY ${tag}: ${pass} passed, ${fail} failed`);await send('Emulation.clearDeviceMetricsOverride'); await send('Emulation.setTouchEmulationEnabled', { enabled: false });await send('Page.navigate', { url: 'about:blank' }); await sleep(300);ws.close(); process.exit(fail ? 1 : 0);
Branches
Latest commits
- 5d144817Merge branch 'records-t40' into mainTickets
- 44ee6f06|||PR records: #43 #45 livemre
- b8fdeee9Merge branch 'p39-routes' into mainTickets
- a0187a0a|||PR Remove redundant route-order loopmre
- 369e4b9cMerge branch 'k40-lists' into mainTickets
- 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
- 610d8e8aMerge branch 'records-t39' into mainTickets
- 32bcdf24|||PR records: GO P39 K40mre
- 4123c6d1Merge branch 'records-t38' into mainTickets
- cd3641a1|||PR records: day72 deploy live, tickets closedmre
- 7d44d852Merge branch 'records-t37' into mainTickets
- 926f7061|||PR records: merges, D36 deploymre
- bf58534eMerge branch 'l33-final' into mainTickets
- 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
- 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
- 5822cb3aMerge branch 'o34-clean' into mainTickets
- 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
- 14cf96b4Merge branch 'records-t36' into mainTickets
- 07749fa1|||PR records: day72 + #40 mergedmre
- ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre