gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitc0830967c0830967|||PR calendar#29: key reminder rows and day chips with @id and nested forAtlasc0830967/tests/calendar29.mjs

15.3 KB

  1. // calendar#29: keyed reminder rows (@id, upsert, one-arg remove) and nested-for day chips (@id).
  2. import { spawn } from 'node:child_process';
  3. import { mkdirSync, readFileSync, writeFileSync, existsSync } from 'node:fs';
  4. import { resolve, join } from 'node:path';
  5. import { launchBrowser, sleep } from './cdp.mjs';
  6. import { startIdent } from './identkit.mjs';
  7. const APP = resolve(process.env.TEST_APP || new URL('..', import.meta.url).pathname);
  8. const G = process.env.CALENDAR_29_SCRATCH || join(APP, '.scratch', 'calendar29');
  9. const PORT = Number(process.env.CALENDAR_GATE_PORT || 8812);
  10. const IDENT_PORT = Number(process.env.CALENDAR_GATE_IDENT_PORT || (PORT + 1));
  11. const CHROME_SPEC = (process.env.CALENDAR_GATE_CHROME || '8814-8819').split('-').map(Number);
  12. const CHROME_RANGE = [CHROME_SPEC[0], CHROME_SPEC[1] ?? CHROME_SPEC[0]];
  13. const BASE = 'http://localhost:' + PORT;
  14. 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')));
  15. mkdirSync(G, { recursive: true });
  16. let ident, server, browser, page, log = '', passed = 0, failed = 0;
  17. function check(name, ok, detail = '') {
  18. console.log((ok ? 'ok ' : 'FAIL ') + name + (ok || !detail ? '' : ' — ' + detail));
  19. if (ok) passed++;
  20. else failed++;
  21. }
  22. try {
  23. // Source checks: keyed reminder rows (upsert + one-arg remove) and nested for over day chips.
  24. const source = readFileSync(join(APP, 'components/month-view/month-view.hl'), 'utf8');
  25. check('source uses nested for over day chips (no t0..t3/has0..has3/more0..more3/v0..v3)',
  26. !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));
  27. check('source keys reminder rows with @id and uses upsert and one-arg remove (no withIndex)',
  28. !source.includes('withIndex') && source.includes('.upsert(') && source.includes('.remove(rid)') && source.includes('@id'));
  29. ident = await startIdent({ identDir: IDENT_DIR, workDir: join(G, 'ident'), port: IDENT_PORT });
  30. const alice = await ident.signIn('[email protected]');
  31. const app = await ident.registerApp(alice, 'calendar29', [BASE]);
  32. server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], {
  33. cwd: APP,
  34. env: {
  35. ...process.env,
  36. CALENDAR_PORT: String(PORT),
  37. CALENDAR_WATCH: '0',
  38. CALENDAR_PUBLIC_URL: BASE,
  39. CALENDAR_STORAGE: join(G, 'db'),
  40. CALENDAR_SESSIONS: join(G, 'sessions') + '/',
  41. IDENT_URL: ident.base,
  42. IDENT_EXCHANGE_URL: ident.base,
  43. IDENT_API_KEY: app.key,
  44. IDENT_API_SECRET: app.secret,
  45. },
  46. stdio: ['ignore', 'pipe', 'pipe'],
  47. });
  48. server.stdout.on('data', x => { log += x; });
  49. server.stderr.on('data', x => { log += x; });
  50. for (let i = 0; ; i++) {
  51. try { if ((await fetch(BASE)).ok) break; } catch {}
  52. if (i > 600) throw Error('boot timeout: ' + log);
  53. await sleep(250);
  54. }
  55. browser = await launchBrowser({ debugPortRange: CHROME_RANGE });
  56. page = await browser.newPage();
  57. const code = await ident.selectorCode(alice, app, BASE);
  58. await page.goto(BASE + '/login/callback?ident_code=' + code, { timeout: 120000 });
  59. await page.waitFor('!!window.__hl?.socket && window.__hl.socket.readyState === 1', { timeout: 120000 });
  60. await page.click('#month-title');
  61. await sleep(400);
  62. // 1. Reminder rows in event editor: editing one row keeps other rows' DOM nodes and focus;
  63. // deleting an earlier row keeps surviving rows' DOM nodes and focus.
  64. const targetDate = await page.evaluate('document.querySelector("#month-days li:nth-child(18) time").dateTime');
  65. await page.click('#month-days li:nth-child(18) time');
  66. await page.waitFor('!!document.querySelector("#eventeditor")');
  67. await page.click('#rem-own');
  68. await page.waitFor('document.querySelectorAll("#rem-rows reminder-row").length === 2');
  69. await page.click('#rem-add');
  70. await page.waitFor('document.querySelectorAll("#rem-rows reminder-row").length === 3');
  71. await page.evaluate(`(() => {
  72. const rows = [...document.querySelectorAll('#rem-rows reminder-row')];
  73. window.__remRow0 = rows[0];
  74. window.__remRow1 = rows[1];
  75. window.__remRow2 = rows[2];
  76. window.__remTime1 = rows[1].querySelector('input[type=time]');
  77. window.__remTime1.focus();
  78. })()`);
  79. // Edit row 0's number while row 1's time input is focused.
  80. await page.evaluate(`(() => {
  81. const n = document.querySelector('#rem-rows reminder-row:nth-child(1) input[type=number]');
  82. n.value = '3';
  83. n.dispatchEvent(new Event('change', { bubbles: true }));
  84. })()`);
  85. await sleep(300);
  86. const afterEditOther = await page.evaluate(`(() => {
  87. const rows = [...document.querySelectorAll('#rem-rows reminder-row')];
  88. return {
  89. same0: rows[0] === window.__remRow0,
  90. same1: rows[1] === window.__remRow1,
  91. same2: rows[2] === window.__remRow2,
  92. focusKept: document.activeElement === window.__remTime1 && window.__remTime1.isConnected,
  93. val0: rows[0].querySelector('input[type=number]').value,
  94. };
  95. })()`);
  96. check('remRows: editing row 0 keeps all row DOM nodes and focus on row 1',
  97. afterEditOther.same0 && afterEditOther.same1 && afterEditOther.same2 && afterEditOther.focusKept && afterEditOther.val0 === '3',
  98. JSON.stringify(afterEditOther));
  99. // Edit row 1's own time while focused.
  100. await page.evaluate(`(() => {
  101. const t = window.__remTime1;
  102. t.value = '18:30';
  103. t.dispatchEvent(new Event('change', { bubbles: true }));
  104. })()`);
  105. await sleep(300);
  106. const afterEditSelf = await page.evaluate(`(() => {
  107. const rows = [...document.querySelectorAll('#rem-rows reminder-row')];
  108. return {
  109. same1: rows[1] === window.__remRow1,
  110. sameTimeInput: rows[1].querySelector('input[type=time]') === window.__remTime1,
  111. focusKept: document.activeElement === window.__remTime1,
  112. val1: rows[1].querySelector('input[type=time]').value,
  113. };
  114. })()`);
  115. check('remRows: editing row 1 time keeps its input node and focus',
  116. afterEditSelf.same1 && afterEditSelf.sameTimeInput && afterEditSelf.focusKept && afterEditSelf.val1 === '18:30',
  117. JSON.stringify(afterEditSelf));
  118. // Delete row 0 by clicking its × button -> surviving rows keep their exact DOM nodes.
  119. await page.click('#rem-rows reminder-row:nth-child(1) button');
  120. await page.waitFor('document.querySelectorAll("#rem-rows reminder-row").length === 2');
  121. const afterDel = await page.evaluate(`(() => {
  122. const rows = [...document.querySelectorAll('#rem-rows reminder-row')];
  123. return {
  124. kept1: rows[0] === window.__remRow1 && window.__remRow1.isConnected,
  125. kept2: rows[1] === window.__remRow2 && window.__remRow2.isConnected,
  126. n0: rows[0].querySelector('input[type=number]').value,
  127. t0: rows[0].querySelector('input[type=time]').value,
  128. n1: rows[1].querySelector('input[type=number]').value,
  129. };
  130. })()`);
  131. check('remRows: deleting row 0 keeps surviving row DOM nodes',
  132. afterDel.kept1 && afterDel.kept2 && afterDel.n0 === '1' && afterDel.t0 === '18:30' && afterDel.n1 === '10',
  133. JSON.stringify(afterDel));
  134. // Save this event ("18:00 Evening") and verify its chip + saved custom reminders.
  135. await page.type('#f-title', 'Evening');
  136. await page.evaluate(`(() => {
  137. const s = document.querySelector('#f-starttime'); s.value = '18:00'; s.dispatchEvent(new Event('input', { bubbles: true }));
  138. const e = document.querySelector('#f-endtime'); e.value = '19:00'; e.dispatchEvent(new Event('input', { bubbles: true }));
  139. })()`);
  140. await page.click('#event-save');
  141. await page.waitFor('!document.querySelector("#eventeditor")');
  142. await page.waitFor('document.querySelectorAll("#month-days li:nth-child(18) button.event").length === 1');
  143. // 2. Day chips: adding an earlier event on the same day keeps the existing chip's DOM node intact.
  144. await page.evaluate(`(() => {
  145. window.__eveningChip = document.querySelector('#month-days li:nth-child(18) button.event');
  146. window.__dayLi = document.querySelector('#month-days li:nth-child(18)');
  147. })()`);
  148. await page.click('#month-days li:nth-child(18) time');
  149. await page.waitFor('!!document.querySelector("#eventeditor")');
  150. await page.type('#f-title', 'Morning');
  151. await page.evaluate(`(() => {
  152. const s = document.querySelector('#f-starttime'); s.value = '08:00'; s.dispatchEvent(new Event('input', { bubbles: true }));
  153. const e = document.querySelector('#f-endtime'); e.value = '09:00'; e.dispatchEvent(new Event('input', { bubbles: true }));
  154. })()`);
  155. await page.click('#event-save');
  156. await page.waitFor('!document.querySelector("#eventeditor")');
  157. await page.waitFor('document.querySelectorAll("#month-days li:nth-child(18) button.event").length === 2');
  158. const chipsAfterInsert = await page.evaluate(`(() => {
  159. const li = document.querySelector('#month-days li:nth-child(18)');
  160. const btns = [...li.querySelectorAll('button.event')];
  161. return {
  162. sameLi: li === window.__dayLi,
  163. texts: btns.map(b => b.textContent),
  164. eveningKept: btns[1] === window.__eveningChip && window.__eveningChip.textContent === '18:00 Evening',
  165. };
  166. })()`);
  167. check('day chips: inserting an earlier event keeps existing chip DOM node and order',
  168. chipsAfterInsert.sameLi && chipsAfterInsert.eveningKept && JSON.stringify(chipsAfterInsert.texts) === '["08:00 Morning","18:00 Evening"]',
  169. JSON.stringify(chipsAfterInsert));
  170. // 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.
  171. const cookie = (await page.cookies([BASE])).map(c => c.name + '=' + c.value).join('; ');
  172. const dates = await page.evaluate('[...document.querySelectorAll("#month-days time")].map(t => t.dateTime)');
  173. for (const [title, startTime] of [['Noon', '12:00'], ['Afternoon', '15:00'], ['Night', '21:00']]) {
  174. const f = { id: '', title, allDay: false, startDate: targetDate, startTime, endDate: '', endTime: '', place: '', notes: '', zone: 'UTC', custom: false, reminders: [] };
  175. 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]] }) });
  176. }
  177. await page.click('#month-next');
  178. await page.waitFor(`document.querySelector("#month-days time").dateTime !== ${JSON.stringify(dates[0])}`);
  179. await page.click('#month-prev');
  180. await page.waitFor(`document.querySelector("#month-days time").dateTime === ${JSON.stringify(dates[0])}`);
  181. await page.waitFor('document.querySelectorAll("#month-days li:nth-child(18) button.more").length === 1');
  182. const overflowTexts = await page.evaluate('[...document.querySelectorAll("#month-days li:nth-child(18) day-events button")].map(b => b.className + ":" + b.textContent)');
  183. check('day chips: 5 events render 3 event chips and "+2 more" overflow chip after paging',
  184. 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'),
  185. JSON.stringify(overflowTexts));
  186. // Click an event chip -> opens its Edit event form with the saved custom reminders intact.
  187. await page.click('#month-days li:nth-child(18) button.more');
  188. await page.waitFor('!!document.querySelector("#eventeditor")');
  189. check('overflow chip opens New event on that date',
  190. await page.evaluate(`document.querySelector('#formheading').textContent === 'New event' && document.querySelector('#f-startdate').value === ${JSON.stringify(targetDate)}`));
  191. await page.click('#event-cancel');
  192. await page.waitFor('!document.querySelector("#eventeditor")');
  193. // Verify saved custom reminders survive reload and reopen.
  194. await page.goto(BASE + '/', { timeout: 120000 });
  195. await page.waitFor('!!window.__hl?.socket && window.__hl.socket.readyState === 1', { timeout: 120000 });
  196. await page.click('#month-title');
  197. await page.waitFor('document.querySelectorAll("#month-days li:nth-child(18) button.event").length === 3');
  198. await page.evaluate(`(() => {
  199. const btns = [...document.querySelectorAll('#month-days li:nth-child(18) button.event')];
  200. window.__morningAfterReload = btns[0];
  201. window.__noonAfterReload = btns[1];
  202. window.__afternoonAfterReload = btns[2];
  203. })()`);
  204. await page.click('#month-days li:nth-child(18) button.event:nth-child(2)');
  205. await page.waitFor('!!document.querySelector("#eventeditor")');
  206. check('editing 12:00 Noon chip opens Noon', await page.evaluate('document.querySelector("#f-title").value === "Noon"'));
  207. await page.type('#f-title', ' updated');
  208. await page.click('#event-save');
  209. await page.waitFor('!document.querySelector("#eventeditor")');
  210. await page.waitFor('document.querySelector("#month-days li:nth-child(18) button.event:nth-child(2)").textContent.includes("Noon updated")');
  211. const afterRename = await page.evaluate(`(() => {
  212. const btns = [...document.querySelectorAll('#month-days li:nth-child(18) button.event')];
  213. return {
  214. kept0: btns[0] === window.__morningAfterReload,
  215. kept1: btns[1] === window.__noonAfterReload,
  216. kept2: btns[2] === window.__afternoonAfterReload,
  217. };
  218. })()`);
  219. check('day chips: editing one event keeps all chip DOM nodes on the day',
  220. afterRename.kept0 && afterRename.kept1 && afterRename.kept2,
  221. JSON.stringify(afterRename));
  222. // 3. Settings rows (#set-rows): same keyed behaviour (delete keeps surviving node; edit keeps other row node and focus).
  223. await page.click('#settings-open');
  224. await page.waitFor('document.querySelector("#settingseditor").matches(":popover-open") && document.querySelectorAll("#set-rows reminder-row").length === 2');
  225. await sleep(300);
  226. await page.evaluate(`(() => {
  227. const rows = [...document.querySelectorAll('#set-rows reminder-row')];
  228. window.__setRow0 = rows[0];
  229. window.__setRow1 = rows[1];
  230. window.__setTime1 = rows[1].querySelector('input[type=time]');
  231. window.__setTime1.focus();
  232. })()`);
  233. await page.evaluate(`(() => {
  234. const n = document.querySelector('#set-rows reminder-row:nth-child(1) input[type=number]');
  235. n.value = '4';
  236. n.dispatchEvent(new Event('change', { bubbles: true }));
  237. })()`);
  238. await sleep(300);
  239. const setAfterEdit = await page.evaluate(`(() => {
  240. const rows = [...document.querySelectorAll('#set-rows reminder-row')];
  241. return {
  242. same0: rows[0] === window.__setRow0,
  243. same1: rows[1] === window.__setRow1,
  244. focusKept: document.activeElement === window.__setTime1 && window.__setTime1.isConnected,
  245. };
  246. })()`);
  247. check('setRows: editing row 0 keeps row DOM nodes and focus on row 1', setAfterEdit.same0 && setAfterEdit.same1 && setAfterEdit.focusKept, JSON.stringify(setAfterEdit));
  248. await page.click('#set-rows reminder-row:nth-child(1) button');
  249. await page.waitFor('document.querySelectorAll("#set-rows reminder-row").length === 1');
  250. const setAfterDel = await page.evaluate(`(() => {
  251. const rows = [...document.querySelectorAll('#set-rows reminder-row')];
  252. return {
  253. kept1: rows[0] === window.__setRow1 && window.__setRow1.isConnected,
  254. };
  255. })()`);
  256. check('setRows: deleting row 0 keeps surviving row DOM node', setAfterDel.kept1, JSON.stringify(setAfterDel));
  257. await page.click('#set-cancel');
  258. await page.waitFor('!document.querySelector("#settingseditor").matches(":popover-open")');
  259. check('no browser console errors', page.problems().filter(x => !/favicon|Failed to load resource/.test(x.text)).length === 0, JSON.stringify(page.problems()));
  260. } catch (e) {
  261. check(e.stack || String(e), false);
  262. } finally {
  263. if (page) await page.close().catch(() => {});
  264. if (browser) await browser.close().catch(() => {});
  265. if (server) {
  266. server.kill('SIGTERM');
  267. await new Promise(r => { if (server.exitCode !== null) return r(); server.once('exit', r); setTimeout(r, 5000); });
  268. }
  269. if (ident) await ident.stop().catch(() => {});
  270. writeFileSync(join(G, 'server.log'), log);
  271. }
  272. console.log(`${passed} passed, ${failed} failed`);
  273. 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