PlotDirector/PlotLine.Tests/Browser/location-controls.cjs

34 lines
2.2 KiB
JavaScript

const {chromium}=require('playwright');
const assert=require('node:assert/strict');
(async()=>{const browser=await chromium.launch();try{
for(const pwa of [false,true]){
const context=await browser.newContext({viewport:{width:1440,height:1000}});
if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
const page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message));
for(const theme of ['modern-light','modern-dark','warm-light','warm-dark']){
await page.goto('http://127.0.0.1:5238/fixture?desktop=Locations');
await page.evaluate(theme=>document.documentElement.dataset.appTheme=theme,theme);
const toolbar=page.locator('.location-hierarchy-toolbar');
assert.equal(await toolbar.isVisible(),!pwa);
const group=pwa?page.locator('[data-pwa-context-controls] .pd-context-group[aria-label="Location hierarchy"]'):toolbar;
const parent=group.getByRole('button',{name:'Change parent',exact:true}),relationship=group.getByRole('button',{name:'Create relationship',exact:true});
await parent.waitFor();await relationship.waitFor();
if(pwa){
assert.equal(await group.locator('.pd-context-segmented').count(),1);
const a=await parent.boundingBox(),b=await relationship.boundingBox();
assert.ok(Math.abs(a.x+a.width-b.x)<2,'Segments join without a gap');
assert.ok(a.height<=36&&b.height<=36,'Compact label-only controls');
assert.equal(await parent.locator('svg').isVisible(),false);
}
await relationship.focus();await page.keyboard.press('Enter');
assert.equal(await parent.getAttribute('aria-pressed'),'false');assert.equal(await relationship.getAttribute('aria-pressed'),'true');
assert.equal(await page.locator('[data-location-drag-action]').inputValue(),'relationship');
await page.reload();
assert.equal(await relationship.getAttribute('aria-pressed'),'true','Persisted preference restores through ribbon binding');
await parent.click();
}
assert.deepEqual(errors,[]);await context.close();
}
console.log('PASS compact connected Location hierarchy segments, keyboard selection, persisted state and browser/PWA fallback in four themes');
}finally{await browser.close();}})().catch(error=>{console.error(error);process.exitCode=1;});