calendar
All repositories: gitoria
9.6 KB
// tests/reminders-e2e.mjs — calendar mission 009: the reminders card and the push button in lisbeth's real Chrome, at 390 and 1280 px,// real clicks; run it against the OLD tree and the NEW tree (PREFIX names the shots). ONE tab reused, under `timeout 600 flock -o <lisbeth.lock>`.// REAL_PORT=8793 REAL_SCRATCH=<dir of tests/push-real-app.mjs> OUT=<evidence dir> PREFIX=new node tests/reminders-e2e.mjs// needs: tests/push-real-app.mjs running (outside the lock) and ssh -f -N -R <port>:127.0.0.1:<port> lisbeth// 1 sign in with a fresh ident code, grant notifications, tap "Turn on notifications" (subscribes through FCM) 2 an event 2.5 min ahead,// reminders 1 min before + 1 day before at 20:00, and an all-day event tomorrow with 12 h before 3 shots of the card at 390 and 1280// 4 the planned text; at the reminder time the page's own timer (hl:time in the new code) shows the notification: read it from the// service worker registration; its tag carries the reminder's instant = start − 60 s EXACTLY.import { launchBrowser, Page } from './cdp.mjs';import { writeFileSync, readFileSync } from 'node:fs';const PORT = process.env.REAL_PORT, SCR = process.env.REAL_SCRATCH, OUT = process.env.OUT || '.';const PREFIX = process.env.PREFIX || 'x';const BASE = `http://localhost:${PORT}`;const sleep = (ms) => new Promise(r => setTimeout(r, ms));const pad = (n) => String(n).padStart(2, '0'); const J = JSON.stringify;const browser = await launchBrowser();const { targetInfos } = await browser.conn.send('Target.getTargets');const t = targetInfos.find(x => x.type === 'page');const { sessionId } = await browser.conn.send('Target.attachToTarget', { targetId: t.targetId, flatten: true });const page = new Page(browser, t.targetId, sessionId); await page._init();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); } };const text = () => page.evaluate(`(document.querySelector('#push-state') || {}).textContent || ''`);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 }; })()`);await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 800, deviceScaleFactor: 2, mobile: true });await browser.conn.send('Target.activateTarget', { targetId: t.targetId }).catch(() => {});await page.send('Page.bringToFront').catch(() => {});await browser.conn.send('Browser.grantPermissions', { origin: BASE, permissions: ['notifications'] }).catch(e => console.log('grant:', e.message));await page.goto(BASE + '/login/callback?ident_code=' + readFileSync(`${SCR}/code.txt`, 'utf8').trim(), { timeout: 90000 });await page.waitForSelector('#logout', { timeout: 60000 });await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 60000, label: 'hydrated' });await page.waitFor(`navigator.serviceWorker.getRegistration().then(r => !!(r && r.active))`, { label: 'sw', timeout: 60000 }).catch(() => console.log('sw not active yet'));// a fresh run starts without the subscription an earlier run left (each run's app has its own VAPID pair)await page.evaluate(`navigator.serviceWorker.getRegistration().then(r => r && r.pushManager.getSubscription()).then(x => x && x.unsubscribe())`).catch(() => {});await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: 200, y: 120 });console.log('permission', await page.evaluate('Notification.permission'));const ask = await box('#notify-ask'); console.log('ask button', J(ask));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 }); }let s = ''; for (let i = 0; i < 90 && !/closed/.test(s); i++) { await sleep(1000); s = await text(); }console.log('push-state:', J(s), '\nconsole:', page.dumpConsole().slice(-800));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)`));const off = await box('#push-off'); console.log('push-off control', J(off));await shot(PREFIX + '-390-on');if (!/closed/.test(s)) { console.log('NOT SUBSCRIBED'); process.exit(2); }const now = Date.now(); const start = new Date(Math.ceil((now + 150000) / 60000) * 60000);const zone = await page.evaluate('Intl.DateTimeFormat().resolvedOptions().timeZone');const dateOf = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;const fields = { title: 'Real push', allDay: false, startDate: dateOf(start), startTime: `${pad(start.getHours())}:${pad(start.getMinutes())}`, endDate: '', endTime: '', place: '', notes: '', zone, custom: true, reminders: [{ unit: 'minutes', n: '1', time: '09:00' }, { unit: 'days', n: '1', time: '20:00' }] };const cookie = (await page.cookies([BASE])).map(c => c.name + '=' + c.value).join('; ');const r = await fetch(BASE + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie }, body: J({ t: 'emit', i: 1, event: 'calSave', payload: [fields, dateOf(new Date(now - 259200000)), dateOf(new Date(now + 777600000))] }) });console.log('calSave', r.status);const tomorrow = new Date(now + 86400000);const f2 = { ...fields, title: 'All day tomorrow', allDay: true, startDate: dateOf(tomorrow), startTime: '', reminders: [{ unit: 'hours', n: '12', time: '09:00' }] };const r2 = await fetch(BASE + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie }, body: J({ t: 'emit', i: 2, event: 'calSave', payload: [f2, dateOf(new Date(now - 259200000)), dateOf(new Date(now + 777600000))] }) });console.log('calSave all-day', r2.status);await page.goto(BASE + '/', { timeout: 60000 });await page.waitForSelector('#logout', { timeout: 60000 });await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 60000, label: 'hydrated' });await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: 200, y: 120 });await sleep(2500);console.log('planned text:', J(await page.evaluate(`(document.querySelector('#notify-planned') || {}).textContent`)), 'push-state:', J(await text()));await shot(PREFIX + '-390-card');const sb = await box('#settings-open');await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: sb.x, y: sb.y, button: 'left', clickCount: 1 }); await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: sb.x, y: sb.y, button: 'left', clickCount: 1 });await sleep(1500); await shot(PREFIX + '-390-settings');await page.goto(BASE + '/', { timeout: 60000 });await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 60000, label: 'hydrated' });await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 800, deviceScaleFactor: 1, mobile: false });await sleep(2500); await shot(PREFIX + '-1280-card');const remindAt = start.getTime() - 60000;console.log('reminder at', new Date(remindAt).toTimeString().slice(0, 8), '(the calendar page stays open); expected tag suffix :' + remindAt);await sleep(Math.max(0, remindAt + 20000 - Date.now()));await page.send('Page.bringToFront').catch(() => {});const list = await page.evaluate(`navigator.serviceWorker.getRegistration().then(r => r.getNotifications()).then(l => JSON.stringify(l.map(n => [n.title, n.body, n.tag])))`);console.log('registration.getNotifications():', list);console.log('RESULT tag has exact reminder instant:', list.includes(':' + remindAt) ? 'yes' : 'NO');await shot(PREFIX + '-1280-notified');const click = async (b) => { await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: b.x, y: b.y }); await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: b.x, y: b.y, button: 'left', clickCount: 1 }); await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: b.x, y: b.y, button: 'left', clickCount: 1 }); };const subscribed = () => page.evaluate(`navigator.serviceWorker.getRegistration().then(r => r.pushManager.getSubscription()).then(x => !!x)`);// the push button at 1280, real clicks: off → unsubscribed and "Turn on notifications" offered; on → subscribed againconst o = await box('#push-off'); console.log('1280 push-off', J(o));await click(o); await sleep(3000);const afterOff = { sub: await subscribed(), ask: await box('#notify-ask'), state: await text() };console.log('after Turn off:', J(afterOff));await shot(PREFIX + '-1280-off');console.log('RESULT off ok:', !afterOff.sub && !!afterOff.ask ? 'yes' : 'NO');await click(afterOff.ask); let s2 = ''; for (let i = 0; i < 60 && !/closed/.test(s2); i++) { await sleep(1000); s2 = await text(); }const afterOn = { sub: await subscribed(), off: await box('#push-off'), state: s2 };console.log('after Turn on:', J(afterOn));console.log('RESULT on ok:', afterOn.sub && !!afterOn.off ? 'yes' : 'NO');await shot(PREFIX + '-1280-on-again');await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 800, deviceScaleFactor: 2, mobile: true });await sleep(1000); await shot(PREFIX + '-390-on-again');console.log('RESULT 390 off control height:', J(await box('#push-off')));console.log('app log push lines:', readFileSync(`${SCR}/app.log`, 'utf8').split('\n').filter(l => /push/i.test(l)).join(' | '));process.exit(0);
Branches
Latest commits
- 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
- 5d8579d7README: login.js stays by caramboleyo's explicit rulemre
- cc759328Merge sb3-standby: calendar deploys through its standbymre
- f2fcdc6dcalendar: a standby container (port 45015, profile standby, reminder clock off) and a /health page; deploy hands over through standby-swap.sh without a gapmre