gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainf9b8f918Merge branch 'calendar-vendor-day61' into mainAtlasmain/tests/push-shots.mjs

5.2 KB

  1. // tests/push-shots.mjs — the on/off control at 390 and 1280 px in lisbeth's Chrome (same setup as push-real.mjs; taps "Turn off on this device" with a real click)
  2. // (derived from tests/push-real.mjs — calendar#9 part 2, the REAL push service (FCM) and a VISIBLE notification, in lisbeth's LLM Chrome
  3. // (HL_CDP_URL / CDP tunnel -L 9223; ONE tab reused, the calendar page stays open on it; run under `timeout 600 flock -o <lisbeth.lock>`).
  4. // REAL_PORT=8789 REAL_SCRATCH=<dir of tests/push-real-app.mjs> OUT=<evidence dir> node tests/push-real.mjs
  5. // needs: tests/push-real-app.mjs running, and ssh -f -N -R <port>:127.0.0.1:<port> lisbeth (the page is http://localhost:<port> on lisbeth)
  6. // 1 sign in (fresh ident code), grant notifications, first pointer; the page subscribes through FCM 2 an event 2.5 min ahead with a
  7. // reminder 1 min before 3 the page stays on the calendar; at the reminder time read registration.getNotifications() from the page
  8. // and screenshot the page. The app's log shows `push sent (201)` (read from <scratch>/app.log).
  9. import { launchBrowser, Page } from './cdp.mjs';
  10. import { writeFileSync, readFileSync } from 'node:fs';
  11. const PORT = process.env.REAL_PORT, SCR = process.env.REAL_SCRATCH, OUT = process.env.OUT || '.';
  12. const BASE = `http://localhost:${PORT}`;
  13. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  14. const pad = (n) => String(n).padStart(2, '0'); const J = JSON.stringify;
  15. const browser = await launchBrowser();
  16. const { targetInfos } = await browser.conn.send('Target.getTargets');
  17. const t = targetInfos.find(x => x.type === 'page');
  18. const { sessionId } = await browser.conn.send('Target.attachToTarget', { targetId: t.targetId, flatten: true });
  19. const page = new Page(browser, t.targetId, sessionId); await page._init();
  20. const shot = async (n) => { try { await Promise.race([page.send('Page.captureScreenshot', { format: 'png' }).then(({ data }) => writeFileSync(`${OUT}/${n}.png`, Buffer.from(data, 'base64'))), sleep(20000).then(() => { throw new Error('timeout'); })]); console.log('shot', n); } catch (e) { console.log('shot', n, 'FAILED', e.message); } };
  21. const text = () => page.evaluate(`(document.querySelector('#push-state') || {}).textContent || ''`);
  22. const box = (sel) => page.evaluate(`(() => { const e = document.querySelector(${J(sel)}); if (!e || e.classList.contains('hidden')) return null; const r = e.getBoundingClientRect(); return { x: r.x + r.width / 2, y: r.y + r.height / 2, h: r.height, text: e.textContent }; })()`);
  23. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 800, deviceScaleFactor: 2, mobile: true });
  24. await browser.conn.send('Target.activateTarget', { targetId: t.targetId }).catch(() => {});
  25. await page.send('Page.bringToFront').catch(() => {});
  26. await browser.conn.send('Browser.grantPermissions', { origin: BASE, permissions: ['notifications'] }).catch(e => console.log('grant:', e.message));
  27. await page.goto(BASE + '/login/callback?ident_code=' + readFileSync(`${SCR}/code.txt`, 'utf8').trim(), { timeout: 90000 });
  28. await page.waitForSelector('#logout', { timeout: 60000 });
  29. await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 60000, label: 'hydrated' });
  30. await page.waitFor(`navigator.serviceWorker.getRegistration().then(r => !!(r && r.active))`, { label: 'sw', timeout: 60000 }).catch(() => console.log('sw not active yet'));
  31. await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: 200, y: 120 });
  32. console.log('permission', await page.evaluate('Notification.permission'));
  33. const ask = await box('#notify-ask'); console.log('ask button', J(ask));
  34. if (ask) { await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: ask.x, y: ask.y, button: 'left', clickCount: 1 }); await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: ask.x, y: ask.y, button: 'left', clickCount: 1 }); }
  35. let s = ''; for (let i = 0; i < 90 && !/closed/.test(s); i++) { await sleep(1000); s = await text(); }
  36. console.log('push-state:', J(s), '\nconsole:', page.dumpConsole().slice(-800));
  37. console.log('subscription host:', await page.evaluate(`navigator.serviceWorker.getRegistration().then(r => r && r.pushManager.getSubscription()).then(x => x ? new URL(x.endpoint).host : null)`));
  38. const off = await box('#push-off'); console.log('push-off control', J(off));
  39. await shot('real-3-on');
  40. if (!/closed/.test(s)) { console.log('NOT SUBSCRIBED'); process.exit(2); }
  41. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 800, deviceScaleFactor: 1, mobile: false });
  42. await sleep(800); await shot('shot-1280-on');
  43. const o = await box('#push-off');
  44. await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: o.x, y: o.y, button: 'left', clickCount: 1 }); await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: o.x, y: o.y, button: 'left', clickCount: 1 });
  45. await sleep(3000);
  46. console.log('after off: state', J(await text()), 'push-off', J(await box('#push-off')), 'ask', J(await box('#notify-ask')), 'subscription', J(await page.evaluate(`navigator.serviceWorker.getRegistration().then(r => r.pushManager.getSubscription()).then(x => !!x)`)));
  47. await shot('shot-1280-off');
  48. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 800, deviceScaleFactor: 2, mobile: true });
  49. await sleep(800); await shot('shot-390-off');
  50. process.exit(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