PlotDirector/PlotLine.Tests/Browser/context-locations.cjs
2026-12-01 12:25:06 +00:00

12 lines
3.5 KiB
JavaScript

// Actual Locations lifecycle in a browser with synthetic read-only data.
const {chromium}=require('playwright'),assert=require('node:assert/strict');
(async()=>{const browser=await chromium.launch();try{
const page=await browser.newPage();await page.route('https://context.test/**',r=>r.fulfill({contentType:'text/html',body:'<div data-context-workspace data-scope-project-id="1" data-scope-book-id="2"><div data-spatial-context="locations"><button data-spatial-return></button><span data-spatial-status></span><p data-spatial-error></p><nav data-spatial-scenes></nav><section data-spatial-details></section><div data-spatial-operation></div><button data-spatial-undo></button></div></div>'}));await page.goto('https://context.test/');
await page.evaluate(()=>{window.fixture={scope:{projectID:1,bookID:2,sceneID:3,primaryLocationID:10,canEdit:false},scenes:[{position:0,sceneID:3,locationID:10,label:'Current'}],assignments:[{sceneID:3,locationID:10,kind:'Scene location'}],locations:[{locationID:10,locationName:'Room'},{locationID:20,locationName:'Yard'}],characters:[{characterName:'<script>observer</script>',presenceTypeName:'Mentioned',locationName:null}],sensoryRelationships:[{fromLocationID:10,toLocationID:20,fromLocationName:'Room',toLocationName:'Yard',canSeeMovement:true,canHearLoudNoise:true,isBidirectional:true,notes:'<b>barrier</b>'}],relationships:[],types:[],maps:[],plans:[]};window.fetch=async()=>({ok:true,json:async()=>structuredClone(window.fixture)});document.querySelector('[data-context-workspace]').contextController={windowId:'test',position:{sceneId:3}};});
await page.addScriptTag({path:'PlotLine/wwwroot/js/context-spatial.js'});await page.evaluate(()=>PlotDirectorContextLifecycles.spatial.mount(document.querySelector('[data-spatial-context]'),{position:{projectId:1,bookId:2,sceneId:3},windowId:'test',paneId:'0'}));
const host=page.locator('[data-spatial-details]');await host.getByRole('heading',{name:'Can see',exact:true}).waitFor();assert.equal(await host.locator('script,b').count(),0);assert.match(await host.textContent(),/Mentioned · Location unknown \/ unset/);assert.equal(await host.getByText('Unknown / unset: no relationship recorded in this direction.',{exact:true}).count(),2);assert.equal(await host.getByRole('link',{name:'Yard',exact:true}).count(),2);assert.match(await host.textContent(),/movement: enabled/);assert.match(await host.textContent(),/clear sight: unset \/ not enabled/);
await page.evaluate(()=>PlotDirectorSpatialContext.inspect(document.querySelector('[data-context-workspace]'),20,'test'));await host.locator('h2').filter({hasText:'Yard'}).waitFor();assert.equal(await host.getByRole('link',{name:'Room',exact:true}).count(),2);assert.equal(await host.getByText('Unknown / unset: no relationship recorded in this direction.',{exact:true}).count(),2);
await page.evaluate(()=>{window.fixture.scope.primaryLocationID=null;window.fixture.assignments=[];window.fixture.characters=[];window.fixture.sensoryRelationships=[];PlotDirectorContextLifecycles.spatial.onInvalidation(document.querySelector('[data-spatial-context]'),{kind:'locations'});});await host.getByText('Unknown / unset: no scene characters recorded.',{exact:true}).waitFor();assert.equal(await host.getByText('Unknown / unset: no relationship recorded in this direction.',{exact:true}).count(),4);
console.log('PASS Locations lifecycle: incoming/outgoing asymmetry, no both-ways inference, unset flags/placements/presence, literal author text and main-window-compatible links');
}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});