26 lines
9.4 KiB
JavaScript
26 lines
9.4 KiB
JavaScript
// Opt-in authenticated Development acceptance; disposable author scope only.
|
|
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=[];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)));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+'/Scenes/Edit/'+f.scenes[1]);await main.goto(base+'/Projects/Details/'+i.ProjectID);focusWrites=0;
|
|
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}));
|
|
const snap=()=>p.evaluate(()=>({url:location.href,layout:document.querySelector('[data-context-layout]').value,tabs:[...document.querySelectorAll('[data-context-tab]')].map(n=>n.value),scene:document.querySelector('[data-context-scene]').value,position:document.querySelector('[data-context-workspace]').contextController.position,hold:document.querySelector('[data-shared-focus-hold]').getAttribute('aria-pressed'),selection:document.querySelector('[data-spatial-details] h2')?.textContent,floorView:document.querySelector('[data-spatial-floor-world]')?.style.transform,view:document.querySelector('iframe')?.contentWindow?.PlotDirectorMapWorkspace?.view,scroll:[...document.querySelectorAll('[data-context-pane-body], [data-spatial-details]')].map(n=>[n.scrollLeft,n.scrollTop])}));
|
|
const ready=async()=>{await p.waitForFunction(book=>document.querySelector('[data-context-workspace]').contextController.connection?.state==='Connected'&&document.querySelector('[data-context-workspace]').contextController.connection.invoke('MyContextWindows',book).then(rows=>rows.some(r=>r.kind==='main'&&r.environmentID===window.PlotDirectorContextEnvironment)),i.BookID);await p.waitForTimeout(600);};
|
|
async function follow(link,expected){step=expected;await ready();await link.scrollIntoViewIfNeeded();const before=await snap(),count=c.pages().length;await link.click();await main.waitForURL(u=>u.pathname+u.search===expected);assert.equal(c.pages().length,count);assert.deepEqual(await snap(),before);checks.push(expected);}
|
|
step='companion chrome main reuse';await follow(p.getByRole('link',{name:'PlotDirector',exact:true}),'/Writer');step='existing spatial main reuse';await follow(p.getByRole('link',{name:'Location Details',exact:true}),`/Locations/Details/${f.locations[1]}`);await follow(p.getByRole('link',{name:'Edit Location',exact:true}),`/Locations/Edit/${f.locations[1]}`);const backState=await snap();await main.goBack();await main.waitForURL('**/Locations/Details/'+f.locations[1]);assert.deepEqual(await snap(),backState);checks.push('normal main-window Back history');const mapped=new URL(await p.getByRole('link',{name:'Open in Maps',exact:true}).getAttribute('href'),base);assert(mapped.searchParams.get('featureId'));await follow(p.getByRole('link',{name:'Open in Maps',exact:true}),mapped.pathname+mapped.search);await p.screenshot({path:out+`/${pwa?'pwa':'browser'}-locations-maps-preserved.png`});
|
|
step='floor exact block and split preservation';await p.selectOption(tabs(1),'floorplans');await p.locator('[data-block]').first().waitFor();const floorUrl=new URL(await p.getByRole('link',{name:'Open in Floor Plans',exact:true}).getAttribute('href'),base);assert(floorUrl.searchParams.get('selectedBlockId'));await follow(p.getByRole('link',{name:'Open in Floor Plans',exact:true}),floorUrl.pathname+floorUrl.search);await p.screenshot({path:out+`/${pwa?'pwa':'browser'}-locations-floorplans-preserved.png`});
|
|
step='Characters and expanded details';await p.selectOption(tabs(0),'characters');const row=p.locator(`[data-context-character="${i.NavigationCharacterID}"]`);await row.waitFor();if(!await row.evaluate(n=>n.open))await row.locator('summary').click();await follow(p.locator(`a[data-context-workspace-target="characters"][data-context-entity="${i.NavigationCharacterID}"]`).last(),`/Characters/Details/${i.NavigationCharacterID}`);
|
|
// Edit Character is supplied by the shared Name Details partial; dynamic-anchor
|
|
// coverage uses exactly its unmarked href contract without changing author data.
|
|
await p.evaluate(id=>{const a=document.createElement('a');a.textContent='Edit fixture Character';a.href='/Characters/Edit/'+id;document.querySelector('[data-character-explorer]').append(a);},i.NavigationCharacterID);await follow(p.getByRole('link',{name:'Edit fixture Character',exact:true}),`/Characters/Edit/${i.NavigationCharacterID}`);
|
|
step='Overview main links';await p.selectOption(tabs(0),'overview');const calendar=p.locator('a[href^="/StoryCalendar"]').first();await calendar.waitFor();const cal=new URL(await calendar.getAttribute('href'),base);await follow(calendar,cal.pathname+cal.search);const storyMaps=p.locator('a[href^="/Maps"]').first(),storyUrl=new URL(await storyMaps.getAttribute('href'),base);await follow(storyMaps,storyUrl.pathname+storyUrl.search);
|
|
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]));assert.equal(await second.locator('[data-shared-focus-hold]').getAttribute('aria-pressed'),'false');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,[]);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});}})();
|