gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit384d3d23384d3d23|||PR give calendar months their own addressAtlas384d3d23/tests/month-url.mjs

6.2 KB

  1. import {spawn} from 'node:child_process';
  2. import {mkdirSync,writeFileSync} from 'node:fs';
  3. import {resolve,join} from 'node:path';
  4. import {launchBrowser,sleep} from './cdp.mjs';
  5. const app=resolve(process.env.TEST_APP||'.'), scratch=resolve(process.env.MONTH_SCRATCH||'.scratch/month-url'),base='http://localhost:8812';
  6. mkdirSync(scratch,{recursive:true});let server,browser,page,log='',passed=0,failed=0;
  7. function check(name,v){console.log((v?'ok ':'FAIL ')+name);if(v)passed++;else {failed++;throw Error(name)}}
  8. const pages=async()=> (await (await fetch(process.env.HL_CDP_URL+'/json/list')).json()).filter(p=>p.type==='page');
  9. try{
  10. if(!process.env.MONTH_EXTERNAL)server=spawn(join(app,'bin/hybriel'),['project.hl'],{cwd:app,env:{...process.env,CALENDAR_PORT:'8812',CALENDAR_WATCH:'0',CALENDAR_PUBLIC_URL:base,CALENDAR_STORAGE:join(scratch,'db'),CALENDAR_SESSIONS:join(scratch,'sessions')+'/'},stdio:['ignore','pipe','pipe']});
  11. if(server){server.stdout.on('data',d=>log+=d);server.stderr.on('data',d=>log+=d);}
  12. for(const end=Date.now()+150000;;){try{if((await fetch(base)).ok)break}catch{}if(Date.now()>end)throw Error(log);await sleep(250)}
  13. if(process.env.HL_CDP_URL)writeFileSync(join(scratch,'pages-before.json'),JSON.stringify(await pages(),null,2));
  14. browser=await launchBrowser({debugPortRange:[8814,8819]});page=await browser.newPage();
  15. await page.send('Network.setExtraHTTPHeaders',{headers:{'Accept-Language':'en'}});
  16. const ready=()=>page.waitFor('!!document.querySelector("#month-next") && !!window.__hl?.socket && window.__hl.socket.readyState===1',{timeout:120000});
  17. // Neighbour address identifies the displayed month independently of translated names.
  18. const title=()=>page.evaluate("document.querySelector('#month-next').getAttribute('href')");
  19. const reload=async()=>{page._loaded=false;await page.send('Page.reload');const end=Date.now()+120000;while(!page._loaded){if(Date.now()>end)throw Error('reload load event');await sleep(25)}};
  20. const key=async(k,n)=>{await page.send('Input.dispatchKeyEvent',{type:'keyDown',key:k,code:k,windowsVirtualKeyCode:n});await page.send('Input.dispatchKeyEvent',{type:'keyUp',key:k,code:k,windowsVirtualKeyCode:n})};
  21. for(const [width,height] of (process.env.HL_CDP_URL?[[390,844],[800,1280],[1280,800],[1280,900]]:[[390,844]])){
  22. await page.send('Emulation.setDeviceMetricsOverride',{width,height,deviceScaleFactor:1,mobile:width<600});
  23. await page.goto(base,{timeout:120000});await ready();const old=await title();
  24. const shot=async(label)=>{const {data}=await page.send('Page.captureScreenshot',{format:'png'});writeFileSync(join(scratch,width+'-'+height+'-'+label+'.png'),Buffer.from(data,'base64'))};
  25. await shot('before');await page.click('#month-next');await page.waitFor(`document.querySelector('#month-next').getAttribute('href')!==${JSON.stringify(old)}`);
  26. const url=await page.evaluate('location.href'),next=await title();check(width+' next changes address',url!==base+'/' && /[?&]m=\d{4}-\d{2}/.test(url));
  27. await reload();await ready();check(width+' reload keeps month',await title()===next);
  28. await page.evaluate('history.back()');await page.waitFor(`document.querySelector('#month-next').getAttribute('href')===${JSON.stringify(old)}`);check(width+' Back keeps month',await page.evaluate('location.search')==='');
  29. await page.evaluate('history.forward()');await page.waitFor(`document.querySelector('#month-next').getAttribute('href')===${JSON.stringify(next)}`);check(width+' Forward keeps month',true);
  30. await page.click('#month-prev');await page.waitFor(`document.querySelector('#month-next').getAttribute('href')===${JSON.stringify(old)}`);check(width+' previous changes address',await page.evaluate('location.href')!==url);
  31. await page.focus('#month-prev');await key('Tab',9);check(width+' Tab reaches next',await page.evaluate('document.activeElement.id')==='month-next');await key('Enter',13);await page.waitFor(`document.querySelector('#month-next').getAttribute('href')===${JSON.stringify(next)}`);check(width+' Enter navigates',await page.evaluate('location.href')===url);
  32. await shot('after');
  33. if(!process.env.HL_CDP_URL){const fresh=await browser.newPage();try{await fresh.goto(url,{timeout:120000});await fresh.waitForSelector('#month-title');check('fresh tab renders addressed month',await fresh.evaluate('document.querySelector("#month-next").getAttribute("href")')===await page.evaluate('document.querySelector("#month-next").getAttribute("href")'))}finally{await fresh.close()}}
  34. // A fresh document in the one owned tab exercises a copied address without opening another tab in his browser.
  35. await page.goto('about:blank');await page.goto(url,{timeout:120000});await ready();check(width+' fresh document keeps month',await title()===next);
  36. const html=await(await fetch(url,{headers:{'Accept-Language':'en'}})).text();writeFileSync(join(scratch,'served.html'),html);const [year,month]=new URL(url).searchParams.get('m').split('-').map(Number);const serverTitle=new Intl.DateTimeFormat('en',{month:'long',timeZone:'UTC'}).format(new Date(Date.UTC(year,month-1,15)))+' '+year;check(width+' document renders month',html.includes('<h2 id="month-title">'+serverTitle+'</h2>'));
  37. await page.waitFor('!!navigator.serviceWorker.controller',{timeout:120000});await page.setOffline(true);await reload();await page.waitForSelector('#month-title',{timeout:120000});check(width+' offline reload keeps shell/month',await title()===next);await page.setOffline(false);
  38. await page.goto(base+'/?m=bad',{timeout:120000});await ready();check(width+' invalid month uses current',await title()===old);
  39. }
  40. }catch(e){console.error(e.stack);if(page){console.log('STATE',await page.evaluate('JSON.stringify({url:location.href,title:document.querySelector("#month-title")?.textContent,days:document.querySelector("#month-days")?.textContent})'));console.log(page.dumpConsole())}failed++}finally{
  41. if(page)await page.close();if(browser)await browser.close();
  42. if(process.env.HL_CDP_URL){writeFileSync(join(scratch,'pages-after.json'),JSON.stringify(await pages(),null,2));writeFileSync(join(scratch,'pages-final.json'),JSON.stringify(await pages(),null,2))}
  43. if(server){server.kill('SIGTERM');await new Promise(r=>{if(server.exitCode!==null)return r();server.once('exit',r);setTimeout(r,5000)})}writeFileSync(join(scratch,'server.log'),log)
  44. }
  45. 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