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
- 866397a0mission 023: theme from layouts 76f99f6 (current marker, menu count badge), components from 3794c59 (MdEditor keys); Inbox count as badge, current by address; gates and E2E; reportmre
- 7ed2e5e5deploy.sh: a gate without a 'passed,' line (check-theme) no longer ends the script silently (grep under pipefail), as gitoria/layoutsmre
- bf9064a3mission 022: tickets on the layouts theme (step 1): shell, styles, gates, audit, E2E; reportmre
- f3d61711mission 022 WIP: tickets on the layouts theme (dbe3de7): AppHeader/MainMenu/UserMenu/Sidebar/ContentFirst shell, styles reduced to the app's own, check-theme in the gates, 390 audit + real-Chrome walk scriptmre
- 31cabfccmission 021: E2E script, report, LOG, STATUSmre
- 6aea8683editor look: .empty rule only for p.empty, files off where tickets has no upload, state note one line, events test scrolls the editor into view; synced md-editor (components d702d76+6f27ad3); gate 377/0, events 52/0mre
- dce6ffa6Merge branch 'w28-deflake'mre
- 536092a1tickets (mission 019): de-flake the m016 comment clicks (B: unliked) — calmClick waits until the button stops moving; test only, no app changemre
- 9c5fd42amission 020: attachments E2E proof (lisbeth Chrome, real-data copy), reportmre
- 1206404fREADME attachments, report 018, LOG/STATUSmre
- 3d9e7f3ctests: m017 gate fixes (list count, waits before delete clicks); gate 373/0mre
- dd41d5bcre-sync components 15be2ac; mission 018mre
- 420ad1bbtickets (mission 017 WIP, tickets#27): comment attachments — lib/attachments.hl (storage/attachments, limits, type by content, members-only GET /api/attachments/:id, delete drops, edit keeps), multipart POST …/comments (lib/multipart.hl), Respond block in FilesUpload (blocks verbatim from components w27c 1f8d79d), gate m017 checks written (not yet run); report, LOG, STATUSmre
- a7a1380dmission brief 017mre
- f83d9c0dtickets (mission 016): report reports/016-comments-block.md, LOG, STATUS, README gate countmre
- eef80f55tickets (mission 016): comments through the shared Comments block (layouts#2) — edit (author, earlier versions kept), delete (author, asks; leaves one line in the history), like (members, toggle) on the server (lib/comments.hl, append-only tables), faces + API …/comments/:comment/{edit,delete,like}, push commentChanged; every run of comments is a block in place in the history; Markdown fields on the Hybriel MdEditor (shared/md-editor.js retired: it took over the block's <md-editor>); blocks copied verbatim from components.hybriel 9db927d (tools/sync-components.sh); gates browser 351/0 (old 326/0), events 52/0 (old 52/0)mre
- eb7aeeb9mission brief 016mre
- e4c34759paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
- 26efb23freport w6-events (events test)mre
- c6bfab04mission 015: re-vendor Hybriel 0f396652 (static build), reportmre