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
- 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