From 16eeed0139c95139925925885568803cece1e020 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Fri, 27 Nov 2026 20:05:03 +0000 Subject: [PATCH] test(context): assert navigation preserves focus and shared connection --- .../Browser/context-external-navigation-development.cjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PlotLine.Tests/Browser/context-external-navigation-development.cjs b/PlotLine.Tests/Browser/context-external-navigation-development.cjs index 01b2c6b3..7b9df93d 100644 --- a/PlotLine.Tests/Browser/context-external-navigation-development.cjs +++ b/PlotLine.Tests/Browser/context-external-navigation-development.cjs @@ -2,9 +2,9 @@ const {chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict'); const file=process.argv[2],pwa=process.argv.includes('--pwa'),base='https://dev.plotdirector.com',out='/tmp/pd-context-navigation-evidence'; assert(file?.startsWith('/tmp/pd-dev-browser-'));const i=JSON.parse(fs.readFileSync(file)),f=i.SpatialFixture;assert(i.Database==='PlotDirector_Development'&&i.Email.startsWith('pwa-browser-')&&f&&i.NavigationCharacterID);fs.mkdirSync(out,{recursive:true}); -(async()=>{let browser,c,cdp,profile,step='login';const errors=[],checks=[];try{ +(async()=>{let browser,c,cdp,profile,step='login';const errors=[],checks=[];let focusWrites=0;try{ if(pwa){profile=fs.mkdtempSync('/tmp/pd-context-nav-pwa-');c=await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1600,height:1050}});cdp=await c.browser().newBrowserCDPSession();}else{browser=await chromium.launch();c=await browser.newContext({viewport:{width:1600,height:1050}});} - c.on('page',p=>p.on('pageerror',e=>errors.push(e.message)));let main=c.pages()[0]||await c.newPage();await main.goto(base+'/Account/Login');await main.locator('#Email').fill(i.Email);await main.locator('#Password').fill(i.Password);await Promise.all([main.waitForURL('**/Projects'),main.locator('form button[type=submit]').click()]);await main.goto(base+'/Projects/Details/'+i.ProjectID); + c.on('page',p=>p.on('pageerror',e=>errors.push(e.message)));c.on('request',r=>{if(/\/(?:SharedFocus|Writing\/Context|WriterWord)\/Navigate$/i.test(new URL(r.url()).pathname))focusWrites++;});let main=c.pages()[0]||await c.newPage();await main.goto(base+'/Account/Login');await main.locator('#Email').fill(i.Email);await main.locator('#Password').fill(i.Password);await Promise.all([main.waitForURL('**/Projects'),main.locator('form button[type=submit]').click()]);await main.goto(base+'/Projects/Details/'+i.ProjectID); const url=base+`/Writing/Context?projectId=${i.ProjectID}&bookId=${i.BookID}&sceneId=${f.scenes[1]}&pinned=true`;let p; if(pwa){await cdp.send('PWA.install',{manifestId:base+'/Projects',installUrlOrBundleUrl:base+'/Projects'});await cdp.send('PWA.changeAppUserSettings',{manifestId:base+'/Projects',displayMode:'standalone'});const opened=c.waitForEvent('page');await cdp.send('PWA.launch',{manifestId:base+'/Projects',url});p=await opened;await p.waitForLoadState();assert(await p.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}else{p=await c.newPage();await p.goto(url);} const tabs=n=>`[data-context-pane="${n}"] [data-context-tab]`;await p.selectOption(tabs(0),'locations');await p.getByRole('heading',{name:'Bedroom',exact:true}).waitFor();await p.selectOption('[data-context-layout]','columns');await p.selectOption(tabs(1),'maps');await p.waitForFunction(()=>document.querySelector('iframe')?.contentWindow?.PlotDirectorMapWorkspace?.document.features.length>0);await p.evaluate(()=>document.querySelector('iframe').contentWindow.PlotDirectorMapWorkspace.setView({x:10,y:20,w:900,h:650})); @@ -21,5 +21,5 @@ assert(file?.startsWith('/tmp/pd-dev-browser-'));const i=JSON.parse(fs.readFileS step='multiple Context and following';const second=await c.newPage();await second.goto(url.replace('&pinned=true',''));await second.selectOption(tabs(0),'locations');await second.getByRole('heading',{name:'Bedroom',exact:true}).waitFor();await ready();const original=await snap();await second.getByRole('link',{name:'Location Details',exact:true}).click();await main.waitForURL('**/Locations/Details/'+f.locations[1]);assert.deepEqual(await snap(),original);assert.equal(await second.locator('[data-context-scene]').inputValue(),String(f.scenes[1]));checks.push('independent held/following Context windows'); step='closed main location fallback and rapid reuse';await p.selectOption(tabs(0),'locations');await p.getByRole('heading',{name:'Bedroom',exact:true}).waitFor();await main.close();await p.waitForTimeout(700);const pop=p.waitForEvent('popup');await p.getByRole('link',{name:'Location Details',exact:true}).click();main=await pop;await main.waitForURL('**/Locations/Details/'+f.locations[1]);await follow(p.getByRole('link',{name:'Open in Floor Plans',exact:true}),floorUrl.pathname+floorUrl.search);checks.push('closed-main fallback reused'); step='Context internal editing';await p.getByRole('button',{name:'Edit description',exact:true}).click();await p.locator('[data-spatial-operation] textarea').waitFor();await follow(p.getByRole('link',{name:'Location Details',exact:true}),`/Locations/Details/${f.locations[1]}`);assert(await p.locator('[data-spatial-operation] textarea').isVisible());await p.getByRole('button',{name:'Cancel',exact:true}).click(); - assert.deepEqual(errors,[]);fs.writeFileSync(out+`/${pwa?'pwa':'browser'}-results.json`,JSON.stringify({passed:true,authenticated:true,installedPwa:pwa,checks,errors,physicalWindowsWord:false},null,2));console.log('PASS authenticated '+(pwa?'installed PWA':'browser')+' external Context navigation: exact routes, existing/closed-main reuse, two held/following windows, split/map viewport retained, inline draft retained.'); + assert.deepEqual(errors,[]);assert.equal(focusWrites,0);const signalRConnections=await p.evaluate(()=>performance.getEntriesByType('resource').filter(r=>r.name.includes('/hubs/native-companion/negotiate')).length);assert.equal(signalRConnections,1);fs.writeFileSync(out+`/${pwa?'pwa':'browser'}-results.json`,JSON.stringify({passed:true,authenticated:true,installedPwa:pwa,checks,focusWrites,signalRConnections,errors,physicalWindowsWord:false},null,2));console.log('PASS authenticated '+(pwa?'installed PWA':'browser')+' external Context navigation: exact routes, existing/closed-main reuse, two held/following windows, split/map viewport retained, inline draft retained.'); }catch(e){console.error('FAIL '+step,e);process.exitCode=1;}finally{if(cdp)await cdp.send('PWA.uninstall',{manifestId:base+'/Projects'}).catch(()=>{});await c?.close();await browser?.close();if(profile)fs.rmSync(profile,{recursive:true,force:true});}})();