56 lines
4.0 KiB
JavaScript
56 lines
4.0 KiB
JavaScript
const {chromium}=require('playwright');
|
|
const assert=require('node:assert/strict');
|
|
(async()=>{
|
|
const browser=await chromium.launch();
|
|
try {
|
|
for(const width of [1440,390]) for(const pwa of [false,true]) {
|
|
const context=await browser.newContext({viewport:{width,height:1000}});
|
|
if(pwa) await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
|
|
const page=await context.newPage(); const errors=[];page.on('pageerror',e=>errors.push(e.message));
|
|
await page.goto('http://127.0.0.1:5238/fixture?page=calendar-test');
|
|
await page.waitForFunction(()=>!!window.PlotDirectorPageContext);
|
|
const filter=page.locator('.story-calendar-filter');
|
|
await page.waitForTimeout(300);
|
|
assert.equal(await filter.isVisible(),!pwa,'in-page panel visibility');
|
|
async function controls(){
|
|
await page.evaluate(()=>new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r))));
|
|
if(!pwa) return filter;
|
|
const group=page.locator('.pd-context-group[aria-label="Calendar"]');
|
|
const details=group.locator(':scope > details');
|
|
if(await details.getAttribute('data-compact')==='true' && !await details.evaluate(e=>e.open)) await details.locator(':scope > summary').click();
|
|
return group;
|
|
}
|
|
let scope=await controls();
|
|
if(pwa && width===390) {
|
|
assert.equal(await scope.locator(':scope > details').getAttribute('data-compact'),'true','narrow Calendar uses shared collapse');
|
|
assert(await scope.locator('form').evaluate(e=>e.getBoundingClientRect().left>=0 && e.getBoundingClientRect().right<=innerWidth),'controls fit viewport');
|
|
}
|
|
const month=()=>pwa ? scope.getByLabel('Month',{exact:true}) : scope.locator('#month');
|
|
assert.deepEqual(await month().locator('option').evaluateAll(os=>os.map(o=>o.value)),['1983-03','1983-05','1983-09']);
|
|
const top=await page.locator('.story-calendar-month').evaluate(e=>e.getBoundingClientRect().top);
|
|
await page.getByRole('link',{name:'Next month',exact:true}).click();
|
|
await page.waitForFunction(()=>document.querySelector('#month').value==='1983-04');
|
|
scope=await controls(); assert.equal(await month().inputValue(),'1983-04');
|
|
assert(await page.locator('.story-calendar-month-title').textContent().then(t=>t.includes('April 1983')));
|
|
await page.getByRole('link',{name:'Next story month',exact:true}).click();
|
|
await page.waitForFunction(()=>document.querySelector('#month').value==='1983-05');
|
|
scope=await controls();assert.equal(await month().inputValue(),'1983-05');
|
|
assert.equal(await month().locator('option[value="1983-04"]').count(),0,'temporary empty month removed');
|
|
await (pwa ? scope.getByLabel('Book',{exact:true}) : scope.locator('#bookId')).selectOption('13');
|
|
await page.waitForFunction(()=>document.querySelector('#bookId').value==='13' && document.querySelector('#month option[value="1983-03"]')===null);
|
|
scope=await controls(); assert.equal(await month().inputValue(),'1983-05','current empty month retained after book change');
|
|
assert.deepEqual(await month().locator('option').evaluateAll(os=>os.map(o=>o.value)),['1983-05','1983-09']);
|
|
await month().selectOption('1983-09');
|
|
await page.waitForFunction(()=>document.querySelector('.story-calendar-month-title').textContent.includes('September 1983'));
|
|
scope=await controls();assert.equal(await page.getByRole('button',{name:'Apply',exact:true,includeHidden:true}).count(),0,'no redundant Apply button in page or ribbon');
|
|
await page.waitForFunction(()=>!document.querySelector('[data-story-calendar-root]').hasAttribute('aria-busy'));
|
|
assert.equal(await page.locator('#month').inputValue(),'1983-09');
|
|
assert.equal(await filter.isVisible(),!pwa);
|
|
assert.equal(errors.length,0,errors.join('\n'));
|
|
console.log(JSON.stringify({width,pwa,gridTop:Math.round(top),panelHeight:await filter.evaluate(e=>e.getBoundingClientRect().height)}));
|
|
await page.screenshot({path:`/tmp/calendar-${width}-${pwa?'pwa':'web'}.png`,fullPage:true});
|
|
await context.close();
|
|
}
|
|
} finally {await browser.close();}
|
|
})().catch(e=>{console.error(e);process.exit(1)});
|