calendar
All repositories: gitoria
15.3 KB
// calendar#29: keyed reminder rows (@id, upsert, one-arg remove) and nested-for day chips (@id).import { spawn } from 'node:child_process';import { mkdirSync, readFileSync, writeFileSync, existsSync } from 'node:fs';import { resolve, join } from 'node:path';import { launchBrowser, sleep } from './cdp.mjs';import { startIdent } from './identkit.mjs';const APP = resolve(process.env.TEST_APP || new URL('..', import.meta.url).pathname);const G = process.env.CALENDAR_29_SCRATCH || join(APP, '.scratch', 'calendar29');const PORT = Number(process.env.CALENDAR_GATE_PORT || 8812);const IDENT_PORT = Number(process.env.CALENDAR_GATE_IDENT_PORT || (PORT + 1));const CHROME_SPEC = (process.env.CALENDAR_GATE_CHROME || '8814-8819').split('-').map(Number);const CHROME_RANGE = [CHROME_SPEC[0], CHROME_SPEC[1] ?? CHROME_SPEC[0]];const BASE = 'http://localhost:' + PORT;const IDENT_DIR = process.env.CALENDAR_GATE_IDENT_DIR || [resolve(APP, '../ident.worldapi.org'), '/media/STORAGE/projects/WorldAPI/ident.worldapi.org'].find(d => existsSync(join(d, 'project.hl')));mkdirSync(G, { recursive: true });let ident, server, browser, page, log = '', passed = 0, failed = 0;function check(name, ok, detail = '') {console.log((ok ? 'ok ' : 'FAIL ') + name + (ok || !detail ? '' : ' — ' + detail));if (ok) passed++;else failed++;}try {// Source checks: keyed reminder rows (upsert + one-arg remove) and nested for over day chips.const source = readFileSync(join(APP, 'components/month-view/month-view.hl'), 'utf8');check('source uses nested for over day chips (no t0..t3/has0..has3/more0..more3/v0..v3)',!source.includes('d.has0') && !source.includes('d.t0') && !source.includes('d.more0') && !source.includes('d.v0') && /for\s*\(\s*c\s+of\s+d\.chips\s*\)/.test(source));check('source keys reminder rows with @id and uses upsert and one-arg remove (no withIndex)',!source.includes('withIndex') && source.includes('.upsert(') && source.includes('.remove(rid)') && source.includes('@id'));ident = await startIdent({ identDir: IDENT_DIR, workDir: join(G, 'ident'), port: IDENT_PORT });const alice = await ident.signIn('[email protected]');const app = await ident.registerApp(alice, 'calendar29', [BASE]);server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], {cwd: APP,env: {...process.env,CALENDAR_PORT: String(PORT),CALENDAR_WATCH: '0',CALENDAR_PUBLIC_URL: BASE,CALENDAR_STORAGE: join(G, 'db'),CALENDAR_SESSIONS: join(G, 'sessions') + '/',IDENT_URL: ident.base,IDENT_EXCHANGE_URL: ident.base,IDENT_API_KEY: app.key,IDENT_API_SECRET: app.secret,},stdio: ['ignore', 'pipe', 'pipe'],});server.stdout.on('data', x => { log += x; });server.stderr.on('data', x => { log += x; });for (let i = 0; ; i++) {try { if ((await fetch(BASE)).ok) break; } catch {}if (i > 600) throw Error('boot timeout: ' + log);await sleep(250);}browser = await launchBrowser({ debugPortRange: CHROME_RANGE });page = await browser.newPage();const code = await ident.selectorCode(alice, app, BASE);await page.goto(BASE + '/login/callback?ident_code=' + code, { timeout: 120000 });await page.waitFor('!!window.__hl?.socket && window.__hl.socket.readyState === 1', { timeout: 120000 });await page.click('#month-title');await sleep(400);// 1. Reminder rows in event editor: editing one row keeps other rows' DOM nodes and focus;// deleting an earlier row keeps surviving rows' DOM nodes and focus.const targetDate = await page.evaluate('document.querySelector("#month-days li:nth-child(18) time").dateTime');await page.click('#month-days li:nth-child(18) time');await page.waitFor('!!document.querySelector("#eventeditor")');await page.click('#rem-own');await page.waitFor('document.querySelectorAll("#rem-rows reminder-row").length === 2');await page.click('#rem-add');await page.waitFor('document.querySelectorAll("#rem-rows reminder-row").length === 3');await page.evaluate(`(() => {const rows = [...document.querySelectorAll('#rem-rows reminder-row')];window.__remRow0 = rows[0];window.__remRow1 = rows[1];window.__remRow2 = rows[2];window.__remTime1 = rows[1].querySelector('input[type=time]');window.__remTime1.focus();})()`);// Edit row 0's number while row 1's time input is focused.await page.evaluate(`(() => {const n = document.querySelector('#rem-rows reminder-row:nth-child(1) input[type=number]');n.value = '3';n.dispatchEvent(new Event('change', { bubbles: true }));})()`);await sleep(300);const afterEditOther = await page.evaluate(`(() => {const rows = [...document.querySelectorAll('#rem-rows reminder-row')];return {same0: rows[0] === window.__remRow0,same1: rows[1] === window.__remRow1,same2: rows[2] === window.__remRow2,focusKept: document.activeElement === window.__remTime1 && window.__remTime1.isConnected,val0: rows[0].querySelector('input[type=number]').value,};})()`);check('remRows: editing row 0 keeps all row DOM nodes and focus on row 1',afterEditOther.same0 && afterEditOther.same1 && afterEditOther.same2 && afterEditOther.focusKept && afterEditOther.val0 === '3',JSON.stringify(afterEditOther));// Edit row 1's own time while focused.await page.evaluate(`(() => {const t = window.__remTime1;t.value = '18:30';t.dispatchEvent(new Event('change', { bubbles: true }));})()`);await sleep(300);const afterEditSelf = await page.evaluate(`(() => {const rows = [...document.querySelectorAll('#rem-rows reminder-row')];return {same1: rows[1] === window.__remRow1,sameTimeInput: rows[1].querySelector('input[type=time]') === window.__remTime1,focusKept: document.activeElement === window.__remTime1,val1: rows[1].querySelector('input[type=time]').value,};})()`);check('remRows: editing row 1 time keeps its input node and focus',afterEditSelf.same1 && afterEditSelf.sameTimeInput && afterEditSelf.focusKept && afterEditSelf.val1 === '18:30',JSON.stringify(afterEditSelf));// Delete row 0 by clicking its × button -> surviving rows keep their exact DOM nodes.await page.click('#rem-rows reminder-row:nth-child(1) button');await page.waitFor('document.querySelectorAll("#rem-rows reminder-row").length === 2');const afterDel = await page.evaluate(`(() => {const rows = [...document.querySelectorAll('#rem-rows reminder-row')];return {kept1: rows[0] === window.__remRow1 && window.__remRow1.isConnected,kept2: rows[1] === window.__remRow2 && window.__remRow2.isConnected,n0: rows[0].querySelector('input[type=number]').value,t0: rows[0].querySelector('input[type=time]').value,n1: rows[1].querySelector('input[type=number]').value,};})()`);check('remRows: deleting row 0 keeps surviving row DOM nodes',afterDel.kept1 && afterDel.kept2 && afterDel.n0 === '1' && afterDel.t0 === '18:30' && afterDel.n1 === '10',JSON.stringify(afterDel));// Save this event ("18:00 Evening") and verify its chip + saved custom reminders.await page.type('#f-title', 'Evening');await page.evaluate(`(() => {const s = document.querySelector('#f-starttime'); s.value = '18:00'; s.dispatchEvent(new Event('input', { bubbles: true }));const e = document.querySelector('#f-endtime'); e.value = '19:00'; e.dispatchEvent(new Event('input', { bubbles: true }));})()`);await page.click('#event-save');await page.waitFor('!document.querySelector("#eventeditor")');await page.waitFor('document.querySelectorAll("#month-days li:nth-child(18) button.event").length === 1');// 2. Day chips: adding an earlier event on the same day keeps the existing chip's DOM node intact.await page.evaluate(`(() => {window.__eveningChip = document.querySelector('#month-days li:nth-child(18) button.event');window.__dayLi = document.querySelector('#month-days li:nth-child(18)');})()`);await page.click('#month-days li:nth-child(18) time');await page.waitFor('!!document.querySelector("#eventeditor")');await page.type('#f-title', 'Morning');await page.evaluate(`(() => {const s = document.querySelector('#f-starttime'); s.value = '08:00'; s.dispatchEvent(new Event('input', { bubbles: true }));const e = document.querySelector('#f-endtime'); e.value = '09:00'; e.dispatchEvent(new Event('input', { bubbles: true }));})()`);await page.click('#event-save');await page.waitFor('!document.querySelector("#eventeditor")');await page.waitFor('document.querySelectorAll("#month-days li:nth-child(18) button.event").length === 2');const chipsAfterInsert = await page.evaluate(`(() => {const li = document.querySelector('#month-days li:nth-child(18)');const btns = [...li.querySelectorAll('button.event')];return {sameLi: li === window.__dayLi,texts: btns.map(b => b.textContent),eveningKept: btns[1] === window.__eveningChip && window.__eveningChip.textContent === '18:00 Evening',};})()`);check('day chips: inserting an earlier event keeps existing chip DOM node and order',chipsAfterInsert.sameLi && chipsAfterInsert.eveningKept && JSON.stringify(chipsAfterInsert.texts) === '["08:00 Morning","18:00 Evening"]',JSON.stringify(chipsAfterInsert));// Add 3 more events on the same day -> 3 event chips + 1 "+2 more" overflow chip; Evening chip stays intact; clicking "+2 more" opens New event.const cookie = (await page.cookies([BASE])).map(c => c.name + '=' + c.value).join('; ');const dates = await page.evaluate('[...document.querySelectorAll("#month-days time")].map(t => t.dateTime)');for (const [title, startTime] of [['Noon', '12:00'], ['Afternoon', '15:00'], ['Night', '21:00']]) {const f = { id: '', title, allDay: false, startDate: targetDate, startTime, endDate: '', endTime: '', place: '', notes: '', zone: 'UTC', custom: false, reminders: [] };await fetch(BASE + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', cookie }, body: JSON.stringify({ t: 'emit', i: 1, event: 'calSave', payload: [f, dates[0], dates[41]] }) });}await page.click('#month-next');await page.waitFor(`document.querySelector("#month-days time").dateTime !== ${JSON.stringify(dates[0])}`);await page.click('#month-prev');await page.waitFor(`document.querySelector("#month-days time").dateTime === ${JSON.stringify(dates[0])}`);await page.waitFor('document.querySelectorAll("#month-days li:nth-child(18) button.more").length === 1');const overflowTexts = await page.evaluate('[...document.querySelectorAll("#month-days li:nth-child(18) day-events button")].map(b => b.className + ":" + b.textContent)');check('day chips: 5 events render 3 event chips and "+2 more" overflow chip after paging',overflowTexts.length === 4 && overflowTexts[0].endsWith('08:00 Morning') && overflowTexts[1].endsWith('12:00 Noon') && overflowTexts[2].endsWith('15:00 Afternoon') && overflowTexts[3].includes('more:+2 more'),JSON.stringify(overflowTexts));// Click an event chip -> opens its Edit event form with the saved custom reminders intact.await page.click('#month-days li:nth-child(18) button.more');await page.waitFor('!!document.querySelector("#eventeditor")');check('overflow chip opens New event on that date',await page.evaluate(`document.querySelector('#formheading').textContent === 'New event' && document.querySelector('#f-startdate').value === ${JSON.stringify(targetDate)}`));await page.click('#event-cancel');await page.waitFor('!document.querySelector("#eventeditor")');// Verify saved custom reminders survive reload and reopen.await page.goto(BASE + '/', { timeout: 120000 });await page.waitFor('!!window.__hl?.socket && window.__hl.socket.readyState === 1', { timeout: 120000 });await page.click('#month-title');await page.waitFor('document.querySelectorAll("#month-days li:nth-child(18) button.event").length === 3');await page.evaluate(`(() => {const btns = [...document.querySelectorAll('#month-days li:nth-child(18) button.event')];window.__morningAfterReload = btns[0];window.__noonAfterReload = btns[1];window.__afternoonAfterReload = btns[2];})()`);await page.click('#month-days li:nth-child(18) button.event:nth-child(2)');await page.waitFor('!!document.querySelector("#eventeditor")');check('editing 12:00 Noon chip opens Noon', await page.evaluate('document.querySelector("#f-title").value === "Noon"'));await page.type('#f-title', ' updated');await page.click('#event-save');await page.waitFor('!document.querySelector("#eventeditor")');await page.waitFor('document.querySelector("#month-days li:nth-child(18) button.event:nth-child(2)").textContent.includes("Noon updated")');const afterRename = await page.evaluate(`(() => {const btns = [...document.querySelectorAll('#month-days li:nth-child(18) button.event')];return {kept0: btns[0] === window.__morningAfterReload,kept1: btns[1] === window.__noonAfterReload,kept2: btns[2] === window.__afternoonAfterReload,};})()`);check('day chips: editing one event keeps all chip DOM nodes on the day',afterRename.kept0 && afterRename.kept1 && afterRename.kept2,JSON.stringify(afterRename));// 3. Settings rows (#set-rows): same keyed behaviour (delete keeps surviving node; edit keeps other row node and focus).await page.click('#settings-open');await page.waitFor('document.querySelector("#settingseditor").matches(":popover-open") && document.querySelectorAll("#set-rows reminder-row").length === 2');await sleep(300);await page.evaluate(`(() => {const rows = [...document.querySelectorAll('#set-rows reminder-row')];window.__setRow0 = rows[0];window.__setRow1 = rows[1];window.__setTime1 = rows[1].querySelector('input[type=time]');window.__setTime1.focus();})()`);await page.evaluate(`(() => {const n = document.querySelector('#set-rows reminder-row:nth-child(1) input[type=number]');n.value = '4';n.dispatchEvent(new Event('change', { bubbles: true }));})()`);await sleep(300);const setAfterEdit = await page.evaluate(`(() => {const rows = [...document.querySelectorAll('#set-rows reminder-row')];return {same0: rows[0] === window.__setRow0,same1: rows[1] === window.__setRow1,focusKept: document.activeElement === window.__setTime1 && window.__setTime1.isConnected,};})()`);check('setRows: editing row 0 keeps row DOM nodes and focus on row 1', setAfterEdit.same0 && setAfterEdit.same1 && setAfterEdit.focusKept, JSON.stringify(setAfterEdit));await page.click('#set-rows reminder-row:nth-child(1) button');await page.waitFor('document.querySelectorAll("#set-rows reminder-row").length === 1');const setAfterDel = await page.evaluate(`(() => {const rows = [...document.querySelectorAll('#set-rows reminder-row')];return {kept1: rows[0] === window.__setRow1 && window.__setRow1.isConnected,};})()`);check('setRows: deleting row 0 keeps surviving row DOM node', setAfterDel.kept1, JSON.stringify(setAfterDel));await page.click('#set-cancel');await page.waitFor('!document.querySelector("#settingseditor").matches(":popover-open")');check('no browser console errors', page.problems().filter(x => !/favicon|Failed to load resource/.test(x.text)).length === 0, JSON.stringify(page.problems()));} catch (e) {check(e.stack || String(e), false);} finally {if (page) await page.close().catch(() => {});if (browser) await browser.close().catch(() => {});if (server) {server.kill('SIGTERM');await new Promise(r => { if (server.exitCode !== null) return r(); server.once('exit', r); setTimeout(r, 5000); });}if (ident) await ident.stop().catch(() => {});writeFileSync(join(G, 'server.log'), log);}console.log(`${passed} passed, ${failed} failed`);process.exitCode = failed ? 1 : 0;
Branches
Latest commits
- c0830967|||PR calendar#29: key reminder rows and day chips with @id and nested forAtlas
- 3e5cfd59Merge branch 'calendar28-fix' into mainAtlas
- 692346ed|||PR calendar28: handle an already-subscribed notification device in push checksAtlas
- bc2d7776|||PR WIP calendar28: preserve toggle focus and chip specificityAtlas
- 189c4c8c|||PR WIP calendar28: replace visual class state with View conditionsAtlas
- fff2f537Merge branch 'calendar31-lib' into mainAtlas
- 07cde3dc|||PR keep worker records out of the repo; README vendor is day72Atlas
- a753b0ab|||PR move shared calendar logic to libAtlas
- b32a921dMerge branch 'vendor-day72' into mainAtlas
- 60a0dd19|||PR Hybriel day72 (00c9dbb8) instead of the withdrawn day73Atlas
- 53f5464dMerge branch 'calendar26-day73' into mainAtlas
- 338499ec|||PR Keep reminder settings open during editing and rejected savesAtlas
- ad9e8d59|||PR Use framework page and popover state, Hybriel day73Atlas
- cab224a1Re-vendor calendar to verified Hybriel day73Atlas
- 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