gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit31cabfcc31cabfccmission 021: E2E script, report, LOG, STATUSmre31cabfcc/tests/e2e-editor-look.mjs

6.2 KB

  1. // tests/e2e-editor-look.mjs (mission 021): the Markdown editor's LOOK in a REAL browser (lisbeth's test Chrome over CDP, ONE existing tab reused).
  2. // node tests/e2e-editor-look.mjs <old|new> <port> <sid> <out.json> <shotdir> <targetId>
  3. // App on loreana (a COPY of the data), reached from lisbeth through a reverse ssh forward at 127.0.0.1:<port>. Real mouse click into
  4. // the editor, real Input.insertText, nothing is submitted. Measures the 5 fields at 390 and 1280 px, empty and after one typed letter.
  5. import { writeFileSync } from 'node:fs';
  6. const [mode, port, sid, outFile, shotDir, tid] = process.argv.slice(2);
  7. const BASE = `http://127.0.0.1:${port}`, sleep = ms => new Promise(r => setTimeout(r, ms));
  8. const list = await (await fetch('http://127.0.0.1:9223/json/list')).json();
  9. const tgt = list.find(t => t.id === tid);
  10. const ws = new WebSocket(tgt.webSocketDebuggerUrl); await new Promise(r => ws.onopen = r);
  11. let id = 0; const pend = new Map();
  12. 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(JSON.stringify(d.error))) : ok(d.result); } };
  13. const send = (method, params = {}) => new Promise((ok, bad) => { const i = ++id; pend.set(i, [ok, bad]); ws.send(JSON.stringify({ id: i, method, params })); });
  14. const ev = async x => { const r = await send('Runtime.evaluate', { expression: x, awaitPromise: true, returnByValue: true }); if (r.exceptionDetails) throw new Error(JSON.stringify(r.exceptionDetails).slice(0, 300)); return r.result.value; };
  15. const waitFor = async (x, label, t = 20000) => { for (const end = Date.now() + t; Date.now() < end;) { if (await ev(x).catch(() => false)) return true; await sleep(150); } console.log(' TIMEOUT waiting for', label); return false; };
  16. const rect = sel => ev(`(() => { const e = document.querySelector(${JSON.stringify(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 }; })()`);
  17. const click = async sel => { await rect(sel); await sleep(150); const r = await rect(sel); if (!r) throw new Error('no ' + 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 }); };
  18. const shot = async name => { const r = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(`${shotDir}/${name}.png`, Buffer.from(r.data, 'base64')); };
  19. const MEASURE = sel => `(() => { const m = document.querySelector(${JSON.stringify(sel)}); if (!m) return null; const c = getComputedStyle(m); const art = m.querySelector('article'); const ph = m.querySelector('.placeholder'); const bs = [...m.querySelectorAll('nav button')].filter(x => getComputedStyle(x).display !== 'none').map(x => x.getBoundingClientRect()); const nav = m.querySelector('nav').getBoundingClientRect(); const ar = art.getBoundingClientRect(); const lbl = m.closest('md-field,label'); return { cls: m.className, host_h: +m.getBoundingClientRect().height.toFixed(1), host_w: +m.getBoundingClientRect().width.toFixed(1), border: c.borderTopWidth + ' ' + c.borderTopStyle, pad: c.paddingTop, nav_h: +nav.height.toFixed(1), toolbar_rows: new Set(bs.map(r => Math.round(r.top))).size, buttons: bs.length, min_tap: Math.round(Math.min(...bs.map(r => Math.min(r.width, r.height)))), file_btn: [...m.querySelectorAll('nav button.file')].some(x => getComputedStyle(x).display !== 'none'), article_h: +ar.height.toFixed(1), ph_left: ph && getComputedStyle(ph).display !== 'none' ? +ph.getBoundingClientRect().left.toFixed(1) : null, text_left: +(ar.left + parseFloat(getComputedStyle(art).paddingLeft)).toFixed(1), font: getComputedStyle(art).fontSize, color: getComputedStyle(art).color, docW: document.documentElement.scrollWidth }; })()`;
  20. const FIELDS = [
  21. { name: 'newticket', path: '/project/hycon', sel: '#newticket md-editor', pre: `(document.querySelector('#newticket').open = true)` },
  22. { name: 'comment', path: '/hycon/40', sel: '#commentform md-editor' },
  23. { name: 'statenote', path: '/hycon/40', sel: '#statenote md-editor' },
  24. { name: 'editsummary', path: '/hycon/40', sel: '#editform md-editor', pre: `document.querySelector('#editbutton').click()` },
  25. { name: 'settings', path: '/projects/hycon/settings', sel: '#setdescription md-editor' },
  26. ];
  27. await send('Page.enable'); await send('Runtime.enable'); await send('Network.enable');
  28. await send('Page.bringToFront'); await send('Emulation.setFocusEmulationEnabled', { enabled: true });
  29. await send('Network.setCookie', { name: 'hlsid', value: sid, url: BASE, httpOnly: true });
  30. const out = {};
  31. for (const W of [390, 1280]) {
  32. await send('Emulation.setDeviceMetricsOverride', { width: W, height: W < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: W < 600 });
  33. for (const f of FIELDS) {
  34. const key = `${mode}|${W}|${f.name}`;
  35. await send('Page.navigate', { url: BASE + f.path });
  36. await waitFor(`!!document.querySelector('main') && !!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1`, 'page ' + f.path);
  37. await sleep(1200);
  38. if (f.pre) { await ev(f.pre); await sleep(1200); }
  39. const ok = await waitFor(`!!document.querySelector(${JSON.stringify(f.sel + ' article')}) && document.querySelector(${JSON.stringify(f.sel)}).getBoundingClientRect().width > 0`, f.name);
  40. if (!ok) { out[key] = { error: 'editor not found' }; continue; }
  41. if (f.name !== 'editsummary') await waitFor(`(() => { const m = document.querySelector(${JSON.stringify(f.sel)}); return m.classList.contains('empty') || m.classList.contains('md-empty'); })()`, 'mounted ' + f.name, 8000);
  42. await rect(f.sel); await sleep(300);
  43. const before = await ev(MEASURE(f.sel));
  44. await shot(`${mode}-${W}-${f.name}-empty`);
  45. let after = null;
  46. if (f.name !== 'editsummary') {
  47. await click(f.sel + ' article'); await sleep(300);
  48. await send('Input.insertText', { text: 'x' }); await sleep(400);
  49. after = await ev(MEASURE(f.sel));
  50. await shot(`${mode}-${W}-${f.name}-typed`);
  51. }
  52. out[key] = { before, after, jump: after ? +(after.host_h - before.host_h).toFixed(1) : null };
  53. console.log(key, JSON.stringify(out[key]));
  54. }
  55. }
  56. writeFileSync(outFile, JSON.stringify(out, null, 1));
  57. ws.close();

Branches

Latest commits

  • 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
  • 6309ca81mission brief 014mre