14 lines
4.2 KiB
JavaScript
14 lines
4.2 KiB
JavaScript
const{chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict');
|
|
const who=JSON.parse(fs.readFileSync(process.env.PD_PHASE21_IDENTITY)),s=JSON.parse(fs.readFileSync(process.env.PD_PHASE21_SCOPE)),out=process.env.PD_PHASE21_RIBBON;
|
|
assert(who.Database==='PlotDirector_Development'&&/^pwa-browser-.*@example\.invalid$/.test(who.Email));
|
|
(async()=>{const b=await chromium.launch();try{for(const pwa of[false,true]){const c=await b.newContext({viewport:{width:1666,height:1050}});await c.addInitScript(({user,pwa})=>{localStorage.setItem('plotdirector.desktop.v1.'+user,JSON.stringify({dismissedAt:Date.now()}));if(pwa)Object.defineProperty(navigator,'standalone',{value:true});},{user:who.UserID,pwa});const p=await c.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));await p.goto('https://dev.plotdirector.com/Account/Login');await p.locator('[name=Email]').fill(who.Email);await p.locator('[name=Password]').fill(who.Password);await Promise.all([p.waitForURL('**/Projects'),p.locator('button[type=submit]').click()]);await p.goto('https://dev.plotdirector.com/Maps?projectId='+s.project+'&bookId='+s.book);const toggle=p.locator('[data-ribbon-collapse]');if(await toggle.getAttribute('aria-expanded')==='false')await toggle.click();if(pwa)await p.locator('[data-pwa-context-controls] .pd-context-command').first().waitFor();if(out)fs.mkdirSync(out,{recursive:true});
|
|
for(const theme of['modern-light','modern-dark','warm-light','warm-dark']){await p.evaluate(t=>window.PlotDirectorApplyApplicationTheme(t),theme);if(out)await p.screenshot({path:out+'/Maps-1666-'+theme+'-'+(pwa?'PWA':'browser')+'.png'});
|
|
const style=async tab=>await p.locator('#ribbon-tab-'+tab).evaluate(n=>{const s=getComputedStyle(n);return [s.color,s.backgroundColor,s.fontWeight];});
|
|
await p.locator('#ribbon-tab-project').click();await p.mouse.move(1,1);assert.deepEqual(await style('writer'),await style('book'),'same inactive tab style '+theme);const active=await style('project');
|
|
await p.locator('#ribbon-tab-writer').hover();const hover=await style('writer');await p.locator('#ribbon-tab-book').hover();assert.deepEqual(await style('book'),hover,'same hover tab style '+theme);
|
|
await p.mouse.move(1,1);await p.locator('#ribbon-tab-writer').focus();const focused=await style('writer');await p.locator('#ribbon-tab-book').focus();assert.deepEqual(await style('book'),focused,'same focus tab style '+theme);
|
|
const currentURL=p.url();await p.locator('#ribbon-tab-writer').click();assert.equal(p.url(),currentURL,'Writer selects its ribbon without leaving Maps');await p.evaluate(t=>window.PlotDirectorApplyApplicationTheme(t),theme);await p.mouse.move(1,1);assert.deepEqual(await style('writer'),active,'same active tab style '+theme);await p.goto('https://dev.plotdirector.com/Maps?projectId='+s.project+'&bookId='+s.book);}
|
|
|
|
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']){await p.locator('#ribbon-tab-'+category).click();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2),category+width);const rows=await p.locator('#ribbon-panel-'+category+' .pd-ribbon-command:visible').evaluateAll(ns=>ns.filter(n=>!n.closest('.pd-context-menu-content')).map(n=>{const span=n.querySelector(':scope>span');return{height:Math.round(n.getBoundingClientRect().height),label:n.textContent.trim(),lines:span?Math.round(span.scrollHeight/parseFloat(getComputedStyle(span).lineHeight)):0};}));for(const row of rows){assert.equal(row.height,68,category+' '+row.label);assert(row.lines<=2,category+' '+row.label+' wrapping');}if(out&&pwa&&(width===1666||width===800))await p.screenshot({path:out+'/'+category+'-'+width+'-deployed.png'});await p.keyboard.press('Tab');assert(await p.evaluate(()=>document.activeElement!==document.body),'keyboard focus retained');}}
|
|
assert.deepEqual(errors,[]);console.log('PASS deployed authenticated ribbons '+(pwa?'simulated PWA':'browser')+': all seven primary categories, four widths, four Maps themes, two-line labels, uniform heights, keyboard focus and no page overflow; no map command invoked');await c.close();}}finally{await b.close();}})().catch(e=>{console.error(String(e.stack).replaceAll(who.Password,'[redacted]'));process.exitCode=1});
|