19 lines
6.2 KiB
JavaScript
19 lines
6.2 KiB
JavaScript
// Actual compiled Context/renderers + existing registry; disposable loopback main-page shells.
|
|
const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs');
|
|
const base='http://127.0.0.1:5238';
|
|
(async()=>{const browser=await chromium.launch();let step='setup';try{const c=await browser.newContext({viewport:{width:1500,height:1000}});const errors=[];c.on('page',p=>p.on('pageerror',e=>errors.push(e.message)));
|
|
for(const route of ['**/native-companion/status','**/native-companion/connection-state'])await c.route(route,r=>r.fulfill({json:[]}));await c.route('**/Writing/Context/Position?*',r=>r.fulfill({json:{connected:false}}));await c.route('**/Writing/Context/Tabs/*',r=>r.fulfill({body:'<div data-context-tab-fragment data-book-id="12" data-scene-id="22">Existing tool</div>',contentType:'text/html'}));
|
|
for(const route of ['/Locations/**','/Characters/Details/**','/Characters/Edit/**','/FloorPlans/Edit/**','/StoryCalendar*','/PlotThreads/Edit/**','/RelationshipMap*','/Books/Details/**','/manuscript/paragraphs*','/Writer'])await c.route(base+route,async r=>{if(r.request().isNavigationRequest())await r.fulfill({response:await r.fetch({url:base+'/fixture?layout=full'})});else await r.continue();});
|
|
await c.route(base+'/Maps?*',async r=>{if(r.request().isNavigationRequest())await r.fulfill({response:await r.fetch({url:base+'/fixture?layout=full'})});else await r.continue();});
|
|
let main=await c.newPage();await main.goto(base+'/fixture?layout=full');const p=await c.newPage();await p.goto(base+'/Writing/Context?pinned=true');await p.selectOption('[data-context-pane="0"] [data-context-tab]','locations');await p.getByRole('heading',{name:'Bedroom',exact:true}).waitFor();await p.selectOption('[data-context-layout]','columns');await p.selectOption('[data-context-pane="1"] [data-context-tab]','maps');await p.waitForFunction(()=>document.querySelector('iframe')?.contentWindow?.PlotDirectorMapWorkspace?.document.features.length===2);await p.evaluate(()=>document.querySelector('iframe').contentWindow.PlotDirectorMapWorkspace.setView({x:50,y:60,w:900,h:700}));
|
|
const snapshot=()=>p.evaluate(()=>({url:location.href,layout:document.querySelector('[data-context-layout]').value,tabs:[...document.querySelectorAll('[data-context-tab]')].map(n=>n.value),position:document.querySelector('[data-context-workspace]').contextController.position,held:document.querySelector('[data-context-workspace]').contextController.held,heading:document.querySelector('[data-spatial-details] h2')?.textContent,view:document.querySelector('iframe')?.contentWindow?.PlotDirectorMapWorkspace?.view}));
|
|
const before=await snapshot(),count=c.pages().length;const ready=async()=>{await p.waitForFunction(()=>document.querySelector('[data-context-workspace]').contextController.connection?.state==='Connected'&&document.querySelector('[data-context-workspace]').contextController.connection.invoke('MyContextWindows',12).then(rows=>rows.some(r=>r.kind==='main')));await p.waitForTimeout(600);};
|
|
async function go(label,expected){console.log("CHECK",label,expected);await ready();const link=p.getByRole('link',{name:label,exact:true});if(label==='Calendar')await link.click({modifiers:['Control']});else if(label==='Thread'){await link.focus();await p.keyboard.press('Enter');}else if(label==='Book')await link.click({button:'middle'});else await link.click();await main.waitForURL(u=>u.pathname+u.search===expected);assert.equal(c.pages().length,count);assert.deepEqual(await snapshot(),before);}
|
|
step='companion header main link';await go('PlotDirector','/Writer');step='spatial exact URLs in existing main';await go('Location Details','/Locations/Details/103');await go('Edit Location','/Locations/Edit/103');const mapUrl=new URL(await p.getByRole('link',{name:'Open in Maps',exact:true}).getAttribute('href'),base);await go('Open in Maps',mapUrl.pathname+mapUrl.search);
|
|
step='dynamic links, modifiers, keyboard and selected blocks';const links=[['Floor editor','/FloorPlans/Edit/9?selectedBlockId=51'],['Edit Character','/Characters/Edit/5'],['Character Details','/Characters/Details/5'],['Calendar','/StoryCalendar?projectId=7&bookId=12'],['Thread','/PlotThreads/Edit/6'],['Book','/Books/Details/12'],['Structure','/manuscript/paragraphs?bookId=12']];for(const [label,url] of links){await p.evaluate(([text,href])=>{const a=document.createElement('a');a.textContent=text;a.href=href;document.querySelector('[data-context-pane="1"]').append(a);},[label,url]);await go(label,url);}
|
|
step='multiple Context windows';const second=await c.newPage();await second.goto(base+'/Writing/Context?pinned=true');await second.selectOption('[data-context-pane="0"] [data-context-tab]','locations');await second.getByRole('heading',{name:'Bedroom',exact:true}).waitFor();await ready();await second.getByRole('link',{name:'Edit Location',exact:true}).click();await main.waitForURL('**/Locations/Edit/103');assert.deepEqual(await snapshot(),before);
|
|
step='closed main and rapid requests';await main.close();await p.waitForTimeout(600);await p.evaluate(()=>{const a=document.createElement('a');a.textContent='Fallback main';a.href='/Characters?projectId=7';document.querySelector('[data-spatial-details]').append(a);});const popup=p.waitForEvent('popup');await p.getByRole('link',{name:'Fallback main',exact:true}).click();main=await popup;await main.waitForURL('**/Characters?projectId=7');await p.getByRole('link',{name:'Open in Maps',exact:true}).click();await main.waitForURL(u=>u.pathname+u.search===mapUrl.pathname+mapUrl.search);assert.equal(c.pages().length,count+1);assert.deepEqual(await snapshot(),before);
|
|
step='blocked popup remains intercepted';await main.close();await p.waitForTimeout(600);await p.evaluate(()=>{window.open=()=>null;});await p.getByRole('link',{name:'Edit Location',exact:true}).click();await p.getByText('Your browser blocked the main window.',{exact:false}).waitFor();assert.deepEqual(await snapshot(),before);
|
|
assert.deepEqual(errors,[]);console.log('PASS Context external navigation: exact spatial routes, dynamically inserted main-page links, existing registry/main reuse, closed-main fallback, rapid requests, two Context windows, pinned split/map viewport preserved, popup blocking never escapes Context.');
|
|
}catch(e){console.error('FAIL '+step,e);process.exitCode=1;}finally{await browser.close();}})();
|