calendar
All repositories: gitoria
7.7 KB
import {spawn} from 'node:child_process';import {mkdirSync,writeFileSync,existsSync} from 'node:fs';import {resolve,join} from 'node:path';import {launchBrowser,sleep} from './cdp.mjs';import {startIdent} from './identkit.mjs';const W=process.cwd(),APP=resolve(process.env.TEST_APP||new URL('..',import.meta.url).pathname),tag=process.env.TEST_TAG||'proof',G=join(APP,'.scratch','proof-'+tag),PORT=8812,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='',failed=0,passed=0;function check(s,v){console.log((v?'ok ':'FAIL ')+s);if(v)passed++;else failed++}const list=async()=> (await(await fetch(process.env.HL_CDP_URL+'/json/list')).json()).filter(x=>x.type==='page');let before=[];try {ident=await startIdent({identDir:IDENT_DIR,workDir:join(G,'ident'),port:8813});const alice=await ident.signIn('[email protected]'),key=await ident.registerApp(alice,'calendar26 proof',[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:key.key,IDENT_API_SECRET:key.secret},stdio:['ignore','pipe','pipe']});writeFileSync(join(G,'pids.json'),JSON.stringify({server:server.pid,runner:process.pid}));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 '+log);await sleep(250)}if(process.env.HL_CDP_URL){before=await list();writeFileSync(join(G,'pages-before.json'),JSON.stringify(before,null,2))}browser=await launchBrowser({debugPortRange:[8814,8814]});page=await browser.newPage();const code=await ident.selectorCode(alice,key,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});writeFileSync(join(G,'served.html'),await(await fetch(BASE)).text());for(const [width,height] of [[390,844],[800,1280],[1280,800],[1280,900]]){await page.send('Emulation.setDeviceMetricsOverride',{width,height,deviceScaleFactor:1,mobile:width<600});await page.click('#month-title');const date=await page.evaluate('document.querySelector("#month-days li:nth-child(18) time").dateTime');await page.click('#month-days li:nth-child(18) button.day-add');await page.waitFor('document.querySelector("#eventeditor").classList.contains("open")');check(width+' day opens correct date',await page.evaluate('document.querySelector("#f-startdate").value')===date);await page.type('#f-title','Calendar26 '+width);await page.click('#event-save');await page.waitFor('document.querySelector("#eventeditor").classList.contains("closed")');await page.click('#month-days li:nth-child(18) button.event');await page.waitFor('document.querySelector("#formheading").textContent==="Edit event"');check(width+' event opens correct ID/title',await page.evaluate('document.querySelector("#f-title").value')==='Calendar26 '+width);await page.click('#event-delete');await page.waitFor('document.querySelector("#eventeditor").classList.contains("closed")');await page.click('#settings-open');await page.waitFor('document.querySelector("#settingseditor").matches(":popover-open") && document.querySelectorAll("#set-rows reminder-row").length===2');// Native toggle is queued; retained rows alone do not mean this opening has settled.await sleep(500);const isOpen = () => page.evaluate('document.querySelector("#settingseditor").matches(":popover-open")');const reopen = async () => { if (!await isOpen()) { await page.click('#settings-open'); await page.waitFor('document.querySelector("#settingseditor").matches(":popover-open")'); await sleep(300); } };await page.focus('#set-rows input[type=number]');await page.send('Input.dispatchKeyEvent',{type:'keyDown',key:'Tab',code:'Tab',windowsVirtualKeyCode:9});await page.send('Input.dispatchKeyEvent',{type:'keyUp',key:'Tab',code:'Tab'});await sleep(300);check(width+' Tab keeps settings open',await isOpen());await reopen();await page.type('#set-rows input[type=number]','9');await sleep(300);check(width+' typing keeps settings open',await isOpen());await reopen();// A valid HTML number outside the server's allowed hours range causes a real refusal.await page.evaluate('(() => { const n=document.querySelector("#set-rows input[type=number]"); n.value="999"; n.dispatchEvent(new Event("change",{bubbles:true})); })()');await sleep(300);if (await isOpen()) { await page.click('#set-save'); }else { await page.evaluate('document.querySelector("#settingseditor form").requestSubmit()'); }await page.waitFor('document.querySelector("#settingserror").textContent.includes("hours must be 1 to 168")');check(width+' rejected save stays open with visible error',await page.evaluate('document.querySelector("#settingseditor").matches(":popover-open") && document.querySelector("#settingserror").getBoundingClientRect().height>0'));const failureShot=await page.send('Page.captureScreenshot',{format:'png'});writeFileSync(join(G,width+'-'+height+'-refused.png'),Buffer.from(failureShot.data,'base64'));await reopen();await page.evaluate('(() => { const n=document.querySelector("#set-rows input[type=number]"); n.value="1"; n.dispatchEvent(new Event("change",{bubbles:true})); })()');await page.focus('#set-cancel');await page.send('Input.dispatchKeyEvent',{type:'keyDown',key:'Escape',code:'Escape',windowsVirtualKeyCode:27});await page.send('Input.dispatchKeyEvent',{type:'keyUp',key:'Escape',code:'Escape'});await page.waitFor('!document.querySelector("#settingseditor").matches(":popover-open")');check(width+' Escape closes settings',true);await page.click('#settings-open');await page.waitFor('document.querySelector("#settingseditor").matches(":popover-open")');await sleep(500);const {data}=await page.send('Page.captureScreenshot',{format:'png'});writeFileSync(join(G,width+'-'+height+'.png'),Buffer.from(data,'base64'));await page.click('#set-save');await page.waitFor('!document.querySelector("#settingseditor").matches(":popover-open")');check(width+' accepted save closes settings',true);const stamp=await page.evaluate('Math.max(...Object.keys(localStorage).filter(x=>x.startsWith("calendar-reminded-until-" )).map(x=>Number(localStorage[x])))');await sleep(50);await page.evaluate('window.dispatchEvent(new PageTransitionEvent("pageshow",{persisted:true}))');await page.waitFor(`Math.max(...Object.keys(localStorage).filter(x=>x.startsWith('calendar-reminded-until-')).map(x=>Number(localStorage[x]))) !== ${JSON.stringify(stamp)}`);check(width+' returning page refreshes reminder timestamp',true);}check('no component errors',page.problems().filter(x=>!/favicon|Failed to load resource/.test(x.text)).length===0);}catch(e){check(e.stack,false)}finally{if(page)await page.close();if(browser){if(process.env.HL_CDP_URL)browser.conn.close();else await browser.close()}if(process.env.HL_CDP_URL){const after=await list();writeFileSync(join(G,'pages-after.json'),JSON.stringify(after,null,2));writeFileSync(join(G,'pages-final.json'),JSON.stringify(await list(),null,2));check('own tab removed',!after.some(x=>x.id===page?.targetId))}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, ${failed} failed`);process.exitCode=failed?1:0;
Branches
Latest commits
- 384d3d23|||PR give calendar months their own addressAtlas
- 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
- 79e49b4dMerge branch 'hl-standard' into mainAtlas