40 lines
10 KiB
JavaScript
40 lines
10 KiB
JavaScript
const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs');
|
|
const base=process.env.PD_NARRATIVE_TEST_URL||'http://127.0.0.1:5238';
|
|
(async()=>{
|
|
const installed=process.argv.includes('--installed'),profile=fs.mkdtempSync('/tmp/pd-narrative-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}}),b=c.browser();
|
|
try{
|
|
await c.route('**/Writer/Work/State?*',r=>r.fulfill({json:{session:null,defaultPauseOnEdit:true}}));
|
|
await c.route('**/native-companion/connection-state',r=>r.fulfill({json:{known:false,state:'Disconnected',wordConnected:false}}));
|
|
await c.route('**/native-companion/status*',r=>r.fulfill({json:{leases:[]}}));
|
|
await c.route('**/signalr.min.js',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(require.resolve('@microsoft/signalr/dist/browser/signalr.min.js'),'utf8')}));
|
|
await c.route('**/hubs/**',r=>r.abort());
|
|
await c.addInitScript(()=>localStorage.setItem('plotdirector.desktop.v1.4',JSON.stringify({dismissedAt:Date.now()})));
|
|
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();
|
|
|
|
|
|
const active='.pd-ribbon-panel:not([hidden])',button=kind=>p.locator(`${active} [data-global-focus=${kind}]`);
|
|
const state=()=>p.evaluate(()=>window.PlotDirectorNarrativeFocus.state),set=t=>p.evaluate(t=>window.PlotDirectorNarrativeFocus.set(t),t);
|
|
async function placement(){const result=await p.locator(active).evaluate(panel=>{const focus=panel.querySelector('.pd-ribbon-focus'),groups=[...panel.querySelectorAll('.pd-ribbon-group')].filter(n=>n.getClientRects().length),help=groups.find(n=>n.getAttribute('aria-label')==='Help');return {count:panel.querySelectorAll('.pd-ribbon-focus').length,commands:[...focus.querySelectorAll('[data-global-focus]')].map(n=>n.dataset.globalFocus),order:Number(getComputedStyle(focus).order),helpOrder:help?Number(getComputedStyle(help).order):null,focusRight:focus.getBoundingClientRect().right,helpLeft:help?.getBoundingClientRect().left};});assert.equal(result.count,1);assert.deepEqual(result.commands,['previous','go','next']);assert.equal(result.order,90);if(result.helpOrder!==null){assert.equal(result.helpOrder,100);assert(result.focusRight<=result.helpLeft+2);}}
|
|
await p.goto(base+'/Writer/Review?projectId=7&bookId=12&chapterId=21');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);
|
|
await set({chapterID:21,sceneID:31});await placement();assert.equal(await p.locator('.pd-focus-picker [data-focus-step]').count(),0);
|
|
assert.equal(await p.locator(`${active} [data-pwa-binding*="reader-prev"],${active} [data-pwa-binding*="reader-next"]`).count(),0);
|
|
assert(!await p.locator('#reader-chapter').isVisible());assert(await p.locator('#reader-focus').count());assert(await p.locator('#reader-audio').count());
|
|
assert(await button('previous').isDisabled());await button('next').click();await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus.state.sceneID===101);await button('next').click();await p.waitForFunction(()=>document.querySelector('.manuscript-reader').dataset.chapterId==='22');assert.equal((await state()).sceneID,32);assert(await button('next').isDisabled());
|
|
let loads=0;const count=r=>{if(r.url().includes('/Writer/ReviewContent'))loads++;};p.on('request',count);const before=(await state()).version;await button('go').click();await p.waitForTimeout(100);assert.equal(loads,0,'aligned Review Go does not reload');assert.equal((await state()).version,before);p.off('request',count);
|
|
await p.locator('#reader-focus').evaluate(n=>n.click());assert(await p.locator('#reader-chapter').isVisible(),'specialised chapter picker retained when header is inaccessible');await set({chapterID:21,sceneID:31});await p.waitForFunction(()=>document.querySelector('.manuscript-reader').dataset.chapterId==='21');assert.equal(await p.locator('.manuscript-reader').getAttribute('data-focus'),'true','focus reading survives global chapter navigation');await p.locator('#reader-focus').evaluate(n=>n.click());assert(await p.locator('.pd-application-header').evaluate(n=>!n.inert),'application header becomes interactive after exiting Focus Reading');
|
|
for(const width of [1666,950,650])for(const theme of ['modern-light','modern-dark']){await p.setViewportSize({width,height:1050});await p.evaluate(t=>window.PlotDirectorApplyApplicationTheme?.(t),theme);await p.screenshot({path:`/tmp/pd-focus-ribbon-${installed?'pwa':'browser'}-${width}-${theme}.png`});assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));}
|
|
await p.setViewportSize({width:1666,height:1050});
|
|
await p.goto(base+'/Timeline/Index?projectId=7&bookId=12');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);await set({chapterID:21,sceneID:31});const timelineVersion=(await state()).version;await button('go').click();await p.waitForURL(/selectedSceneId=31/);await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);assert.equal((await state()).version,timelineVersion);assert(await p.locator('[data-inspector-drawer] [data-scene-id="31"]').count(),'existing Timeline inspector opens');
|
|
await p.locator('.timeline-scene-card[data-scene-id="31"]').evaluate(n=>n.hidden=true);await button('go').click();assert.match(await p.locator('[data-focus-workspace-status]').textContent(),/filters are retained/);assert(await p.locator('[data-focus-workspace-status] button').count());
|
|
await p.goto(base+'/fixture?desktop=Books');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);await set({chapterID:21,sceneID:31});const bookVersion=(await state()).version;const destination=p.waitForRequest(r=>r.isNavigationRequest()&&r.url().includes('/Chapters/Details/21'));await button('go').click();const request=await destination;assert(new URL(request.url()).searchParams.get('retainNarrativeFocus')==='true');await p.waitForURL(/Chapters\/Details\/21/);await p.waitForLoadState();assert.match(await p.locator('main').innerText(),/Focused chapter/);const read=await(await c.request.get(base+'/NarrativeFocus/Read?projectId=7&bookId=12')).json();assert.equal(read.version,bookVersion);assert.equal(read.sceneID,31);
|
|
await p.goto(base+'/fixture?desktop=StoryPoint');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus&&window.PlotDirectorFocusWorkspace?.adapter);await placement();await p.route('**/StoryPoint?*',r=>r.fulfill({contentType:'text/html',body:'<p>Snapshot loaded</p>'}));await p.route('**/StoryPoint/Index?*',r=>r.fulfill({contentType:'text/html',body:'<p>Snapshot loaded</p>'}));
|
|
await set({chapterID:22,sceneID:32});assert.notEqual(await p.locator('[data-point-scene]').inputValue(),'32');const pointVersion=(await state()).version;await button('go').click();assert.equal(await p.locator('[data-point-scene]').inputValue(),'32');assert.equal((await state()).version,pointVersion);await p.locator('[data-point-chapter]').selectOption('21');assert.equal((await state()).version,pointVersion,'local snapshot selection stays local');
|
|
await p.goto(base+'/fixture?desktop=PlotLineWorkspace');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus&&window.PlotDirectorFocusWorkspace?.adapter);await set({chapterID:21,sceneID:31});const plotVersion=(await state()).version;await button('go').click();assert(await p.locator('[data-plot-scene]').evaluate(n=>n.classList.contains('plot-weave-focus')));assert.equal((await state()).version,plotVersion);await p.locator('#plot-scene-search').fill('No matching scene');await button('go').click();assert.match(await p.locator('[data-focus-workspace-status]').textContent(),/selected plot lines and search are retained/);await p.route('**/PlotLineWorkspace/Inspector?*',r=>r.fulfill({contentType:'text/html',body:'<p>Focused scene details</p>'}));await p.locator('[data-focus-workspace-status] button').click();await p.waitForFunction(()=>document.querySelector('#plot-inspector-content').textContent.includes('Focused scene'));assert.equal(await p.locator('#plot-scene-search').inputValue(),'No matching scene');assert.equal((await state()).version,plotVersion);
|
|
await p.goto(base+'/fixture?page=floorplans');await p.waitForFunction(()=>document.querySelector('[data-floor-plan-initialized=true]'));await set({chapterID:21,sceneID:31});await p.route('**/FloorPlans/SaveLayout',r=>r.fulfill({status:400,json:{ok:false,message:'Synthetic save failure'}}));await p.locator('[data-save-layout-button]').evaluate(n=>n.click());await p.waitForFunction(()=>document.querySelector('[data-save-status]').dataset.saveState==='failed');const floorBefore=await p.locator('[data-occupancy-scene-select]').inputValue();const menu=p.locator(`${active} .pd-ribbon-focus details[data-compact=true]`);if(await menu.count()&&!await menu.evaluate(n=>n.open))await menu.locator('summary').click();await button('go').click();assert.match(await p.locator('[data-focus-workspace-status]').textContent(),/Save or discard/);assert.equal(await p.locator('[data-occupancy-scene-select]').inputValue(),floorBefore);assert.equal(await p.locator('[data-save-status]').getAttribute('data-save-state'),'failed','Go preserves unsaved floor-plan state');p.once('dialog',d=>d.accept());
|
|
await p.goto(base+'/fixture?desktop=Characters');await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);assert(await button('go').isDisabled(),'unsupported workspace disables Go');await placement();
|
|
console.log(`PASS ${installed?'installed PWA':'Chromium'} Focus ribbon order/placement, consolidated Review, one-click scene stepping across chapters, reader follow/Go/no-op/focus-mode controls, Timeline inspector and explicit filtered reveal, Book chapter destination retains scene focus, local snapshot alignment/isolation, unsupported states, responsive light/dark.`);
|
|
}finally{await c.close();await b?.close();fs.rmSync(profile,{recursive:true,force:true});}
|
|
})().catch(e=>{console.error(e.stack);process.exitCode=1;});
|