gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit9334845393348453Re-vendor tickets to Hybriel set day35mre93348453/tests/e2e-menu-current.mjs

10.1 KB

  1. // tests/e2e-menu-current.mjs (tickets mission 023): the menu's current-page marker, the Inbox badge and the MdEditor's real keys in
  2. // LISBETH's real test Chrome over CDP. Real mouse clicks and real key events; no /json/new, no clipboard. ONE existing page tab,
  3. // picked fresh from /json, brought to front, left at about:blank. Run it only under the shared lock:
  4. // timeout 600 flock /media/STORAGE/claude-scratch/atlas/lisbeth.lock node tests/e2e-menu-current.mjs <port> <sid> <shotDir> [cdpPort=9223] [tag=new]
  5. // The app runs on loreana on a COPY of a tickets backup, reached from lisbeth through `ssh -R <port>:127.0.0.1:<port>`.
  6. // Walk at 390 (phone: the ☰ opens the sidebar with the menu) and 1280 (header menu): list → Inbox → a ticket; the marker moves, the
  7. // 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.
  8. import { writeFileSync } from 'node:fs';
  9. const [port, sid, shotDir, cdpPort = '9223', tag = 'new'] = process.argv.slice(2);
  10. const BASE = `http://127.0.0.1:${port}`, sleep = ms => new Promise(r => setTimeout(r, ms)), J = JSON.stringify;
  11. const list = await (await fetch(`http://127.0.0.1:${cdpPort}/json`)).json();
  12. const pages = list.filter(t => t.type === 'page');
  13. const tgt = pages.find(t => t.url === 'about:blank') || pages[0];
  14. if (!tgt) { console.log('NO PAGE TAB'); process.exit(2); }
  15. const ws = new WebSocket(tgt.webSocketDebuggerUrl.replace(/ws:\/\/[^/]+/, `ws://127.0.0.1:${cdpPort}`)); await new Promise(r => ws.onopen = r);
  16. let id = 0; const pend = new Map(), errors = [];
  17. 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)); };
  18. const send = (method, params = {}) => new Promise((ok, bad) => { const i = ++id; pend.set(i, [ok, bad]); ws.send(J({ id: i, method, params })); });
  19. 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; };
  20. 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; };
  21. 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 }; })()`);
  22. 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 }); };
  23. const shot = async name => { const r = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(`${shotDir}/e2e-${tag}-${name}.png`, Buffer.from(r.data, 'base64')); };
  24. let pass = 0, fail = 0; const check = (n, ok, d = '') => { ok ? pass++ : fail++; console.log((ok ? 'PASS ' : 'FAIL ') + n + (ok ? '' : ' ' + d)); };
  25. const hydrated = () => waitFor(`!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1`, 'hydrated');
  26. 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); };
  27. const enter = () => key('Enter', 'Enter', 13, '\r');
  28. const type = async t => { for (const ch of t) { if (ch === '\n') await enter(); else await key(ch, '', undefined, ch); } };
  29. 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); };
  30. 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); };
  31. // the menu the user sees: at 390 the ☰ opens the sidebar (a real tap), from 60rem the header carries it
  32. const menuScope = W => W === 390 ? '#sidebar main-menu' : 'application-header main-menu';
  33. 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); };
  34. 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 }))`);
  35. 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 }; };
  36. await send('Page.enable'); await send('Runtime.enable'); await send('DOM.enable'); await send('Network.enable');
  37. await send('Target.activateTarget', { targetId: tgt.id }).catch(() => {});
  38. await send('Page.bringToFront');
  39. await send('Network.setCookie', { name: 'hlsid', value: sid, url: BASE, httpOnly: true });
  40. await send('Storage.clearDataForOrigin', { origin: BASE, storageTypes: 'service_workers,cache_storage' }).catch(() => {});
  41. try {
  42. for (const W of [390, 1280]) {
  43. await view(W); const T = `${W}: `;
  44. await go('/', '#tickets li'); await openMenu(W);
  45. let r = await markedIs(W, '/'); const badge = r.m[1].badge[0];
  46. check(T + 'list: All tickets has aria-current="page" + class current, Inbox not', r.ok, J(r.m));
  47. 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));
  48. await shot(`${W}-1-list`);
  49. // real click on the Inbox item
  50. await click(menuScope(W) + ' a[href="/inbox"]'); await waitFor(`location.pathname === '/inbox' && !!document.querySelector('#pendingbox, #reviewbox')`, 'inbox page'); await hydrated(); await sleep(1500);
  51. const rows = await ev(`document.querySelectorAll('#pending li, #review li').length`);
  52. await openMenu(W); r = await markedIs(W, '/inbox');
  53. check(T + 'inbox (clicked): the marker moved to Inbox, All tickets unmarked', r.ok, J(r.m));
  54. 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));
  55. await shot(`${W}-2-inbox`);
  56. // real click on a ticket of the inbox
  57. await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }); await sleep(300);
  58. await click('#pending li a.subject, #review li a.subject'); await waitFor(`!!document.querySelector('#subject')`, 'ticket page'); await hydrated(); await sleep(1500);
  59. const path = await ev('location.pathname');
  60. await openMenu(W); r = await markedIs(W, '/');
  61. 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));
  62. await shot(`${W}-3-ticket`);
  63. await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }); await sleep(300);
  64. // MdEditor in the comment field: a list, then a table, with real keys (not posted)
  65. await waitFor(`!!document.querySelector('#commentform md-editor article')`, 'comment editor');
  66. await click('#commentform md-editor article'); await waitFor(`document.querySelector('#commentform md-editor article').contains(document.activeElement)`, 'editor focused'); await sleep(300);
  67. await type('- apples\npears\n'); await enter(); await sleep(250);
  68. await type('| Item | Qty |\n|:---|---:|\n'); await sleep(300);
  69. await type('milk'); await key('Tab', 'Tab', 9); await type('2'); await sleep(400);
  70. 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 }; })()`);
  71. 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));
  72. 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));
  73. await shot(`${W}-4-comment-table`);
  74. }
  75. check('no console errors during the walk', errors.length === 0, errors.slice(0, 3).join(' | '));
  76. } catch (e) { console.log('E2E ERROR', e.stack || e); fail++; }
  77. console.log(`\nSUMMARY ${tag}: ${pass} passed, ${fail} failed`);
  78. await send('Emulation.clearDeviceMetricsOverride'); await send('Emulation.setTouchEmulationEnabled', { enabled: false });
  79. await send('Page.navigate', { url: 'about:blank' }); await sleep(300);
  80. ws.close(); process.exit(fail ? 1 : 0);

Branches

Latest commits

  • 93348453Re-vendor tickets to Hybriel set day35mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
  • f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
  • 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
  • 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
  • d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
  • afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
  • 48c1ba79tickets: md-paste-files gate with the file manager casesmre
  • f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
  • 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre
  • 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
  • 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre
  • 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
  • 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
  • 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre
  • 8179d287tickets: standby service on its port plus 10 and a deploy that hands over through it without a gapmre
  • 0398145ctickets: the table grid rule is marked functional for check-thememre