tickets
All repositories: gitoria
12.1 KB
// tests/e2e-theme.mjs (tickets mission 022): the theme move in a REAL browser (lisbeth's test Chrome over CDP, ONE existing tab// reused, never a new one), real mouse clicks. Not a gate: prints numbers, writes screenshots.// node tests/e2e-theme.mjs <old|new> <port> <sid> <shotDir> <targetId> [cdpPort=8756]// 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>`.// 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 —// list → open a ticket → comment with an attachment → change state → user menu → sidebar → settings, at 390 and 1280.// File to attach: on lisbeth /tmp/x2-files/shot.png (DOM.setFileInputFiles takes paths on the browser's machine).import { writeFileSync, readFileSync } from 'node:fs';import { dirname, join } from 'node:path';import { fileURLToPath } from 'node:url';const [mode, port, sid, shotDir, tid, cdpPort = '8756'] = process.argv.slice(2);const BASE = `http://127.0.0.1:${port}`, sleep = ms => new Promise(r => setTimeout(r, ms)), J = JSON.stringify;const MEASURE = readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'mobile-measure.js'), 'utf8');const list = await (await fetch(`http://127.0.0.1:${cdpPort}/json/list`)).json();const tgt = list.find(t => t.id === tid);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(), consoleErrors = [];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)); };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, w: r.width, h: r.height }; })()`);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 }); };const shot = async name => { const r = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(`${shotDir}/${mode}-${name}.png`, Buffer.from(r.data, 'base64')); };const results = []; const check = (n, ok, d = '') => { results.push([n, !!ok]); console.log((ok ? 'PASS ' : 'FAIL ') + n + (ok ? '' : ' ' + d)); };const hydrated = () => waitFor(`!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1`, 'hydrated');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); };const shows = sel => ev(`(() => { const e = document.querySelector(${J(sel)}); return !!e && e.getBoundingClientRect().width > 0; })()`);const audits = [];async function audit(name, W) {const m = await ev(`window.__W = ${W};` + MEASURE);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 };audits.push(r); console.log('AUDIT', J(r)); await shot(`${W}-${name.replace(/[^a-z0-9]+/gi, '-')}`);}await send('Page.enable'); await send('Runtime.enable'); await send('DOM.enable'); await send('Network.enable');await send('Target.activateTarget', { targetId: tid }).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(() => {});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 TICKET = '/hycon/40', PROJ = 'hycon';try {for (const W of [390, 1280]) {await view(W);await go('/', '#heading'); await audit('list', W);await go(TICKET, '#subject'); await audit('ticket', W);await go('/' + PROJ, '#newticket'); await click('#newticket summary'); await sleep(600); await audit('new-ticket', W);await go('/projects/' + PROJ + '/settings', '#settingstitle'); await audit('project-settings', W);await go('/inbox', 'main'); await audit('inbox', W);await send('Page.navigate', { url: BASE + '/login/callback' }); await sleep(1500); await audit('login-failed', W);}if (mode === 'new') {for (const W of [390, 1280]) {await view(W); const T = `${W}-`;// list → open a ticket by a real click on its subjectawait go('/' + PROJ, '#heading'); await waitFor(`document.querySelectorAll('.tickets li').length > 0`, 'ticket rows');await click('.tickets li a.subject'); await waitFor(`!!document.querySelector('#subject')`, 'ticket page'); await hydrated(); await sleep(500);check(`${T}list: a click on a ticket opens its page (${await ev('location.pathname')})`, await shows('#subject'));// user menu, sidebarif (W === 390) { await click('button.user-toggle'); await waitFor(`document.querySelector('#user-menu').matches(':popover-open')`, 'user menu'); await sleep(300);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);await click('button.menu-toggle'); await waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, 'sidebar'); await sleep(300);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`);await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'Escape', code: 'Escape', windowsVirtualKeyCode: 27 }); await sleep(300);} 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); }// comment with an attachmentawait waitFor(`!!document.querySelector('#commentform files-upload')`, 'comment form');const n0 = await ev(`document.querySelectorAll('#events li.comment').length`);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]' });await send('DOM.setFileInputFiles', { files: ['/tmp/x2-files/shot.png'], nodeId });await waitFor(`document.querySelectorAll('#commentform files-upload li.picked').length === 1`, 'file picked');await click('#commentform md-editor article'); await sleep(300); await send('Input.insertText', { text: `X2 ${mode} ${W}: comment with an attachment` });await shot(`${T}comment-filled`);await click('#commentform button.comment-post');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);check(`${T}comment with an attachment is posted and shows its thumbnail`, sent);await ev(`[...document.querySelectorAll('#events li.comment')].pop().scrollIntoView({ block: 'center' })`); await sleep(500); await shot(`${T}comment-sent`);// change state: pick a state in the select, real click on the buttonconst st0 = await ev(`document.querySelector('#state').textContent`);const opts = await ev(`[...document.querySelectorAll('#stateform select option')].map(o => o.value + ':' + o.textContent)`);if (opts.length) {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; })()`);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 })); })()`);await click('#statesend');const changed = await waitFor(`document.querySelector('#state').textContent.trim() !== ${J(st0.trim())}`, 'state changed', 20000);check(`${T}state change: ${J(st0)} → ${J(await ev(`document.querySelector('#state').textContent`))}`, changed);await shot(`${T}state-changed`);} else console.log(' (no state options for this user on this ticket)');// settings (admin link on the project page)await go('/' + PROJ, '#heading');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`); }else console.log(' (no settings link: not an admin of', PROJ + ')');// header at this widthawait go('/', '#heading'); await shot(`${T}list-final`);}}const badAudits = audits.filter(a => (a.W === 390 && a.tapsSmall) || a.wide || a.scrollWidth > a.W || a.inputsSmall);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}`);for (const e of consoleErrors.slice(0, 5)) console.log(' CONSOLE', e);writeFileSync(`${shotDir}/${mode}-audits.json`, J(audits, null, 1));} catch (e) { console.log('E2E ERROR', e.stack || e); process.exitCode = 1; }await send('Emulation.clearDeviceMetricsOverride'); await send('Emulation.setTouchEmulationEnabled', { enabled: false });await send('Page.navigate', { url: 'about:blank' }); await sleep(300);ws.close(); process.exit(process.exitCode || 0);
Branches
Latest commits
- 9d02c540sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
- 22751914sync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre
- c8452453sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
- 52ba11e8sync-components: copy icons/icons.hl + README (F4); testsmre
- 138d198dmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
- 18d2df60md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
- f6764bedreports/H1-hydrate.mdmre
- 1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre
- 6f503cfctests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- e17e2855re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- a6ddccd2re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
- 81e036b7docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
- 5d8d2cf6deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
- 58e8c02cmission 024: report, LOG, STATUS, e2e fixmre
- 50778073tests/e2e-route-marker.mjs: first paint marker, comments post/edit redrawmre
- c5203298mission 024: MainMenu marks the page from the route (layouts 0bcc629 main-menu.hl); browser-side marker removed; gate: marker in the server HTMLmre
- b1a4c270re-vendor Hybriel master f9614007: bin/ (git-ignored) and plugins wholemre
- 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