gitoria

calendar

All repositories: gitoria

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

6.6 KB

  1. // Stable toggle focus and the colours captured from fff2f53, including hover.
  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 assert from 'node:assert/strict';
  6. import {launchBrowser,sleep} from './cdp.mjs';
  7. import {startIdent} from './identkit.mjs';
  8. const APP=resolve(process.env.TEST_APP||new URL('..',import.meta.url).pathname),ROOT=resolve(new URL('..',import.meta.url).pathname);
  9. const G=join(APP,'.scratch','calendar28'),PORT=Number(process.env.CALENDAR_GATE_PORT||8812),BASE='http://localhost:'+PORT;
  10. const capture=process.argv[2]==='--capture',fixture=join(ROOT,'tests/calendar28-colors.json');
  11. mkdirSync(G,{recursive:true});let ident,server,browser,page,log='',passed=0;
  12. function check(name,condition){assert.ok(condition,name);passed++;console.log('ok '+name)}
  13. async function key(name,shift=false){for(const type of ['keyDown','keyUp'])await page.send('Input.dispatchKeyEvent',{type,key:name,code:name,windowsVirtualKeyCode:name==='Tab'?9:13,modifiers:shift?8:0,text:type==='keyDown'&&name==='Enter'?'\r':undefined})}
  14. async function focusToggle(id,neighbor,back){await page.focus(neighbor);await key('Tab',back);await page.waitFor(`document.activeElement.id===${JSON.stringify(id)}`);await page.evaluate('window.__toggle=document.activeElement');await key('Enter');await page.waitFor(`document.querySelector('#${id}').getAttribute('aria-pressed')==='true'`);check(id+' stays the same focused node after Tab and Enter',await page.evaluate(`document.activeElement===window.__toggle && document.querySelector('#${id}')===window.__toggle && document.activeElement.getAttribute('aria-pressed')==='true'`))}
  15. const values={};
  16. async function measure(name,selector){const pos=await page.evaluate(`(()=>{const e=document.querySelector(${JSON.stringify(selector)}),r=e.getBoundingClientRect();return {x:r.x+r.width/2,y:r.y+r.height/2}})()`);for(const hover of [false,true]){await page.send('Input.dispatchMouseEvent',{type:'mouseMoved',x:hover?pos.x:1,y:hover?pos.y:1});await sleep(50);values[name+(hover?'-hover':'')]=await page.evaluate(`(()=>{const c=getComputedStyle(document.querySelector(${JSON.stringify(selector)}));return {color:c.color,background:c.backgroundColor}})()`)}}
  17. try{
  18. // Execute the actual gone-device setup with the already-subscribed state. Before
  19. // #28 a hidden prompt still existed, so an unconditional tap silently hit (0,0).
  20. // The conditional View correctly omits it; setup must tolerate that absence.
  21. const pushSource=readFileSync(join(ROOT,'tests/push.mjs'),'utf8');
  22. const gone=pushSource.slice(pushSource.indexOf('// ---- 2 gone:'));
  23. const setup=gone.slice(gone.indexOf('await openSettings(page);')+'await openSettings(page);'.length,gone.indexOf("text = '';"));
  24. const AsyncFunction=Object.getPrototypeOf(async function(){}).constructor;
  25. let promptTaps=0;
  26. const subscribeSetup=new AsyncFunction('page','tap',setup);
  27. await subscribeSetup({evaluate:async()=>false},async()=>{throw Error('tap: no #notify-ask')});
  28. await subscribeSetup({evaluate:async()=>true},async()=>{promptTaps++});
  29. check('gone-device setup accepts automatic subscription and taps an offered prompt exactly once',promptTaps===1);
  30. ident=await startIdent({identDir:process.env.CALENDAR_GATE_IDENT_DIR||'/media/STORAGE/projects/WorldAPI/ident.worldapi.org',workDir:join(G,'ident'),port:PORT+1});
  31. const alice=await ident.signIn('[email protected]'),app=await ident.registerApp(alice,'calendar28',[BASE]);
  32. server=spawn(join(APP,'bin/hybriel'),['project.hl'],{cwd:APP,env:{...process.env,CALENDAR_PORT:''+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);
  33. for(let i=0;;i++){try{if((await fetch(BASE)).ok)break}catch{}if(i>600)throw Error(log);await sleep(250)}
  34. browser=await launchBrowser({debugPortRange:[8814,8814]});page=await browser.newPage();
  35. 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?.readyState===1',{timeout:120000});await page.click('#month-title');
  36. const dates=await page.evaluate('[...document.querySelectorAll("#month-days time")].map(t=>t.dateTime)'),date=dates[17],cookie=(await page.cookies([BASE])).map(c=>c.name+'='+c.value).join('; ');
  37. for(let i=0;i<5;i++){const f={id:'',title:'Colour '+i,allDay:false,startDate:date,startTime:'09:00',endDate:'',endTime:'',place:'',notes:'',zone:'UTC',custom:false,reminders:[]};const response=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]]})});const result=await response.json();assert.ok(result.value&&!result.value.error,JSON.stringify(result))}
  38. await page.goto(BASE,{timeout:120000});await page.waitFor('window.__hl?.socket?.readyState===1',{timeout:120000});
  39. const css=await page.evaluate('[...document.styleSheets].map(s=>{try{return [...s.cssRules].map(r=>r.cssText).join(" ")}catch{return ""}}).join(" ")');writeFileSync(join(G,'emitted.css'),css);
  40. check('event and more retain tag-qualified selectors',css.includes('button.event')&&css.includes('button.more'));
  41. for(const [width,height] of [[390,844],[1280,900]]){
  42. await page.send('Emulation.setDeviceMetricsOverride',{width,height,deviceScaleFactor:1,mobile:width<600});
  43. await measure(width+'-event','#month-days button.event');await measure(width+'-more','#month-days button.more');
  44. await page.click('#month-days li:nth-child(18) button.day-add');await page.waitFor('document.querySelector("#eventform") && document.querySelector("#eventform").getBoundingClientRect().height>0');
  45. await measure(width+'-selected','#kind-timed');
  46. if(!capture){await focusToggle('kind-allday','#kind-timed',false);await focusToggle('kind-timed','#kind-allday',true);await focusToggle('rem-own','#rem-calendar',false);await focusToggle('rem-calendar','#rem-own',true)}
  47. await page.click('#event-cancel');
  48. }
  49. if(capture)writeFileSync(fixture,JSON.stringify(values,null,2)+'\n');else{assert.deepEqual(values,JSON.parse(readFileSync(fixture,'utf8')));check('chip, overflow and selected colours/hover equal fff2f53 at 390 and 1280',true)}
  50. }finally{if(page)await page.close();if(browser)await browser.close();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();writeFileSync(join(G,'server.log'),log)}
  51. console.log(passed+' passed, 0 failed');

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