calendar
All repositories: gitoria
5.7 KB
// Stable toggle focus and the colours captured from fff2f53, including hover.import {spawn} from 'node:child_process';import {mkdirSync,readFileSync,writeFileSync,existsSync} from 'node:fs';import {resolve,join} from 'node:path';import assert from 'node:assert/strict';import {launchBrowser,sleep} from './cdp.mjs';import {startIdent} from './identkit.mjs';const APP=resolve(process.env.TEST_APP||new URL('..',import.meta.url).pathname),ROOT=resolve(new URL('..',import.meta.url).pathname);const G=join(APP,'.scratch','calendar28'),PORT=Number(process.env.CALENDAR_GATE_PORT||8812),BASE='http://localhost:'+PORT;const capture=process.argv[2]==='--capture',fixture=join(ROOT,'tests/calendar28-colors.json');mkdirSync(G,{recursive:true});let ident,server,browser,page,log='',passed=0;function check(name,condition){assert.ok(condition,name);passed++;console.log('ok '+name)}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})}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'`))}const values={};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}})()`)}}try{ident=await startIdent({identDir:process.env.CALENDAR_GATE_IDENT_DIR||'/media/STORAGE/projects/WorldAPI/ident.worldapi.org',workDir:join(G,'ident'),port:PORT+1});const alice=await ident.signIn('[email protected]'),app=await ident.registerApp(alice,'calendar28',[BASE]);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);for(let i=0;;i++){try{if((await fetch(BASE)).ok)break}catch{}if(i>600)throw Error(log);await sleep(250)}browser=await launchBrowser({debugPortRange:[8814,8814]});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?.readyState===1',{timeout:120000});await page.click('#month-title');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('; ');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))}await page.goto(BASE,{timeout:120000});await page.waitFor('window.__hl?.socket?.readyState===1',{timeout:120000});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);check('event and more retain tag-qualified selectors',css.includes('button.event')&&css.includes('button.more'));for(const [width,height] of [[390,844],[1280,900]]){await page.send('Emulation.setDeviceMetricsOverride',{width,height,deviceScaleFactor:1,mobile:width<600});await measure(width+'-event','#month-days button.event');await measure(width+'-more','#month-days button.more');await page.click('#month-days li:nth-child(18) button.day-add');await page.waitFor('document.querySelector("#eventform") && document.querySelector("#eventform").getBoundingClientRect().height>0');await measure(width+'-selected','#kind-timed');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)}await page.click('#event-cancel');}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)}}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)}console.log(passed+' passed, 0 failed');
Branches
Latest commits
- 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
- 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