PlotDirector/PlotLine.Tests/Browser/writer-icon-corrections.cjs

19 lines
3.8 KiB
JavaScript

const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs');
(async()=>{const installed=process.argv.includes('--installed'),profile=fs.mkdtempSync('/tmp/pd-icon-pwa-');const c=installed?await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1666,height:1050}}):await(await chromium.launch()).newContext({viewport:{width:1666,height:1050}});const b=c.browser(),base='http://127.0.0.1:5238';try{
await c.addInitScript(()=>localStorage.setItem('plotdirector.desktop.v1.4',JSON.stringify({dismissedAt:Date.now()})));
await c.route('**/native-companion/status*',r=>r.fulfill({json:{leases:[]}}));
let p;if(installed){const tab=c.pages()[0];await tab.goto(base+'/fixture');const d=await b.newBrowserCDPSession(),manifestId=base+'/Projects';await d.send('PWA.install',{manifestId,installUrlOrBundleUrl:base+'/fixture'});await d.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'});const opened=c.waitForEvent('page');await d.send('PWA.launch',{manifestId,url:base+'/fixture'});p=await opened;await p.waitForLoadState();assert(await p.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}else p=await c.newPage();
await p.goto(base+'/Writer/Review?projectId=7&bookId=12&chapterId=21');
assert.equal(await p.locator('#ribbon-panel-writer [data-help-key="writer3.layout"]').count(),0);
assert(await p.locator('#ribbon-tab-help').isVisible());assert.equal(await p.locator('[data-ribbon-word] .pd-destination-badge').count(),3);
const mappings={'reader-prev':'chevron-left','reader-next':'chevron-right','reader-focus':'maximise','reader-audio':'headphones','reader-pause-toggle':'pause-circle','reader-apply-update':'refresh'};
for(const [id,key]of Object.entries(mappings))assert.equal(await p.locator('#'+id).evaluate(n=>window.PlotDirectorCommands.iconKey(n)),key);
for(const [id,key]of [['reader-focus','minimise'],['reader-pause-toggle','play-circle']]){await p.locator('#'+id).evaluate(n=>{n.click()});assert.equal(await p.locator('#'+id).evaluate(n=>window.PlotDirectorCommands.iconKey(n)),key);}
await p.locator('#reader-focus').evaluate(n=>n.click());
assert.equal(await p.locator('[data-review-record]').evaluate(n=>window.PlotDirectorCommands.iconKey(n)),'comment-add');
if(installed)await p.locator('#ribbon-panel-writer [data-ribbon-icon=comment-add]').waitFor();
if(installed){await p.evaluate(()=>window.PlotDirectorNarrativeFocus.set({chapterID:21,sceneID:101}));await p.waitForFunction(()=>{const icons=[...document.querySelectorAll('#ribbon-panel-writer [data-global-focus=previous] svg,#ribbon-panel-writer [data-global-focus=next] svg')];return icons.length===2&&getComputedStyle(icons[0]).color===getComputedStyle(icons[1]).color;});const pair=p.locator('#ribbon-panel-writer [data-global-focus=previous] svg,#ribbon-panel-writer [data-global-focus=next] svg');await pair.first().waitFor();const styles=await pair.evaluateAll(ns=>ns.map(n=>{const s=getComputedStyle(n);return[s.width,s.height,s.strokeWidth,s.color]}));assert.equal(styles.length,2);assert.deepEqual(styles[0],styles[1]);}
for(const theme of ['modern-light','modern-dark'])for(const width of [1666,800]){await p.setViewportSize({width,height:1050});await p.evaluate(t=>window.PlotDirectorApplyApplicationTheme(t),theme);await p.evaluate(()=>new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r))));assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));fs.mkdirSync('/tmp/pd-icon-evidence',{recursive:true});await p.locator('[data-ribbon-shell]').screenshot({path:`/tmp/pd-icon-evidence/${installed?'pwa':'browser'}-${theme}-${width}.png`});}
console.log('PASS '+(installed?'installed PWA':'browser')+' icon mappings, stateful icons, scoped Help removal, Word badges, themes and widths');
}finally{await c.close();await b.close();fs.rmSync(profile,{recursive:true,force:true});}})().catch(e=>{console.error(e);process.exitCode=1});