30 lines
2.0 KiB
JavaScript
30 lines
2.0 KiB
JavaScript
const {chromium}=require('playwright');
|
|
const assert=require('node:assert/strict');
|
|
const fs=require('node:fs'),os=require('node:os'),path=require('node:path');
|
|
(async()=>{
|
|
const profile=fs.mkdtempSync(path.join(os.tmpdir(),'pd-calendar-installed-'));
|
|
const context=await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1440,height:1000}});
|
|
const cdp=await context.browser().newBrowserCDPSession();
|
|
const base='http://127.0.0.1:5238',manifestId=base+'/Projects';
|
|
try{
|
|
await context.pages()[0].goto(base+'/fixture?page=calendar-test');
|
|
await cdp.send('PWA.install',{manifestId,installUrlOrBundleUrl:base+'/fixture?page=calendar-test'});
|
|
await cdp.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'});
|
|
const opened=context.waitForEvent('page');await cdp.send('PWA.launch',{manifestId,url:base+'/fixture?page=calendar-test'});
|
|
const app=await opened;await app.waitForLoadState();
|
|
assert(await app.evaluate(()=>matchMedia('(display-mode: standalone)').matches));
|
|
for(const width of [1440,390]){
|
|
await app.setViewportSize({width,height:1000});await app.waitForTimeout(300);
|
|
assert(await app.locator('.story-calendar-filter').isHidden());
|
|
const group=app.locator('.pd-context-group[aria-label="Calendar"]');
|
|
const menu=group.locator(':scope > details');
|
|
if(width===390) assert.equal(await menu.getAttribute('data-compact'),'true');
|
|
if(!await menu.evaluate(e=>e.open))await menu.locator(':scope > summary').click();
|
|
await group.getByLabel('Month',{exact:true}).selectOption('1983-05');
|
|
await app.waitForFunction(()=>document.querySelector('#month').value==='1983-05');
|
|
console.log('PASS installed PWA '+width+'x1000: standalone, ribbon, responsive collapse, month change');
|
|
await app.screenshot({path:`/tmp/calendar-installed-${width}.png`,fullPage:true});
|
|
}
|
|
}finally{await cdp.send('PWA.uninstall',{manifestId}).catch(()=>{});await context.close();fs.rmSync(profile,{recursive:true,force:true});}
|
|
})().catch(e=>{console.error(e);process.exit(1)});
|