gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchmainf9b8f918Merge branch 'calendar-vendor-day61' into mainAtlasmain/tests/e2e-theme.mjs

18.0 KB

  1. // tests/e2e-theme.mjs (calendar mission 006): 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 and real typing (Input.insertText). Not a gate: prints numbers, writes screenshots.
  3. // node tests/e2e-theme.mjs <old|new> <port> <sid> <shotDir> <targetId> [cdpPort=$E2E_THEME_CDP_PORT or 8756]
  4. // The app runs on loreana on a COPY of a calendar backup (tests/e2e-start-app.sh), reached from lisbeth's Chrome through `ssh -R`.
  5. // Phase 1 (old and new): the 390 audit of every page (tests/mobile-measure.js) at 390 and 1280: month, the new-event editor, an event's
  6. // editor, the reminder settings, login-failed. Phase 2 (old and new): the walk at 390 and 1280 — next/prev month, open a day, create an
  7. // event with an own reminder, edit it, delete it, the reminder settings (add a row, save), (new only) the user menu and the sidebar.
  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 = process.env.E2E_THEME_CDP_PORT || '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 key = async (k, code, vk) => { await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: k, code, windowsVirtualKeyCode: vk }); await send('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code, windowsVirtualKeyCode: vk }); };
  25. // type into a field with a real click, select-all, then the text (the page sees real input events)
  26. const typeInto = async (sel, text) => { await click(sel); await sleep(100); await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key: 'a', code: 'KeyA', windowsVirtualKeyCode: 65, modifiers: 2, commands: ['selectAll'] }); await send('Input.dispatchKeyEvent', { type: 'keyUp', key: 'a', code: 'KeyA', windowsVirtualKeyCode: 65, modifiers: 2 }); await send('Input.insertText', { text }); await sleep(150); };
  27. const shot = async name => { const r = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(`${shotDir}/${mode}-${name}.png`, Buffer.from(r.data, 'base64')); };
  28. const results = []; const check = (n, ok, d = '') => { results.push([n, !!ok]); console.log((ok ? 'PASS ' : 'FAIL ') + n + (ok ? '' : ' ' + d)); };
  29. const hydrated = () => waitFor(`!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1`, 'hydrated');
  30. 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(900);
  31. // a real pointer move: the month view reads the browser's today/language on the first pointer event (a round trip) — let that settle
  32. await send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: 120, y: 200 }); await sleep(1500); };
  33. const shows = sel => ev(`(() => { const e = document.querySelector(${J(sel)}); return !!e && e.getBoundingClientRect().width > 0; })()`);
  34. const audits = [];
  35. async function audit(name, W) {
  36. const m = await ev(`window.__W = ${W};` + MEASURE);
  37. const r = { name, W, scrollWidth: m.docScrollWidth, taps: m.taps, tapsSmall: m.tapsSmall, small: m.tapsSmallList.slice(0, 6), 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 };
  38. audits.push(r); console.log('AUDIT', J(r)); await shot(`${W}-${name.replace(/[^a-z0-9]+/gi, '-')}`);
  39. }
  40. await send('Page.enable'); await send('Runtime.enable'); await send('DOM.enable'); await send('Network.enable');
  41. await send('Target.activateTarget', { targetId: tid }).catch(() => {});
  42. await send('Page.bringToFront');
  43. await send('Network.setCookie', { name: 'calendarsid', value: sid, url: BASE, httpOnly: true });
  44. await send('Storage.clearDataForOrigin', { origin: BASE, storageTypes: 'service_workers,cache_storage,local_storage' }).catch(() => {});
  45. 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); };
  46. const title = () => ev(`document.querySelector('#month-title').textContent`);
  47. const chips = txt => ev(`[...document.querySelectorAll('#month-days button.event')].filter(b => b.textContent.includes(${J(txt)})).length`);
  48. const openDay = async () => { // a real click on the number of a blank day cell of the shown month (the 20th, not an event chip)
  49. await click(`#month-days li:not(.outside) time[datetime$="-20"]`); await waitFor(`document.querySelector('#eventeditor').classList.contains('open')`, 'editor open'); await sleep(300); };
  50. try {
  51. for (const W of process.env.E2E_SKIP_AUDIT ? [] : [390, 1280]) {
  52. await view(W);
  53. await go('/', '#month-days li'); await audit('month', W);
  54. await openDay(); await audit('event-editor-new', W);
  55. await click('#rem-own'); await click('#rem-add'); await sleep(300); await audit('event-editor-own-reminder', W);
  56. await click('#event-cancel'); await sleep(300);
  57. await click('#settings-open'); await waitFor(`document.querySelector('#settingseditor').matches(':popover-open')`, 'settings open'); await sleep(400); await audit('reminder-settings', W);
  58. await click('#set-cancel'); await sleep(300);
  59. // an existing event: the first chip on the page (the copy holds real events; none in this month → look in the other months)
  60. let found = await ev(`document.querySelectorAll('#month-days button.event').length`);
  61. for (let i = 0; !found && i < 14; i++) { await click('#month-prev'); await sleep(900); found = await ev(`document.querySelectorAll('#month-days button.event').length`); }
  62. if (found) { await shot(`${W}-month-with-events`); await click('#month-days button.event'); await waitFor(`document.querySelector('#eventeditor').classList.contains('open')`, 'edit open'); await sleep(300); await audit('event-editor-edit', W); await click('#event-cancel'); await sleep(300); await audit('month-with-events', W); }
  63. else console.log(' (the copy holds no event within 14 months back)');
  64. await go('/login/failed', '#loginfailed'); await audit('login-failed', W);
  65. }
  66. for (const W of process.env.E2E_SKIP_WALK ? [] : [390, 1280]) {
  67. await view(W); const T = `${W}-`;
  68. await go('/', '#month-days li');
  69. check(`${T}month shown (${J(await title())}), 42 day cells`, (await ev(`document.querySelectorAll('#month-days li').length`)) === 42);
  70. const t0 = await title();
  71. console.log(' before next:', await ev(`JSON.stringify({ p: location.pathname, w: innerWidth, sy: scrollY, hit: (() => { const r = document.querySelector('#month-next').getBoundingClientRect(); const t = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2); return t.tagName + '#' + t.id; })(), rect: document.querySelector('#month-next').getBoundingClientRect() })`));
  72. await click('#month-next'); await waitFor(`document.querySelector('#month-title').textContent !== ${J(t0)}`, 'next month'); const t1 = await title();
  73. check(`${T}next month: ${J(t0)} → ${J(t1)}`, t1 !== t0); await shot(`${T}next-month`);
  74. await click('#month-prev'); await waitFor(`document.querySelector('#month-title').textContent === ${J(t0)}`, 'prev month');
  75. check(`${T}prev month: back to ${J(await title())}`, (await title()) === t0);
  76. // create: open a day by a real click, type a title, an own reminder, save
  77. const name = `A3 ${mode} ${W} event`;
  78. await openDay();
  79. check(`${T}a click on a day opens the editor "New event" (date ${J(await ev(`document.querySelector('#f-startdate').value`))})`, (await ev(`document.querySelector('#formheading').textContent`)) === 'New event'); await shot(`${T}editor-new`);
  80. await typeInto('#f-title', name);
  81. await typeInto('#f-place', 'Lisbon');
  82. await click('#rem-own'); await click('#rem-add'); await sleep(300);
  83. check(`${T}own reminder: one row added (${await ev(`document.querySelectorAll('#rem-rows reminder-row').length`)})`, (await ev(`document.querySelectorAll('#rem-rows reminder-row').length`)) >= 1);
  84. await shot(`${T}editor-filled`);
  85. await click('#event-save'); await waitFor(`document.querySelector('#eventeditor').classList.contains('closed')`, 'editor closed');
  86. check(`${T}create: the event ${J(name)} stands on the day`, await waitFor(`[...document.querySelectorAll('#month-days button.event')].some(b => b.textContent.includes(${J(name.slice(0, 12))}))`, 'chip'));
  87. await shot(`${T}event-created`);
  88. // reload: it is stored (server) and the reminder bar says so
  89. await go('/', '#month-days li');
  90. check(`${T}reload: the event is still there (server)`, (await chips(name.slice(0, 12))) === 1);
  91. // edit: click its chip, change the title
  92. await ev(`(() => { const b = [...document.querySelectorAll('#month-days button.event')].find(b => b.textContent.includes(${J(name.slice(0, 12))})); b.scrollIntoView({ block: 'center' }); })()`);
  93. const chipSel = await ev(`(() => { const b = [...document.querySelectorAll('#month-days button.event')].find(b => b.textContent.includes(${J(name.slice(0, 12))})); b.setAttribute('data-a3', '1'); return 'button[data-a3="1"]'; })()`);
  94. const where = async sel => ev(`(() => { const e = document.querySelector(${J(sel)}); const r = e.getBoundingClientRect(); const t = document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2); return JSON.stringify({ chip: [r.x | 0, r.y | 0, r.width | 0, r.height | 0], sy: scrollY, hit: t.tagName + '.' + t.className + ' ' + (t.textContent || '').slice(0, 20) }); })()`);
  95. console.log(' chip before click:', await where('#month-days ' + chipSel));
  96. await ev(`window.__log = []; const t0 = performance.now(); for (const n of ['pointerover', 'pointerdown', 'mousedown', 'pointerup', 'mouseup', 'click']) document.addEventListener(n, e => window.__log.push([Math.round(performance.now() - t0), n, e.target.tagName + '.' + e.target.className + '#' + e.target.id]), true); new MutationObserver(m => window.__log.push([Math.round(performance.now() - t0), 'mutation', m.length + ' ' + m[0].type + ' ' + (m[0].target.tagName || '') + ' ' + (m[0].attributeName || '')])).observe(document.querySelector('#month-days'), { subtree: true, childList: true, attributes: true, characterData: true });`);
  97. await click('#month-days ' + chipSel); await waitFor(`document.querySelector('#eventeditor').classList.contains('open')`, 'edit open'); await sleep(300);
  98. console.log(' LOG', await ev(`JSON.stringify(window.__log)`));
  99. console.log(' after click: heading', J(await ev(`document.querySelector('#formheading').textContent`)), 'open', await ev(`document.querySelector('#eventeditor').className`), 'chip now', await where('#month-days ' + chipSel).catch(e => 'gone'));
  100. check(`${T}a click on the event opens "Edit event" with its title and the Delete button`, (await ev(`document.querySelector('#formheading').textContent`)) === 'Edit event' && (await ev(`document.querySelector('#f-title').value`)) === name && await shows('#event-delete'));
  101. await shot(`${T}editor-edit`);
  102. const name2 = name + ' (edited)';
  103. await typeInto('#f-title', name2); await click('#event-save'); await waitFor(`document.querySelector('#eventeditor').classList.contains('closed')`, 'closed');
  104. check(`${T}edit: the chip carries the new title`, await waitFor(`[...document.querySelectorAll('#month-days button.event')].some(b => b.textContent.includes('(edited)'))`, 'edited chip'));
  105. // delete (on the copy): click the chip, Delete
  106. await ev(`(() => { const b = [...document.querySelectorAll('#month-days button.event')].find(b => b.textContent.includes(${J(name.slice(0, 12))})); b.setAttribute('data-a3', '2'); })()`);
  107. await click('#month-days button[data-a3="2"]'); await waitFor(`document.querySelector('#eventeditor').classList.contains('open')`, 'edit open 2'); await sleep(300);
  108. check(`${T}the edited title was saved (field shows it)`, (await ev(`document.querySelector('#f-title').value`)) === name2);
  109. await click('#event-delete'); await waitFor(`document.querySelector('#eventeditor').classList.contains('closed')`, 'closed after delete');
  110. check(`${T}delete: the event is gone from the day`, await waitFor(`![...document.querySelectorAll('#month-days button.event')].some(b => b.textContent.includes(${J(name.slice(0, 12))}))`, 'gone'));
  111. await shot(`${T}event-deleted`);
  112. // the reminder settings: open, add a row, save (on the copy)
  113. await click('#settings-open'); await waitFor(`document.querySelector('#settingseditor').matches(':popover-open')`, 'settings open'); await sleep(400);
  114. const rows0 = await ev(`document.querySelectorAll('#set-rows reminder-row').length`);
  115. await click('#set-add'); await sleep(300);
  116. check(`${T}reminder settings: a row added (${rows0} → ${await ev(`document.querySelectorAll('#set-rows reminder-row').length`)})`, (await ev(`document.querySelectorAll('#set-rows reminder-row').length`)) === rows0 + 1); await shot(`${T}settings-open`);
  117. await click('#set-save'); await waitFor(`document.querySelector('#settingseditor').classList.contains('closed')`, 'settings closed');
  118. check(`${T}reminder settings saved, the dialog closed`, (await ev(`document.querySelector('#settingseditor').classList.contains('closed')`)));
  119. // put it back (the settings take at most 8 rows): open again, delete the row just added with its ×, save
  120. await click('#settings-open'); await waitFor(`document.querySelector('#settingseditor').matches(':popover-open')`, 'settings open again'); await sleep(400);
  121. check(`${T}reminder settings reopened: the new row was stored (${rows0 + 1} rows)`, (await ev(`document.querySelectorAll('#set-rows reminder-row').length`)) === rows0 + 1);
  122. await click('#set-rows reminder-row:last-of-type button'); await sleep(300);
  123. await click('#set-save'); await waitFor(`document.querySelector('#settingseditor').classList.contains('closed')`, 'settings closed 2');
  124. check(`${T}reminder settings: the row deleted again and saved (${await ev(`document.querySelector('#settingseditor').className`)})`, (await ev(`document.querySelector('#settingseditor').classList.contains('closed')`)));
  125. // the user menu and the sidebar (theme shell only)
  126. if (mode === 'new') {
  127. check(`${T}the header shows Log out and the ident selector (no user menu)`, await shows('#logout') && await shows('ident-selector')); await shot(`${T}header`);
  128. if (W === 390) {
  129. await click('button.menu-toggle'); await waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, 'sidebar'); await sleep(300);
  130. 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`)) === 1); await shot(`${T}sidebar`);
  131. await key('Escape', 'Escape', 27); await sleep(300);
  132. }
  133. }
  134. }
  135. 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}`);
  136. for (const e of consoleErrors.slice(0, 5)) console.log(' CONSOLE', e);
  137. writeFileSync(`${shotDir}/${mode}-audits.json`, J(audits, null, 1));
  138. } catch (e) { console.log('E2E ERROR', String(e.stack || e).slice(0, 400)); for (const c of consoleErrors.slice(0, 6)) console.log(' CONSOLE', c); process.exitCode = 1; }
  139. await send('Emulation.clearDeviceMetricsOverride'); await send('Emulation.setTouchEmulationEnabled', { enabled: false });
  140. await send('Page.navigate', { url: 'about:blank' }); await sleep(300);
  141. ws.close(); process.exit(process.exitCode || 0);

Branches

Latest commits

  • f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
  • 66341793|||PR Vendor Hybriel day61Atlas
  • 36fc596bMerge branch 'vendor-day59' into mainAtlas
  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas
  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas
  • e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
  • eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
  • cef81394Wait for the DST fixture page instead of an unused socketmre
  • 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
  • 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
  • cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
  • f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
  • edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
  • bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre