PlotDirector/PlotLine.Tests/Browser/context-floorplans-development.cjs
2026-12-01 13:00:54 +00:00

32 lines
9.6 KiB
JavaScript

// Ordinary Development writer, real saved records, scoped disposable project.
const assert=require('node:assert/strict'),{open}=require('./dev-acceptance.cjs');
let session,stage='login';
(async()=>{try{
session=await open();let p=session.page;const project=await session.project();
stage='locations';const places=[];for(const name of ['Study','Hall','Kitchen','Upstairs'])places.push(await session.create('Locations','?projectId='+project,{LocationName:name}));const [a,b,c,d]=places;
const book=await session.create('Books','?projectId='+project,{BookTitle:'Floor acceptance',BookNumber:1}),chapter=await session.create('Chapters','?bookId='+book,{ChapterTitle:'Rooms',ChapterNumber:1});
async function scene(name,place){await session.goto('/Scenes/Create?chapterId='+chapter);await p.locator('#SceneTitle').fill(name);await p.locator('#PrimaryLocationID').selectOption(String(place));await p.getByRole('button',{name:'Create scene',exact:true}).click();await p.waitForURL('**/Scenes/Edit/*');return Number(new URL(p.url()).pathname.split('/').at(-1));}
const first=await scene('In study',a),second=await scene('Upstairs',d);
for(const [name,place] of [['Recorded Guest',a],['Unlocated Guest',null]]){const who=await session.create('Characters','?projectId='+project,{CharacterName:name},async page=>{const field=page.locator('[name=CustomSex]');if(await field.count()&&await field.isEnabled())await field.fill('Unspecified');});await session.goto('/Scenes/SceneCharactersEditor?sceneId='+first);await session.post('/Scenes/SaveSceneCharacters',{SceneID:first,'NewCharacter.CharacterID':who,...(place?{'NewCharacter.LocationID':place}:{})});}
stage='floor plan forms';await session.goto('/FloorPlans?projectId='+project);await p.locator('[name=Name]').fill('Acceptance house');await p.locator('[name=LocationID]').selectOption(String(a));await p.locator('form[action="/FloorPlans/Create"] button[type=submit]').click();await p.waitForURL('**/FloorPlans/Edit/*');const plan=Number(new URL(p.url()).pathname.split('/').at(-1));
for(const [name,order]of [['Upper',1]]){await session.post('/FloorPlans/AddFloor',{FloorPlanID:plan,Name:name,SortOrder:order,GridWidth:18,GridHeight:14});}
await session.goto('/FloorPlans/Edit/'+plan);const floors=await p.locator('[data-floor-panel]').evaluateAll(ns=>ns.map(n=>Number(n.dataset.floorPanel)));assert.equal(floors.length,2);
for(const [i,place] of places.entries()){await session.post('/FloorPlans/AddBlock',{floorPlanId:plan,FloorPlanFloorID:floors[i===3?1:0],LocationID:place,X:i===1?7:1,Y:i===2?7:1,WidthCells:5,HeightCells:4,BlockType:'Room'});}
async function relationship(from,to,flags,id){await session.goto('/Locations/Details/'+from);const type=await p.locator('#LocationRelationshipTypeID option').evaluateAll(ns=>ns.find(n=>Number(n.value)>0)?.value);assert.ok(type);await session.post('/Locations/AddRelationship',{ProjectID:project,FromLocationID:from,ToLocationID:to,LocationRelationshipTypeID:type,...(id?{LocationRelationshipID:id}:{}),...flags});}
stage='saved directional relationships';await relationship(a,b,{CanSeeMovement:true});await relationship(a,c,{CanHearNormalSpeech:true});await relationship(b,a,{CanSeeClearly:true,CanHearLoudNoise:true});
const feature=`/Writing/Context?projectId=${project}&bookId=${book}&chapterId=${chapter}&sceneId=${first}&pinned=true`,ctx=await p.context().newPage();await ctx.goto('https://dev.plotdirector.com'+feature);await ctx.selectOption('[data-context-pane="0"] [data-context-tab]','floorplans');const room=place=>ctx.locator(`[data-block][data-location-id="${place}"]`);
stage='scene floor, read-only and whereabouts';await room(a).waitFor();await ctx.waitForFunction(a=>document.querySelector(`[data-block][data-location-id="${a}"]`)?.classList.contains('spatial-selected'),a);assert.equal(await ctx.locator('[data-spatial-floor]').inputValue(),String(floors[0]));assert.equal(await ctx.locator('[data-spatial-place]').count(),0);assert.equal(await ctx.locator('.spatial-character-marker').count(),1);assert.match(await ctx.locator('[data-spatial-characters]').textContent(),/Unlocated Guest.*Location unknown/);assert.equal(await ctx.getByLabel('Visibility',{exact:true}).isChecked(),false);assert.equal(await ctx.getByLabel('Audibility',{exact:true}).isChecked(),false);
const posts=[];ctx.on('request',r=>{if(r.method()==='POST')posts.push(new URL(r.url()).pathname);});const focus=await ctx.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position}));
stage='overlays and direction';await ctx.getByLabel('Visibility',{exact:true}).check();await ctx.getByLabel('Audibility',{exact:true}).check();await ctx.waitForFunction(b=>document.querySelector(`[data-location-id="${b}"].spatial-visible`),b);assert.equal(await room(c).evaluate(n=>n.classList.contains('spatial-audible')),true);await room(b).click();await ctx.waitForFunction(a=>document.querySelector(`[data-location-id="${a}"].spatial-both`),a);assert.equal(await room(c).evaluate(n=>n.classList.contains('spatial-audible')),false);
stage='floor browsing and zoom';await ctx.locator('[data-spatial-floor]').selectOption(String(floors[1]));await ctx.locator('[data-spatial-zoom=in]').click();const view=await ctx.locator('[data-spatial-floor-world]').evaluate(n=>n.style.transform);assert.deepEqual(await ctx.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position})),focus);assert.deepEqual(posts,[]);
stage='held plan save refresh';await ctx.waitForFunction(()=>document.querySelector('[data-context-workspace]').contextController.connection?.state==='Connected');const old=await ctx.locator('[data-spatial-floor-canvas]').elementHandle();await session.goto('/FloorPlans/Edit/'+plan);await session.post('/FloorPlans/SavePlan',{FloorPlanID:plan,ProjectID:project,LocationID:a,Name:'Acceptance house saved'});await ctx.waitForFunction(n=>!n.isConnected,old);await ctx.locator('[data-spatial-resource] option').filter({hasText:'Acceptance house saved'}).waitFor({state:'attached'});assert.equal(await ctx.locator('[data-spatial-floor]').inputValue(),String(floors[1]));assert.equal(await ctx.locator('[data-spatial-floor-world]').evaluate(n=>n.style.transform),view);assert.equal(await room(b).evaluate(n=>n.classList.contains('spatial-selected')),true);
stage='held relationship save refresh';await ctx.locator('[data-spatial-floor]').selectOption(String(floors[0]));await room(a).click();await ctx.waitForFunction(b=>document.querySelector(`[data-location-id="${b}"].spatial-visible`),b);await session.goto('/Locations/Details/'+a);const relation=await p.evaluate(async ({book,first,a,b})=>{const data=await(await fetch(`/SpatialContext/State?bookId=${book}&sceneId=${first}&locationId=${a}`)).json();return data.sensoryRelationships.find(r=>r.fromLocationID===a&&r.toLocationID===b).locationRelationshipID;},{book,first,a,b});assert.ok(relation);await relationship(a,b,{CanSeeMovement:true,CanHearLoudNoise:true},relation);await ctx.waitForFunction(b=>document.querySelector(`[data-location-id="${b}"].spatial-both`),b);
stage='scene following';await ctx.selectOption('[data-context-scene]',String(second));await ctx.waitForFunction(d=>document.querySelector(`[data-location-id="${d}"].spatial-selected`),d);assert.equal(await ctx.locator('[data-spatial-floor]').inputValue(),String(floors[1]));
stage='split themes and narrow';await ctx.selectOption('[data-context-layout]','columns');await ctx.selectOption('[data-context-pane="1"] [data-context-tab]','floorplans');await ctx.locator('[data-context-pane="1"] [data-spatial-floor-canvas]').waitFor();for(const theme of ['plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue'])await ctx.evaluate(t=>{localStorage.setItem('plotdirector.applicationTheme',t);window.dispatchEvent(new StorageEvent('storage',{key:'plotdirector.applicationTheme',newValue:t}));},theme);await ctx.setViewportSize({width:460,height:850});assert.equal(await ctx.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1),true);
stage='main editor navigation';await session.goto('/Locations/Details/'+a);await p.waitForFunction(()=>window.PlotDirectorPresenceConnection?.state==='Connected');const url=ctx.url();await ctx.locator('[data-context-pane="0"] [data-spatial-advanced]').click();await p.waitForURL('**/FloorPlans/Edit/'+plan+'*');assert.equal(ctx.url(),url);
await session.close();session=await open();p=session.page;stage='fresh login persistence';await session.goto(feature);await p.selectOption('[data-context-pane="0"] [data-context-tab]','floorplans');await p.locator('[data-spatial-resource] option').filter({hasText:'Acceptance house saved'}).waitFor({state:'attached'});await p.getByLabel('Visibility',{exact:true}).check();await p.getByLabel('Audibility',{exact:true}).check();await p.waitForFunction(b=>document.querySelector(`[data-location-id="${b}"].spatial-both`),b);
console.log(JSON.stringify({passed:true,checks:['saved scene floor and room','explicit room initials and unknown presence list','default-off directional visibility/audibility/both','read-only local browsing preserves focus','held plan and relationship saves refresh preserving selection floor viewport','scene follows floor','split narrow and seven themes','main editor navigation','fresh-login server persistence'],featureUrl:'https://dev.plotdirector.com'+feature}));
}catch(error){console.error('Floor Plans acceptance failed at '+stage+' ('+error.name+'); no credentials logged.');if(error.name==='AssertionError')console.error(error.message);process.exitCode=1;}
finally{if(session){try{await session.cleanup();console.log('PASS disposable project cleanup');}catch{console.error('Cleanup incomplete; preserve journal.');process.exitCode=1;}finally{await session.close();}}}
})();