gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain5d144817Merge branch 'records-t40' into mainTicketsmain/tests/e2e-ux-tickets.mjs

15.1 KB

  1. // tests/e2e-ux-tickets.mjs — LISBETH E2E of the UX mission (creator 2026-10-24): the ticket page's ONE composer ("Respond": editor, files,
  2. // `State [select]` + main button) and the ticket list's "New ticket" / "New project" windows, in the creator's real Chrome.
  3. // node tests/e2e-ux-tickets.mjs <base url> <sid> <shot dir> <ticket path e.g. /tickets.worldapi.org/1> [list path, default /]
  4. // BROWSER RULE (caramboleyo 2026-10-23): ONE own tab (Target.createTarget) in the Chrome on lisbeth :9223, closed in finally, then the
  5. // connection is dropped — never Browser.close, no other tab touched, nothing cleared (only my own cookie is set). Run under
  6. // `timeout 600 flock /media/STORAGE/claude-scratch/atlas/lisbeth.lock …`. The app runs on loreana (a COPY of the data) and is reached from
  7. // lisbeth through `ssh -R <port>:127.0.0.1:<port> lisbeth`. Test files on lisbeth: /tmp/atlas-UX-files/{sunset.png,forest.png,notes.txt}.
  8. // Real mouse clicks and keys everywhere (typing, the State select with ArrowDown, Ctrl+A / Backspace, Escape); the chooser's file input is
  9. // filled with DOM.setFileInputFiles (the only way to pick a file without the system dialog).
  10. import { writeFileSync } from 'node:fs';
  11. const [BASE, SID, SHOTS, TICKET, LIST = '/'] = process.argv.slice(2);
  12. const F = '/tmp/atlas-UX-files/';
  13. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  14. const J = JSON.stringify;
  15. let pass = 0, fail = 0;
  16. const check = (label, ok, detail = '') => { console.log((ok ? 'ok ' : 'FAIL ') + label + (ok ? '' : ' — ' + String(detail).slice(0, 400))); if (ok) pass++; else fail++; };
  17. const ver = await (await fetch('http://127.0.0.1:9223/json/version')).json();
  18. const bws = new WebSocket(ver.webSocketDebuggerUrl.replace(/ws:\/\/[^/]+/, 'ws://127.0.0.1:9223'));
  19. await new Promise(r => bws.onopen = r);
  20. let bid = 0; const bpend = new Map();
  21. bws.onmessage = m => { const d = JSON.parse(m.data); if (d.id && bpend.has(d.id)) { bpend.get(d.id)(d); bpend.delete(d.id); } };
  22. const bsend = (method, params = {}) => new Promise((res, rej) => { const i = ++bid; bpend.set(i, d => d.error ? rej(new Error(J(d.error))) : res(d.result)); bws.send(J({ id: i, method, params })); });
  23. const { targetId } = await bsend('Target.createTarget', { url: 'about:blank' });
  24. let ws;
  25. try {
  26. ws = new WebSocket(`ws://127.0.0.1:9223/devtools/page/${targetId}`);
  27. await new Promise(r => ws.onopen = r);
  28. let id = 0; const pend = new Map();
  29. ws.onmessage = m => { const d = JSON.parse(m.data); if (d.id && pend.has(d.id)) { pend.get(d.id)(d); pend.delete(d.id); } };
  30. const send = (method, params = {}) => new Promise((res, rej) => { const i = ++id; pend.set(i, d => d.error ? rej(new Error(method + ': ' + J(d.error))) : res(d.result)); ws.send(J({ id: i, method, params })); });
  31. const ev = async (e) => { const r = await send('Runtime.evaluate', { expression: e, returnByValue: true, awaitPromise: true }); if (r.exceptionDetails) throw new Error(J(r.exceptionDetails).slice(0, 400)); return r.result.value; };
  32. const waitFor = async (e, label, ms = 25000) => { const t = Date.now(); while (Date.now() - t < ms) { try { if (await ev(e)) return true; } catch {} await sleep(150); } console.log(' timeout: ' + label); return false; };
  33. const rect = (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 }; })()`);
  34. const click = async (sel) => { const r = await rect(sel); if (!r) throw new Error('no ' + sel); await sleep(150); const r2 = 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: r2.x, y: r2.y, ...extra }); await sleep(200); };
  35. const key = async (k, code, vk, mod = 0, text) => { await send('Input.dispatchKeyEvent', { type: text ? 'keyDown' : 'rawKeyDown', modifiers: mod, key: k, code, windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk, text }); await send('Input.dispatchKeyEvent', { type: 'keyUp', modifiers: mod, key: k, code, windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk }); };
  36. const typeText = async (t) => { for (const ch of t) await send('Input.dispatchKeyEvent', { type: 'keyDown', text: ch, unmodifiedText: ch, key: ch }).then(() => send('Input.dispatchKeyEvent', { type: 'keyUp', key: ch })); };
  37. const chooseFiles = async (names) => { const { root } = await send('DOM.getDocument'); const { nodeId } = await send('DOM.querySelector', { nodeId: root.nodeId, selector: '#commentform pick-area label.choose input[type=file]' }); await send('DOM.setFileInputFiles', { files: names.map(n => F + n), nodeId }); };
  38. const size = (w) => send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });
  39. const shot = async (name) => { const r = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(`${SHOTS}/${name}.png`, Buffer.from(r.data, 'base64')); console.log(' shot ' + name); };
  40. const open = async (path) => { await send('Page.navigate', { url: BASE + path }); await sleep(700); await waitFor('document.readyState === "complete" && !!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', 'page live', 40000); await sleep(700); };
  41. await send('Page.enable'); await send('Runtime.enable'); await send('DOM.enable'); await send('Network.enable');
  42. await send('Network.setCookie', { name: 'hlsid', value: SID, url: BASE, httpOnly: true });
  43. await send('Page.bringToFront');
  44. const SELS = '#commentform select[name=state]';
  45. const label = () => ev(`document.querySelector('#commentform button.comment-post').textContent.trim()`);
  46. const stateNow = () => ev(`document.querySelector('#state').textContent`);
  47. const chosenText = () => ev(`(() => { const s = document.querySelector(${J(SELS)}); return s.options[s.selectedIndex].textContent.trim(); })()`);
  48. const pickState = async (name) => { await ev(`document.querySelector(${J(SELS)}).focus()`); for (let i = 0; i < 14; i++) { if ((await chosenText()) === name) return true; await key('ArrowDown', 'ArrowDown', 40); await sleep(150); } return false; };
  49. const comments = () => ev(`document.querySelectorAll('#events li.comment').length`);
  50. for (const W of [390, 1280]) {
  51. await size(W);
  52. console.log(`--- ${W} px: ticket ${TICKET}`);
  53. await open(TICKET);
  54. await waitFor(`!!document.querySelector('#commentform form.comment-form md-editor article')`, 'composer');
  55. await sleep(800);
  56. const opts = (await ev(`[...document.querySelectorAll(${J(SELS)} + ' option')].map(o => o.textContent.trim())`));
  57. const start = await stateNow();
  58. check(`${W} the composer has the State select (first "no change", the current state ${start} left out) and the button "Comment"`, opts[0] === 'no change' && !opts.includes(start) && (await label()) === 'Comment', J([opts, start, await label()]));
  59. check(`${W} no separate state form and no second editor on the page`, await ev(`!document.querySelector('#stateform') && document.querySelectorAll('#commentform md-editor').length === 1`));
  60. // 1. the box with two files chosen through its button
  61. await chooseFiles(['sunset.png', 'forest.png']);
  62. await waitFor(`document.querySelectorAll('#commentform li.picked').length === 2 && [...document.querySelectorAll('#commentform img.thumb')].every(i => i.complete && i.naturalWidth > 0)`, 'two thumbs');
  63. await click('#commentform md-editor article');
  64. await typeText('Lisbeth ' + W + ': both, with two files');
  65. const target = ['progress', 'open', 'reopened'].find(x => opts.includes(x));
  66. check(`${W} a real ArrowDown on the State select picks "${target}"`, await pickState(target));
  67. check(`${W} text + state → the button says "Comment and set to ${target}"`, (await label()) === 'Comment and set to ' + target, await label());
  68. const geo = await ev(`(() => { const R = (s) => { const e = document.querySelector(s); if (!e) return null; const b = e.getBoundingClientRect(); return { l: b.left, r: b.right, t: b.top, b: b.bottom }; }; return { box: R('#commentform pick-area'), editor: R('#commentform md-editor'), list: R('#commentform ul.files.picked'), choose: R('#commentform label.choose'), select: R(${J(SELS)}), post: R('#commentform button.comment-post'), side: document.documentElement.scrollWidth, w: innerWidth }; })()`);
  69. check(`${W} one box: the files sit under the editor inside it, the footer under the files, nothing wider than the screen`, geo.list.t >= geo.editor.b - 1 && geo.list.b <= geo.box.b && geo.choose.t >= geo.list.b - 1 && geo.post.t >= geo.list.b - 1 && geo.post.r <= geo.box.r + 1 && geo.post.b <= geo.box.b + 1 && geo.side <= geo.w, J(geo));
  70. if (W >= 1000) check(`${W} footer row: "Choose files" at the left, State + the button at the right end, one row`, geo.choose.l - geo.box.l <= 24 && geo.box.r - geo.post.r <= 24 && geo.select.r < geo.post.l && Math.abs((geo.choose.t + geo.choose.b) / 2 - (geo.post.t + geo.post.b) / 2) <= 8, J(geo));
  71. await shot(`lisbeth-${W}-ticket-composer-both`);
  72. const c0 = await comments();
  73. await click('#commentform button.comment-post');
  74. await waitFor(`document.querySelector('#state').textContent === ${J(target)} && document.querySelectorAll('#events li.comment').length === ${c0 + 1}`, 'both posted');
  75. check(`${W} both → the comment with two thumbnails appears and the state is now ${target}; the box is empty again`, (await stateNow()) === target && (await ev(`[...document.querySelectorAll('#events li.comment')].pop().querySelectorAll('ul.comment-files img').length`)) === 2 && (await ev(`document.querySelectorAll('#commentform li.picked').length === 0`)) && (await chosenText()) === 'no change' && (await label()) === 'Comment');
  76. await ev(`[...document.querySelectorAll('#events li.comment')].pop().scrollIntoView({ block: 'center' })`);
  77. await shot(`lisbeth-${W}-ticket-after-both`);
  78. // 2. comment only
  79. await click('#commentform md-editor article');
  80. await typeText('Lisbeth ' + W + ': just a comment');
  81. check(`${W} text only → "Comment"`, (await label()) === 'Comment', await label());
  82. await click('#commentform button.comment-post');
  83. await waitFor(`document.querySelectorAll('#events li.comment').length === ${c0 + 2}`, 'comment only posted');
  84. check(`${W} comment only → one more comment, the state stays ${target}`, (await comments()) === c0 + 2 && (await stateNow()) === target);
  85. // 3. state only, and the words switch with the text (real Ctrl+A, Backspace)
  86. const opts2 = await ev(`[...document.querySelectorAll(${J(SELS)} + ' option')].map(o => o.textContent.trim())`);
  87. const t2 = opts2.includes('done') ? 'done' : opts2.find(x => x !== 'no change' && x !== 'review' && x !== 'pending');
  88. check(`${W} a real ArrowDown picks "${t2}"`, await pickState(t2));
  89. check(`${W} a state and nothing written → "Set to ${t2}"`, (await label()) === 'Set to ' + t2, await label());
  90. await click('#commentform md-editor article');
  91. await typeText('x');
  92. check(`${W} one letter typed → "Comment and set to ${t2}"`, (await label()) === 'Comment and set to ' + t2, await label());
  93. await key('a', 'KeyA', 65, 2); await key('Backspace', 'Backspace', 8); await sleep(400);
  94. check(`${W} text deleted → "Set to ${t2}" again`, (await label()) === 'Set to ' + t2, await label());
  95. await shot(`lisbeth-${W}-ticket-state-only`);
  96. await click('#commentform button.comment-post');
  97. await waitFor(`document.querySelector('#state').textContent === ${J(t2)}`, 'state only');
  98. check(`${W} state only → the state is ${t2}, no new comment`, (await stateNow()) === t2 && (await comments()) === c0 + 2);
  99. // 4. the list: New ticket / New project windows
  100. console.log(`--- ${W} px: list ${LIST}`);
  101. await open(LIST);
  102. await waitFor(`!!document.querySelector('#newticketbutton')`, 'New ticket button');
  103. const lg = await ev(`(() => { const R = (s) => { const e = document.querySelector(s); if (!e) return null; const b = e.getBoundingClientRect(); const c = getComputedStyle(e); return { l: b.left, r: b.right, t: b.top, b: b.bottom, bg: c.backgroundColor }; }; return { row: R('heading-row'), h1: R('#heading'), nt: R('#newticketbutton'), np: R('#newprojectlink'), fold: !!document.querySelector('#newticket') }; })()`);
  104. check(`${W} list: "New ticket" (accent) and "New project" (quiet) sit in the heading row, at 1280 New ticket at the right end (at 390 they wrap under the heading); no fold-out bar`, !!lg.nt && !!lg.np && lg.nt.bg !== 'rgba(0, 0, 0, 0)' && lg.np.bg === 'rgba(0, 0, 0, 0)' && (W < 1000 || lg.nt.r >= lg.row.r - 2) && !lg.fold && (W < 1000 || (lg.nt.t >= lg.row.t - 1 && lg.nt.b <= lg.row.b + 1 && lg.h1.r <= lg.np.l)), J(lg));
  105. await shot(`lisbeth-${W}-list`);
  106. await click('#newticketbutton');
  107. await waitFor(`!!document.querySelector('dialog#newticketmodal[open]')`, 'new ticket window');
  108. await sleep(400);
  109. const dg = await ev(`(() => { const r = document.querySelector('dialog#newticketmodal').getBoundingClientRect(); return { w: r.width, h: r.height, vw: innerWidth, vh: innerHeight }; })()`);
  110. check(`${W} the New ticket window is ${W < 600 ? 'full screen' : 'a centred window'}`, W < 600 ? dg.w >= dg.vw - 1 && dg.h >= dg.vh - 1 : dg.w < 700 && dg.h < dg.vh, J(dg));
  111. await click('#newsubject');
  112. await typeText('Lisbeth ' + W + ' ticket from the window');
  113. await click('#newsummary md-editor article');
  114. await typeText('written in the window');
  115. await shot(`lisbeth-${W}-list-new-ticket-window`);
  116. await click('#newsubmit');
  117. await waitFor(`!document.querySelector('dialog[open]') && !!document.querySelector('#notice')`, 'window closed after submit');
  118. check(`${W} submit → the window closes, the notice says "Opened …", the new ticket is a row of the list`, /^Opened /.test(await ev(`document.querySelector('#notice').textContent`)) && (await ev(`[...document.querySelectorAll('#tickets li a.subject')].some(a => a.textContent.includes('ticket from the window'))`)), await ev(`document.querySelector('#notice').textContent`));
  119. await click('#newprojectlink');
  120. await waitFor(`!!document.querySelector('dialog#newprojectmodal[open]')`, 'new project window');
  121. await click('#projecttitle');
  122. const suffix = Date.now().toString(36);
  123. await typeText('Lisbeth ' + W + ' project ' + suffix);
  124. await waitFor(`document.querySelector('#projectslug').value === 'lisbeth-${W}-project-${suffix}'`, 'slug');
  125. await shot(`lisbeth-${W}-list-new-project-window`);
  126. await click('#projectcreate');
  127. await waitFor(`!document.querySelector('dialog[open]') && /Created /.test((document.querySelector('#notice') || {}).textContent || '')`, 'project window closed');
  128. check(`${W} New project → the window closes and the notice links its settings`, (await ev(`document.querySelector('#noticelink').getAttribute('href')`)) === `/projects/lisbeth-${W}-project-${suffix}/settings`);
  129. await click('#newticketbutton');
  130. await waitFor(`!!document.querySelector('dialog#newticketmodal[open]')`, 'reopen');
  131. await key('Escape', 'Escape', 27);
  132. await waitFor(`!document.querySelector('dialog[open]')`, 'Esc closes');
  133. check(`${W} Esc closes the window`, await ev(`!document.querySelector('dialog[open]')`));
  134. }
  135. } finally {
  136. try { if (ws) ws.close(); } catch {}
  137. try { await bsend('Target.closeTarget', { targetId }); } catch {}
  138. bws.close();
  139. }
  140. console.log(`lisbeth e2e: ${pass} passed, ${fail} failed`);
  141. process.exit(fail ? 1 : 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