PlotDirector/PlotLine.Tests/Browser/ribbon-compact.cjs

4 lines
3.4 KiB
JavaScript

const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'),cp=require('node:child_process');
(async()=>{const b=await chromium.launch();try{let baseline;const evidence=[];for(const before of [true,false]){const c=await b.newContext({viewport:{width:1666,height:1050}});await c.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));if(before){const css=cp.execFileSync('git',['show','f228d40:PlotLine/wwwroot/css/application-shell.css'],{encoding:'utf8'});await c.route('**/css/application-shell.css*',r=>r.fulfill({contentType:'text/css',body:css}));}const p=await c.newPage();await p.goto('http://127.0.0.1:5238/fixture?page=maps');await p.waitForSelector('[data-pwa-context-controls] .pd-context-command');const toggle=p.locator('[data-ribbon-collapse]');if(await toggle.getAttribute('aria-expanded')==='false')await toggle.click();await p.waitForTimeout(200);const facts=await p.evaluate(()=>{const panel=document.querySelector('.pd-ribbon-panel:not([hidden])'),bounds=panel.getBoundingClientRect(),commands=[...panel.querySelectorAll('.pd-ribbon-command')].filter(n=>n.getBoundingClientRect().width&&n.getBoundingClientRect().height);return{width:panel.clientWidth,scrollWidth:panel.scrollWidth,identities:[...new Set([...panel.querySelectorAll('[data-command-identity],[data-command-operation]')].map(n=>n.dataset.commandIdentity||n.dataset.commandOperation))].sort(),fitting:commands.filter(n=>n.getBoundingClientRect().right<=bounds.right+1).length,lines:commands.map(n=>{const span=n.querySelector(':scope>span');return{label:n.textContent.trim(),height:n.clientHeight,lines:span?Math.round(span.scrollHeight/parseFloat(getComputedStyle(span).lineHeight)):0};})}});if(before)baseline=facts;else{assert.equal(facts.identities.length,baseline.identities.length,'no commands removed');assert(facts.scrollWidth<baseline.scrollWidth,'shared spacing reduces occupied width');assert(facts.fitting>baseline.fitting,'more commands fit at 1666px');for(const x of facts.lines)assert(x.lines<=2,x.label+' exceeds two lines');}const out=process.env.PD_RIBBON_SCREENSHOTS;if(out){fs.mkdirSync(out,{recursive:true});await p.screenshot({path:out+'/Maps-1666-'+(before?'before':'after')+'.png'});}evidence.push({before,...facts});
if(!before)for(const width of [1666,1366,1024,800]){await p.setViewportSize({width,height:1050});for(const category of ['project','book','writer','story','characters','world','tools']){const tab=p.locator('#ribbon-tab-'+category);if(!await tab.count())continue;await tab.click();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2),category+' page overflow '+width);const heights=await p.locator('#ribbon-panel-'+category+' .pd-ribbon-command:visible').evaluateAll(ns=>ns.filter(n=>!n.closest('.pd-context-menu-content')).map(n=>Math.round(n.getBoundingClientRect().height)));assert(heights.every(h=>h===68),category+' inconsistent command heights '+heights);if(out&&(width===1666||width===800))await p.screenshot({path:out+'/'+category+'-'+width+'.png'});}}await c.close();}if(process.env.PD_RIBBON_SCREENSHOTS)fs.writeFileSync(process.env.PD_RIBBON_SCREENSHOTS+'/qualification.json',JSON.stringify(evidence,null,2));console.log('PASS shared ribbon: command preservation, greater 1666px Maps fit, two-line labels, uniform heights and primary tabs at 1666/1366/1024/800px; actual Chromium simulated PWA');}finally{await b.close();}})().catch(e=>{console.error(e.stack);process.exitCode=1;});