gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf3d61711f3d61711mission 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 scriptmref3d61711/tests/e2e-theme.mjs

12.1 KB

  1. // tests/e2e-theme.mjs (tickets mission 022): the theme move in a REAL browser (lisbeth's test Chrome over CDP, ONE existing tab
  2. // reused, never a new one), real mouse clicks. Not a gate: prints numbers, writes screenshots.
  3. // node tests/e2e-theme.mjs <old|new> <port> <sid> <shotDir> <targetId> [cdpPort=8756]
  4. // The app runs on loreana on a COPY of a tickets backup, reached from lisbeth's Chrome through `ssh -R <port>:127.0.0.1:<port>`.
  5. // Phase 1 (old and new): the 390 audit of every page (tests/mobile-measure.js) at 390 and 1280. Phase 2 (new only): the walk —
  6. // list → open a ticket → comment with an attachment → change state → user menu → sidebar → settings, at 390 and 1280.
  7. // File to attach: on lisbeth /tmp/x2-files/shot.png (DOM.setFileInputFiles takes paths on the browser's machine).
  8. import { writeFileSync, readFileSync } from 'node:fs';
  9. import { dirname, join } from 'node:path';
  10. import { fileURLToPath } from 'node:url';
  11. const [mode, port, sid, shotDir, tid, cdpPort = '8756'] = process.argv.slice(2);
  12. const BASE = `http://127.0.0.1:${port}`, sleep = ms => new Promise(r => setTimeout(r, ms)), J = JSON.stringify;
  13. const MEASURE = readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'mobile-measure.js'), 'utf8');
  14. const list = await (await fetch(`http://127.0.0.1:${cdpPort}/json/list`)).json();
  15. const tgt = list.find(t => t.id === tid);
  16. const ws = new WebSocket(tgt.webSocketDebuggerUrl.replace(/ws:\/\/[^/]+/, `ws://127.0.0.1:${cdpPort}`)); await new Promise(r => ws.onopen = r);
  17. let id = 0; const pend = new Map(), consoleErrors = [];
  18. 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') consoleErrors.push(J(d.params.exceptionDetails).slice(0, 200)); else if (d.method === 'Runtime.consoleAPICalled' && d.params.type === 'error') consoleErrors.push(d.params.args.map(a => a.value || a.description).join(' ').slice(0, 200)); };
  19. const send = (method, params = {}) => new Promise((ok, bad) => { const i = ++id; pend.set(i, [ok, bad]); ws.send(J({ id: i, method, params })); });
  20. 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; };
  21. 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; };
  22. 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, w: r.width, h: r.height }; })()`);
  23. const click = async sel => { let r = await rect(sel); if (!r) throw new Error('no ' + sel); await sleep(120); 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 }); };
  24. const shot = async name => { const r = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(`${shotDir}/${mode}-${name}.png`, Buffer.from(r.data, 'base64')); };
  25. const results = []; const check = (n, ok, d = '') => { results.push([n, !!ok]); console.log((ok ? 'PASS ' : 'FAIL ') + n + (ok ? '' : ' ' + d)); };
  26. const hydrated = () => waitFor(`!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1`, 'hydrated');
  27. 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(700); };
  28. const shows = sel => ev(`(() => { const e = document.querySelector(${J(sel)}); return !!e && e.getBoundingClientRect().width > 0; })()`);
  29. const audits = [];
  30. async function audit(name, W) {
  31. const m = await ev(`window.__W = ${W};` + MEASURE);
  32. const r = { name, W, scrollWidth: m.docScrollWidth, taps: m.taps, tapsSmall: m.tapsSmall, small: m.tapsSmallList.slice(0, 5), inputsSmall: m.inputsSmall, inputsSmallList: m.inputsSmallList, textSmall: m.textSmall, textSmallList: m.textSmallList.slice(0, 4), wide: m.wide, wideList: m.wideList.slice(0, 3), header: m.headerH };
  33. audits.push(r); console.log('AUDIT', J(r)); await shot(`${W}-${name.replace(/[^a-z0-9]+/gi, '-')}`);
  34. }
  35. await send('Page.enable'); await send('Runtime.enable'); await send('DOM.enable'); await send('Network.enable');
  36. await send('Target.activateTarget', { targetId: tid }).catch(() => {});
  37. await send('Page.bringToFront');
  38. await send('Network.setCookie', { name: 'hlsid', value: sid, url: BASE, httpOnly: true });
  39. await send('Storage.clearDataForOrigin', { origin: BASE, storageTypes: 'service_workers,cache_storage' }).catch(() => {});
  40. 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); };
  41. const TICKET = '/hycon/40', PROJ = 'hycon';
  42. try {
  43. for (const W of [390, 1280]) {
  44. await view(W);
  45. await go('/', '#heading'); await audit('list', W);
  46. await go(TICKET, '#subject'); await audit('ticket', W);
  47. await go('/' + PROJ, '#newticket'); await click('#newticket summary'); await sleep(600); await audit('new-ticket', W);
  48. await go('/projects/' + PROJ + '/settings', '#settingstitle'); await audit('project-settings', W);
  49. await go('/inbox', 'main'); await audit('inbox', W);
  50. await send('Page.navigate', { url: BASE + '/login/callback' }); await sleep(1500); await audit('login-failed', W);
  51. }
  52. if (mode === 'new') {
  53. for (const W of [390, 1280]) {
  54. await view(W); const T = `${W}-`;
  55. // list → open a ticket by a real click on its subject
  56. await go('/' + PROJ, '#heading'); await waitFor(`document.querySelectorAll('.tickets li').length > 0`, 'ticket rows');
  57. await click('.tickets li a.subject'); await waitFor(`!!document.querySelector('#subject')`, 'ticket page'); await hydrated(); await sleep(500);
  58. check(`${T}list: a click on a ticket opens its page (${await ev('location.pathname')})`, await shows('#subject'));
  59. // user menu, sidebar
  60. if (W === 390) { await click('button.user-toggle'); await waitFor(`document.querySelector('#user-menu').matches(':popover-open')`, 'user menu'); await sleep(300);
  61. check(`${T}user menu opens (name ${J(await ev(`document.querySelector('#whoami').textContent`))}, Log out shown)`, await shows('#logout')); await shot(`${T}user-menu`); await click('#whoami'); await sleep(200); await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }); await sleep(300);
  62. await click('button.menu-toggle'); await waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, 'sidebar'); await sleep(300);
  63. check(`${T}sidebar opens with the main menu (${J(await ev(`[...document.querySelectorAll('#sidebar main-menu a')].map(a => a.textContent)`))})`, (await ev(`document.querySelectorAll('#sidebar main-menu a').length`)) === 2); await shot(`${T}sidebar`);
  64. await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }); await sleep(300);
  65. } else { await click('button.user-toggle'); await waitFor(`document.querySelector('#user-menu').matches(':popover-open')`, 'user menu'); await sleep(300); check(`${T}user menu opens, Log out shown`, await shows('#logout')); await shot(`${T}user-menu`); await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }); await sleep(300); }
  66. // comment with an attachment
  67. await waitFor(`!!document.querySelector('#commentform files-upload')`, 'comment form');
  68. const n0 = await ev(`document.querySelectorAll('#events li.comment').length`);
  69. await rect('#commentform'); const { root } = await send('DOM.getDocument'); const { nodeId } = await send('DOM.querySelector', { nodeId: root.nodeId, selector: '#commentform files-upload label.choose input[type=file]' });
  70. await send('DOM.setFileInputFiles', { files: ['/tmp/x2-files/shot.png'], nodeId });
  71. await waitFor(`document.querySelectorAll('#commentform files-upload li.picked').length === 1`, 'file picked');
  72. await click('#commentform md-editor article'); await sleep(300); await send('Input.insertText', { text: `X2 ${mode} ${W}: comment with an attachment` });
  73. await shot(`${T}comment-filled`);
  74. await click('#commentform button.comment-post');
  75. const sent = await waitFor(`document.querySelectorAll('#events li.comment').length === ${n0 + 1} && [...document.querySelectorAll('#events li.comment')].some(li => li.textContent.includes('X2 ${mode} ${W}') && li.querySelectorAll('ul.comment-files img').length === 1)`, 'comment sent', 30000);
  76. check(`${T}comment with an attachment is posted and shows its thumbnail`, sent);
  77. await ev(`[...document.querySelectorAll('#events li.comment')].pop().scrollIntoView({ block: 'center' })`); await sleep(500); await shot(`${T}comment-sent`);
  78. // change state: pick a state in the select, real click on the button
  79. const st0 = await ev(`document.querySelector('#state').textContent`);
  80. const opts = await ev(`[...document.querySelectorAll('#stateform select option')].map(o => o.value + ':' + o.textContent)`);
  81. if (opts.length) {
  82. const to = await ev(`(() => { const s = document.querySelector('#stateform select'); const o = [...s.options].find(o => o.value && o.textContent.trim() !== ${J(st0)}); return o ? o.value : null; })()`);
  83. await rect('#stateform'); await ev(`(() => { const s = document.querySelector('#stateform select'); s.value = ${J(to)}; s.dispatchEvent(new Event('input', { bubbles: true })); s.dispatchEvent(new Event('change', { bubbles: true })); })()`);
  84. await click('#statesend');
  85. const changed = await waitFor(`document.querySelector('#state').textContent.trim() !== ${J(st0.trim())}`, 'state changed', 20000);
  86. check(`${T}state change: ${J(st0)} → ${J(await ev(`document.querySelector('#state').textContent`))}`, changed);
  87. await shot(`${T}state-changed`);
  88. } else console.log(' (no state options for this user on this ticket)');
  89. // settings (admin link on the project page)
  90. await go('/' + PROJ, '#heading');
  91. if (await shows('#settingslink')) { await click('#settingslink'); await waitFor(`!!document.querySelector('#settingstitle')`, 'settings'); await hydrated(); check(`${T}project settings opens by a click (${await ev('location.pathname')})`, await shows('#settingstitle')); await shot(`${T}settings`); }
  92. else console.log(' (no settings link: not an admin of', PROJ + ')');
  93. // header at this width
  94. await go('/', '#heading'); await shot(`${T}list-final`);
  95. }
  96. }
  97. const badAudits = audits.filter(a => (a.W === 390 && a.tapsSmall) || a.wide || a.scrollWidth > a.W || a.inputsSmall);
  98. console.log(`\nSUMMARY ${mode}: audits ${audits.length}, at 390 taps<44 total ${audits.filter(a => a.W === 390).reduce((s, a) => s + a.tapsSmall, 0)}, wider-than-screen ${audits.reduce((s, a) => s + a.wide, 0)}, inputs<16 ${audits.reduce((s, a) => s + a.inputsSmall, 0)}, text<14 ${audits.filter(a => a.W === 390).reduce((s, a) => s + a.textSmall, 0)}; checks ${results.filter(r => r[1]).length}/${results.length}; console errors ${consoleErrors.length}`);
  99. for (const e of consoleErrors.slice(0, 5)) console.log(' CONSOLE', e);
  100. writeFileSync(`${shotDir}/${mode}-audits.json`, J(audits, null, 1));
  101. } catch (e) { console.log('E2E ERROR', e.stack || e); process.exitCode = 1; }
  102. await send('Emulation.clearDeviceMetricsOverride'); await send('Emulation.setTouchEmulationEnabled', { enabled: false });
  103. await send('Page.navigate', { url: 'about:blank' }); await sleep(300);
  104. ws.close(); process.exit(process.exitCode || 0);

Branches

Latest commits

  • 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
  • b7ec5981mission brief 015mre
  • 5dc68731docker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • 8a460b16mission 014: Apollo's 'stream opened right after the start gets no live events' is not a tickets bug — events.mjs checks early streamsmre