91 lines
9.1 KiB
JavaScript
91 lines
9.1 KiB
JavaScript
const {chromium}=require('playwright');
|
|
const assert=require('node:assert/strict');
|
|
const base='http://127.0.0.1:5238';
|
|
(async()=>{
|
|
const browser=await chromium.launch(); const errors=[];
|
|
try {
|
|
const context=await browser.newContext({viewport:{width:1700,height:1000}});
|
|
const web=await context.newPage();web.on('pageerror',e=>errors.push(e.message));
|
|
await web.goto(base+'/fixture?page=relationships');await web.waitForFunction(()=>!!window.PlotDirectorRelationshipWorkspace);
|
|
assert(await web.locator('.rw-toolbar').isVisible(),'browser toolbar remains');
|
|
const webRow=await web.locator('#rwApp').evaluate(e=>getComputedStyle(e).gridTemplateRows.split(' ')[0]);assert.equal(webRow,'44px');
|
|
const appContext=await browser.newContext({viewport:{width:1700,height:1000}});
|
|
await appContext.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
|
|
const app=await appContext.newPage();app.on('pageerror',e=>errors.push(e.message));
|
|
await app.goto(base+'/fixture?page=relationships');await app.waitForFunction(()=>!!window.PlotDirectorRelationshipWorkspace);
|
|
assert(await app.locator('.rw-toolbar').isHidden(),'PWA has no second toolbar');
|
|
const shell=app.locator('[data-pwa-context-controls]');
|
|
async function command(name){
|
|
const target=shell.getByRole('button',{name,exact:true,includeHidden:true});assert.equal(await target.count(),1,'single ribbon command '+name);
|
|
const menu=target.locator('xpath=ancestor::details[@data-compact="true"]').last();
|
|
if(await menu.count() && !(await menu.evaluate(e=>e.open))) await menu.locator(':scope > summary').click();
|
|
await target.waitFor({state:'visible'});
|
|
return target;
|
|
}
|
|
for(const name of ['Map','List','Full cast','Details','Add relationship','Auto-arrange','Remove focused from map','Reset layout','Characters','Maximise workspace']) await command(name);
|
|
for(const name of ['View','Focus','Relationship','Arrange','Layout','Display']) assert(await shell.locator(`.pd-context-group[aria-label="${name}"]`).count(),name+' group');
|
|
assert(await shell.locator('[data-help-open]').count(),'Help uses ribbon help');
|
|
assert.equal(await shell.locator('.relationship-map-legend-grid').count(),0,'legend removed from ribbon');
|
|
assert(await app.locator('.rw-rail .rw-colour-key').isVisible(),'colour key at bottom of right panel');
|
|
await shell.locator('.pd-context-group[aria-label="Display"] > details > summary').click();
|
|
const display=shell.locator('.pd-context-group[aria-label="Display"] > details > .pd-context-menu-content');
|
|
for (const label of ['Book','Chapter','Scene','Character focus']) assert(await display.getByLabel(label,{exact:true}).isVisible(), 'direct stacked selector '+label);
|
|
assert.equal(await display.locator('.pd-context-selector').count(),0,'ordinary select lists, no nested picker menus');
|
|
await display.getByLabel('Book',{exact:true}).selectOption('12');
|
|
await display.getByLabel('Chapter',{exact:true}).selectOption('21');
|
|
await display.getByLabel('Scene',{exact:true}).selectOption('100');
|
|
assert.equal(await app.locator('#bookId').inputValue(),'12','book binding');
|
|
assert.equal(await app.locator('#chapterId').inputValue(),'21','chapter binding');
|
|
assert.equal(await app.locator('#sceneId').inputValue(),'100','scene binding');
|
|
await web.locator('.rw-display > summary').click();
|
|
for (const id of ['bookId','chapterId','sceneId']) assert(await web.locator('#'+id).isVisible(),'browser dropdown '+id);
|
|
assert(await web.locator('.rw-display > .rw-menu-panel').evaluate(e=>e.scrollHeight<=e.clientHeight+1),'browser Display does not scroll');
|
|
const iconPaths=await shell.locator('button.pd-context-command').evaluateAll(nodes=>nodes.map(n=>n.querySelector('svg path')?.getAttribute('d')));
|
|
assert(iconPaths.every(Boolean),'every command has a relevant icon'); assert.equal(new Set(iconPaths).size,iconPaths.length,'command icons are distinct');
|
|
if (!(await display.locator('..').evaluate(e=>e.open))) await display.locator('..').locator(':scope > summary').click();
|
|
assert(await display.evaluate(e=>e.scrollHeight<=e.clientHeight+1 && e.scrollWidth<=e.clientWidth+1),'Display has no scrolling');
|
|
assert(await (await command('Update Map')).isVisible()); assert(await (await command('Maximise workspace')).isVisible());
|
|
const geometry=await app.locator('#rwApp').evaluate(e=>({top:e.getBoundingClientRect().top,board:document.getElementById('rwBoard').getBoundingClientRect().top,rows:getComputedStyle(e).gridTemplateRows.split(' ').length}));
|
|
assert.equal(geometry.rows,1,'no reserved toolbar grid row');assert(Math.abs(geometry.board-geometry.top)<2,'palettes start immediately, recovered space used');
|
|
await (await command('List')).click();assert(await app.locator('#rwListPanel').isVisible());assert.equal(await (await command('List')).getAttribute('aria-pressed'),'true');
|
|
await (await command('Map')).click();assert(await app.locator('#rwBoard').isVisible());
|
|
await app.locator('[data-rw-character="1"]').click();
|
|
await app.waitForFunction(()=>[...document.querySelectorAll('[data-pwa-context-controls] button')].some(b=>b.textContent.includes('Focus: Élan Vale')));
|
|
assert.equal(await (await command('Focus: Élan Vale')).count(),1);
|
|
await (await command('Clear focus')).click();await app.waitForFunction(()=>document.getElementById('rwFocusName').textContent==='Full cast');
|
|
assert.equal(await (await command('Full cast')).count(),1);
|
|
await (await command('Details')).click();assert(await app.locator('#rwDetailPanel').isVisible());
|
|
await (await command('Add relationship')).click();assert(await app.locator('#rwDialog').evaluate(e=>e.open));await app.keyboard.press('Escape');
|
|
await app.evaluate(()=>{window.__layouts=0;window.PlotDirectorRelationshipWorkspace.cy.on('layoutstop',()=>window.__layouts++);});
|
|
await (await command('Auto-arrange')).click();assert(await app.evaluate(()=>window.__layouts>0),'original auto-arrange handler');
|
|
await (await command('Characters')).click();assert(await app.locator('#rwBoard').evaluate(e=>e.classList.contains('palettes-hidden')));assert(await app.locator('#rwDetailPanel').isVisible(),'Details remains when palettes collapse');await (await command('Characters')).click();
|
|
const maximise=await command('Maximise workspace');
|
|
assert.equal(await maximise.locator('xpath=ancestor::details[@data-compact="true"]').count(),0,'Maximise is directly on ribbon, not in a dropdown');
|
|
assert.equal(await display.getByRole('button',{name:'Maximise workspace',exact:true}).count(),0);
|
|
const beforeMax=await app.locator('#relationshipMapGraph').boundingBox();
|
|
await maximise.click();assert(await app.locator('#rwApp').evaluate(e=>e.classList.contains('rw-maximised')));
|
|
await app.waitForFunction(()=>getComputedStyle(document.querySelector('.pd-titlebar')).display==='none');
|
|
await app.waitForFunction(height=>document.getElementById('relationshipMapGraph').getBoundingClientRect().height>height+30,beforeMax.height);
|
|
const afterMax=await app.locator('#relationshipMapGraph').boundingBox();
|
|
assert(afterMax.height>beforeMax.height+30,'PWA maximise measurably increases canvas height');
|
|
|
|
assert(await shell.isVisible(),'ribbon remains reachable while maximised');
|
|
await (await command('Restore workspace')).click();assert(!(await app.locator('#rwApp').evaluate(e=>e.classList.contains('rw-maximised'))));
|
|
await app.waitForFunction(()=>getComputedStyle(document.querySelector('.pd-titlebar')).display!=='none');
|
|
await (await command('Maximise workspace')).click();await app.keyboard.press('Escape');
|
|
assert(!(await app.locator('#rwApp').evaluate(e=>e.classList.contains('rw-maximised'))),'Escape restores PWA workspace');
|
|
await app.setViewportSize({width:390,height:900});await (await command('Characters')).click();assert(await app.locator('.rw-navigation').isVisible(),'mobile cast opens via existing ribbon overflow');
|
|
assert(await app.locator('.rw-toolbar').isHidden());
|
|
assert.equal(await (await command('Maximise workspace')).locator('xpath=ancestor::details[@data-compact="true"]').count(),0,'mobile Maximise stays on the ribbon');
|
|
if (!(await display.locator('..').evaluate(e=>e.open))) await display.locator('..').locator(':scope > summary').click();
|
|
assert(await display.evaluate(e=>e.scrollHeight<=e.clientHeight+1 && e.scrollWidth<=e.clientWidth+1),'mobile Display has no scrolling');
|
|
await app.route('**/RelationshipMap?**', route=>route.fulfill({contentType:'text/html',body:'Submitted fixture'}));
|
|
const submitted=app.waitForRequest(request=>new URL(request.url()).pathname==='/RelationshipMap');
|
|
await (await command('Update Map')).click();
|
|
const query=new URL((await submitted).url()).searchParams;
|
|
assert.equal(query.get('projectId'),'7');assert.equal(query.get('bookId'),'12');assert.equal(query.get('chapterId'),'21');assert.equal(query.get('sceneId'),'100');
|
|
await app.goto(base+'/fixture');assert.equal(await app.locator('[data-pwa-context-controls]').getByRole('button',{name:'Add relationship',exact:true}).count(),0,'navigation clears relationship contributions');
|
|
assert.deepEqual(errors,[]);console.log('PASS Relationships ribbon: browser fallback, PWA controls/state/menus, recovered height, mobile overflow and navigation cleanup');
|
|
} finally {await browser.close();}
|
|
})().catch(e=>{console.error(e);process.exitCode=1});
|