Keep Maps workspace commands accessible in the PWA ribbon

This commit is contained in:
Nick Beckley 2026-11-02 21:09:54 +00:00
parent 78e80569dd
commit 1e8e816166
6 changed files with 11 additions and 7 deletions

View File

@ -22,7 +22,7 @@ const base=process.env.PD_MAPS_STAGE3_URL||'http://127.0.0.1:5251';
await detached.evaluate(()=>{const token=new URLSearchParams(location.search).get('workspace'),c=new BroadcastChannel('pd-workspace:1:7:'+token);c.postMessage({uid:999,projectID:7,sender:crypto.randomUUID(),sequence:1,type:'scene-selected',payload:{sceneID:30}});c.close();});
await main.evaluate(()=>new Promise(resolve=>setTimeout(resolve,100)));assert.equal(await main.evaluate(()=>window.PlotDirectorStoryOverlay.state.lens),'character');
async function edit(page,name){await page.evaluate(()=>{const w=window.PlotDirectorMapWorkspace;w.setMode('create');w.select(w.document.features[0].featureID);});await page.locator('[data-field=name]').fill(name);await page.locator('[data-field=name]').blur();}
await edit(detached,'Detached unsaved geography');await main.evaluate(()=>window.PlotDirectorStoryOverlay.chooseScene(30));assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.mode),'create');assert.equal(await detached.locator('[data-field=name]').inputValue(),'Detached unsaved geography');
await edit(detached,'Detached unsaved geography');const windows=context.pages().length;await main.evaluate(()=>document.getElementById('mapsDetach').click());assert.equal(context.pages().length,windows,'Repeated Detach focuses the existing dirty workspace');assert(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.dirty));await main.evaluate(()=>window.PlotDirectorStoryOverlay.chooseScene(30));assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.mode),'create');assert.equal(await detached.locator('[data-field=name]').inputValue(),'Detached unsaved geography');
await edit(main,'Main saved geography');assert(await main.evaluate(()=>window.PlotDirectorMapWorkspace.save()));await detached.waitForFunction(()=>document.getElementById('mapsStatus').textContent.includes('another window'));
assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.save()),false);assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.dirty),true);assert.equal(await detached.locator('[data-field=name]').inputValue(),'Detached unsaved geography');assert.equal(revision,13);
await detached.evaluate(()=>{void window.PlotDirectorMapWorkspace.requestLeave(()=>{});});await detached.getByRole('button',{name:'Discard changes',exact:true}).click();await main.close();

View File

@ -11,10 +11,10 @@ if(identity.Database!=='PlotDirector_Development'||!identity.Email.startsWith('p
const context=await browser.newContext({viewport:{width:1800,height:1100},storageState:await signedIn.storageState()});if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
const page=await context.newPage();page.setDefaultTimeout(20000);page.on('pageerror',e=>errors.push(e.message));page.on('dialog',d=>{errors.push('Unexpected browser dialog: '+d.type());d.dismiss();});
await page.goto(root);await page.waitForFunction(()=>!!window.PlotDirectorMapWorkspace);const canvas=page.locator('#mapsCanvas');
async function command(id){await page.evaluate(id=>document.getElementById(id).click(),id);}
async function command(id){const proxy=page.locator(`[data-pwa-context-controls] [data-command-identity="handler:${id}"]`);if(pwa&&await proxy.count()){const menu=proxy.locator('xpath=ancestor::details[1]');if(await menu.count()&&await menu.getAttribute('data-compact')==='true'&&await menu.getAttribute('open')===null)await menu.locator(':scope > summary').click();await proxy.click();}else await page.evaluate(id=>document.getElementById(id).click(),id);}
async function drag(selector,dx,dy){const b=await page.locator(selector).first().boundingBox();assert(b);await page.mouse.move(b.x+b.width/2,b.y+b.height/2);await page.mouse.down();await page.mouse.move(b.x+b.width/2+dx,b.y+b.height/2+dy,{steps:5});await page.mouse.up();}
const added=[];for(const type of ['Land Mass','Forest','Road','Railway','River','Canal']){await page.locator('#mapsAssetSearch').fill(type);await page.locator(`[data-asset="${type}"]`).click();await canvas.click({position:{x:330,y:280}});added.push(await page.evaluate(()=>window.PlotDirectorMapWorkspace.document.features.at(-1).featureID));await page.locator('[data-action=shape]').click();for(let i=0;i<3;i++)await drag('[data-handle=point]',i%2?8:-8,5);assert.equal(await page.evaluate(()=>getSelection().toString()),'');if(['Road','Railway','River','Canal'].includes(type))await drag('[data-handle=endpoint]',25,35);}
await page.evaluate(id=>window.PlotDirectorMapWorkspace.select(id),added[0]);const rotate=page.locator('input[type=range][data-rotate]');await rotate.fill('35');await command('mapsUndo');await command('mapsRedo');
await page.evaluate(id=>window.PlotDirectorMapWorkspace.select(id),added[0]);const rotate=page.locator('input[type=range][data-rotate]');await rotate.fill('35');await command('mapsUndo');await command('mapsRedo');await page.evaluate(id=>window.PlotDirectorMapWorkspace.select(id),added[0]);
await page.locator('[data-field=isLocked]').check();const view=await page.evaluate(()=>({...window.PlotDirectorMapWorkspace.view}));
// Protect all overlapping fixture shapes through the canonical multi-selection menu.
await page.evaluate(ids=>{const w=window.PlotDirectorMapWorkspace;ids.forEach((id,i)=>w.select(id,i>0));},added);await command('mapsContext');assert.equal(await page.locator('.pd-context-popup').count(),1);await page.getByRole('menuitem',{name:'Lock position',exact:true}).click();await canvas.click({position:{x:330,y:280},button:'right'});assert.equal(await page.locator('.pd-context-popup').count(),1);await page.locator('.pd-context-popup').hover();await page.keyboard.press('Escape');
@ -28,11 +28,12 @@ if(identity.Database!=='PlotDirector_Development'||!identity.Email.startsWith('p
const names=await page.locator('#mapStoryCharacter1 option').allTextContents();assert.deepEqual(names.slice(1),names.slice(1).sort((a,b)=>a.localeCompare(b,undefined,{sensitivity:'base'})));
const popup=page.waitForEvent('popup');await command('mapsDetach');const detached=await popup;detached.setDefaultTimeout(20000);detached.on('pageerror',e=>errors.push(e.message));await detached.waitForFunction(()=>!!window.PlotDirectorStoryOverlay?.data);assert.equal(await detached.locator('.pd-application-header').count(),0);assert.equal(await detached.locator('.public-footer').count(),0);assert.equal(await detached.locator('.maps-toolbar:visible').count(),1);assert(await detached.locator('#mapsDetach').isHidden());
await page.evaluate(id=>window.PlotDirectorStoryOverlay.chooseScene(id),f.SceneAID);await detached.waitForFunction(id=>window.PlotDirectorStoryOverlay.state.sceneID===id,f.SceneAID);await detached.evaluate(id=>window.PlotDirectorStoryOverlay.chooseScene(id),f.SceneBID);await page.waitForFunction(id=>window.PlotDirectorStoryOverlay.state.sceneID===id,f.SceneBID);
await page.evaluate(id=>window.PlotDirectorStoryOverlay.chooseScene(id),f.DetailSceneID);await page.locator(`#mapsDetailContent a[href*="id=${f.ChildMapID}&mode=story"]`).click();await page.waitForFunction(id=>window.PlotDirectorMapWorkspace?.document?.map.mapID===id,f.ChildMapID);await detached.waitForFunction(id=>window.PlotDirectorMapWorkspace?.document?.map.mapID===id,f.ChildMapID);assert.equal(new URL(detached.url()).searchParams.get('detached'),'true');await page.locator(`#mapsBreadcrumbs a[href*="id=${f.MapID}&mode=story"]`).click();await page.waitForFunction(id=>window.PlotDirectorMapWorkspace?.document?.map.mapID===id,f.MapID);await detached.waitForFunction(id=>window.PlotDirectorMapWorkspace?.document?.map.mapID===id,f.MapID);await page.waitForFunction(()=>!!window.PlotDirectorStoryOverlay?.data);await detached.waitForFunction(()=>!!window.PlotDirectorStoryOverlay?.data);
const storyAfter=await(await context.request.get(`${base}/Maps/State?projectId=${f.ProjectID}&id=${f.MapID}`)).json();assert.deepEqual(storyAfter,storyBefore);
async function edit(p,name){await p.evaluate(()=>{const w=window.PlotDirectorMapWorkspace;w.setMode('create');w.select(w.document.features[0].featureID);});await p.locator('[data-field=name]').fill(name);await p.locator('[data-field=name]').blur();}
await edit(detached,'Detached retained edit '+pwa);await edit(page,'Main saved edit '+pwa);assert(await page.evaluate(()=>window.PlotDirectorMapWorkspace.save()));assert.equal(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.save()),false);assert(await detached.evaluate(()=>window.PlotDirectorMapWorkspace.dirty));assert.match(await detached.locator('#mapsStatus').innerText(),/changed|another|reload/i);
// Real optimistic conflict also prevents a pending navigation from continuing.
await detached.evaluate(()=>document.getElementById('mapsNew').click());await detached.getByRole('button',{name:'Save and continue',exact:true}).click();assert(await detached.locator('#pdApplicationDialog [data-dialog-error]').isVisible());assert(await detached.locator('#mapsNewDialog').isHidden());await detached.getByRole('button',{name:'Discard changes',exact:true}).click();await detached.locator('#mapsNewDialog').waitFor();await detached.locator('#mapsNewCancel').click();
await detached.evaluate(()=>document.getElementById('mapsNew').click());await detached.getByRole('button',{name:'Save and continue',exact:true}).click();await detached.locator('#pdApplicationDialog [data-dialog-error]').waitFor();assert(await detached.locator('#mapsNewDialog').isHidden());await detached.getByRole('button',{name:'Discard changes',exact:true}).click();await detached.locator('#mapsNewDialog').waitFor();await detached.locator('#mapsNewCancel').click();
await page.close();await detached.evaluate(()=>window.PlotDirectorMapWorkspace.setMode('story'));await detached.evaluate(id=>window.PlotDirectorStoryOverlay.chooseScene(id),f.SceneAID);await detached.getByRole('link',{name:'Open / edit scene',exact:true}).click();await detached.waitForURL('**/Scenes/Edit/'+f.SceneAID);assert(await detached.locator('main').isVisible());
const denied=await context.request.get(`${base}/Maps?projectId=${f.ProjectID}&id=-1&detached=true`);assert.equal(denied.status(),404);const csrf=await context.request.post(`${base}/Maps/Save`,{data:storyBefore});assert.equal(csrf.status(),400);
console.log(`PASS live Development Maps Stage 3 ${pwa?'PWA':'web'}: repeated land/forest/path drags, transforms/rotation/undo, canonical menus/locked pan/maximise, unsaved modal, real save/conflict, scrubber/characters, minimal detached shell/sync/closed-opener scene navigation, auth/CSRF and Story geography immutability`);await context.close();

View File

@ -27,7 +27,7 @@ const base=process.env.PD_MAPS_STAGE3_URL||'http://127.0.0.1:5251';
// Discard the retained edits deliberately, then test manipulation without native dialogs.
await page.evaluate(()=>{void window.PlotDirectorMapWorkspace.requestLeave(()=>{});});await modal.getByRole('button',{name:'Discard changes',exact:true}).click();await modal.waitFor({state:'detached'});
async function place(type){await page.locator('#mapsAssetSearch').fill(type);await page.locator(`[data-asset="${type}"]`).click();await page.locator('#mapsCanvas').click({position:{x:280,y:280}});return await page.evaluate(()=>window.PlotDirectorMapWorkspace.document.features.at(-1).featureID);}
console.log('Manipulation tests');const road=await place('Road');assert.equal(await page.locator('[data-handle=endpoint]').count(),2);
console.log('Manipulation tests');if(pwa)assert(await page.locator('[data-pwa-context-controls] .pd-context-group[aria-label=Workspace]').isVisible(),'Workspace ribbon group must retain Detach/Map menu while Maximise is hidden');const road=await place('Road');assert.equal(await page.locator('[data-handle=endpoint]').count(),2);
async function dragHandle(selector,dx,dy){const b=await page.locator(selector).first().boundingBox();await page.mouse.move(b.x+b.width/2,b.y+b.height/2);await page.mouse.down();await page.mouse.move(b.x+b.width/2+dx,b.y+b.height/2+dy,{steps:6});await page.mouse.up();}
const before=await page.evaluate(id=>JSON.stringify(window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id)),road);
await dragHandle('[data-handle=endpoint]',45,65);const transformed=await page.evaluate(id=>JSON.stringify(window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id)),road);assert.notEqual(transformed,before);await command('mapsUndo');assert.equal(await page.evaluate(id=>JSON.stringify(window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id)),road),before);await command('mapsRedo');assert.equal(await page.evaluate(id=>JSON.stringify(window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id)),road),transformed);

View File

@ -45,6 +45,7 @@ const base=process.env.PD_MAPS_STORY_TEST_URL||'http://127.0.0.1:5247';
const previous=new Map();fixture.legs=[];for(const stop of fixture.stops){const p=previous.get(stop.characterID);if(p)fixture.legs.push({characterID:stop.characterID,fromSceneID:p.sceneID,toSceneID:stop.sceneID,from:p.position,to:stop.position,evidenceLevel:0,timingObservation:false});previous.set(stop.characterID,stop);}
await page.evaluate(()=>window.PlotDirectorMapWorkspace.setMode('story'));await page.evaluate(()=>window.PlotDirectorStoryOverlay.refresh());await page.waitForFunction(()=>window.PlotDirectorStoryOverlay.data.scenes.length===500);await choose('mapStoryLens','scene');await choose('mapStoryScene',1499);assert.match(await page.locator('#mapsDetailContent').innerText(),/Scene 499/);
const elapsed=await page.evaluate(()=>{const start=performance.now();for(let i=0;i<50;i++)window.PlotDirectorStoryOverlay.chooseScene(1000+i);return performance.now()-start;});assert(elapsed<5000,'scene navigation remains practical with 500 scenes/5,000 appearances');
const scrubMs=await page.evaluate(async()=>{const input=document.getElementById('mapStoryScrubber'),start=performance.now();for(let i=0;i<100;i++){input.value=String(i*5);input.dispatchEvent(new Event('input',{bubbles:true}));if(i%10===9)await new Promise(requestAnimationFrame);}input.dispatchEvent(new Event('change',{bubbles:true}));return performance.now()-start;});assert(scrubMs<5000);assert.equal(await page.evaluate(()=>window.PlotDirectorStoryOverlay.state.sceneID),1495,'rapid scrubber input settles at the canonical requested scene');
await choose('mapStoryLens','character');await choose('mapStoryCharacter1',1);await choose('mapStoryCharacter2',2);assert(await page.locator('.maps-story-leg').count()<=4,'repeated movements aggregate their lines while preserving individual stops/leg Details');
assert.equal(geographyWrites,0);assert.equal(await page.evaluate(()=>JSON.stringify(window.PlotDirectorMapWorkspace.document)),geography);console.log(`Maps Story ${pwa?'PWA':'web'} scale: 500 scenes, 5,000 appearances; 50 scene changes in ${elapsed.toFixed(0)}ms.`);
assert.deepEqual(errors,[]);console.log(`PASS Maps Story ${pwa?'PWA':'web'}: six lenses, manuscript navigation, repeated visits/comparison, travel context, evidence, hierarchy/Floor Plan links, honest gaps, stable keyed canvas and unchanged geography/revision`);await context.close();

File diff suppressed because one or more lines are too long

View File

@ -129,7 +129,7 @@
if(!html&&selection.kind==='feature'&&featureID){const feature=W.document.features.find(f=>f.featureID===featureID),scopeIDs=new Set(selected.map(s=>s.sceneID)),physical=data.stops.filter(s=>s.position.featureID===featureID&&scopeIDs.has(s.sceneID)),physicalScenes=new Set(physical.map(s=>s.sceneID)),used=selected.filter(s=>s.position.featureID===featureID||physicalScenes.has(s.sceneID)),location=boot.locations.find(l=>l.locationID===feature?.locationID),stops=physical.filter(s=>state.characterIDs.includes(s.characterID));html=`<h3>${esc(feature?.name)}</h3><p>${feature?.isProvisional?'◇ Planning map piece':'Established map piece'}${location?' · linked story Location':''}</p>${location?.description?`<p>${esc(location.description)}</p>`:''}<p>${used.length} scenes in the current scope. ${used.length===0&&feature?.locationID?'No scenes in this scope use this Location.':''}</p><p>Chapters: ${new Set(used.map(s=>s.chapterID)).size}<br/>Characters: ${esc([...new Set(physical.map(s=>s.characterID))].map(id=>people.get(id)?.name).filter(Boolean).join(', ')||'None recorded')}<br/>Plot Lines: ${esc([...new Set(used.flatMap(s=>s.plotLineIDs))].map(id=>data.plotLines.find(p=>p.plotLineID===id)?.plotLineName).filter(Boolean).join(', ')||'None recorded')}</p>${used.length?`<p>First: ${esc(sceneLabel(used[0]))}<br/>Last: ${esc(sceneLabel(used.at(-1)))}</p>`:''}${locationLinks({locationID:feature?.locationID,floorPlanID:feature?.floorPlanID,detailMapID:boot.maps.find(m=>m.parentMapID===W.document.map.mapID&&m.parentFeatureID===featureID)?.mapID,status:'Detail map'})}<div class="maps-story-list">${(state.lens==='character'?stops.map(stop=>sceneButton(scenes.get(stop.sceneID),`${people.get(stop.characterID)?.name} · stop ${stop.sequence} · ${sceneLabel(scenes.get(stop.sceneID))}`,stop.characterID)):used.map(s=>sceneButton(s))).join('')}</div>`;}
if(!html&&state.lens==='character'){
const stops=E.journeys(data,state.characterIDs,selected);html='<h3>Character journeys</h3><p>Choose up to three characters. Letters A/B/C, stop numbers and different line patterns distinguish their journeys. Repeated visits retain their sequence. Unknown stops break the drawn journey.</p>';
for(const[idIndex,id]of state.characterIDs.entries()){const visits=stops.filter(s=>s.characterID===id);html+=`<h4>${String.fromCharCode(65+idIndex)} · ${esc(people.get(id)?.name)}</h4><p>${new Set(visits.map(s=>s.position.locationID).filter(Boolean)).size} known Locations · ${visits.filter(s=>s.position.status==='Unmapped').length} unmapped stops · ${visits.filter(s=>!s.position.locationID).length} unknown stops</p><ol>${visits.map(s=>`<li><button type="button" data-story-scene="${s.sceneID}" data-story-person="${id}">${s.sequence}. ${esc(s.position.locationName||'Unknown')} · ${esc(s.position.status)} · ${esc(scenes.get(s.sceneID)?.sceneTitle)}</button></li>`).join('')}</ol><div class="maps-story-list">${data.legs.filter(l=>l.characterID===id&&visits.some(v=>v.sceneID===l.fromSceneID)&&visits.some(v=>v.sceneID===l.toSceneID)).map(l=>`<button type="button" data-story-leg="${l.characterID}:${l.fromSceneID}:${l.toSceneID}">Journey leg: ${esc(l.from.locationName||'Unknown')} → ${esc(l.to.locationName||'Unknown')} · ${esc(scenes.get(l.toSceneID)?.sceneTitle)}</button>`).join('')}</div>`;}
for(const[idIndex,id]of state.characterIDs.entries()){const visits=stops.filter(s=>s.characterID===id);html+=`<h4>${String.fromCharCode(65+idIndex)} · ${esc(people.get(id)?.name)}</h4><p>${new Set(visits.map(s=>s.position.locationID).filter(Boolean)).size} known Locations · ${visits.filter(s=>s.position.status==='Unmapped').length} unmapped stops · ${visits.filter(s=>!s.position.locationID).length} unknown stops</p><ol role="list">${visits.map(s=>`<li><button type="button" data-story-scene="${s.sceneID}" data-story-person="${id}">${s.sequence}. ${esc(s.position.locationName||'Unknown')} · ${esc(s.position.status)} · ${esc(scenes.get(s.sceneID)?.sceneTitle)}</button></li>`).join('')}</ol><div class="maps-story-list">${data.legs.filter(l=>l.characterID===id&&visits.some(v=>v.sceneID===l.fromSceneID)&&visits.some(v=>v.sceneID===l.toSceneID)).map(l=>`<button type="button" data-story-leg="${l.characterID}:${l.fromSceneID}:${l.toSceneID}">Journey leg: ${esc(l.from.locationName||'Unknown')} → ${esc(l.to.locationName||'Unknown')} · ${esc(scenes.get(l.toSceneID)?.sceneTitle)}</button>`).join('')}</div>`;}
}
if(!html&&state.lens==='time'){const positions=E.timePositions(data,state.at,state.characterIDs,state.bookID);html='<h3>Last known geography</h3><p>Confirmed dated evidence only. No positions are interpolated between scenes. Date-only appearances cannot establish an intraday position. Undated / estimated appearances are not positioned in time.</p>'+(!state.at?'<p>No confirmed dated events in this scope.</p>':`<p>As of ${esc(state.at.replace('T',' '))}. ${state.characterIDs.length?'Selected characters':'Markers show up to eight significant characters; the list includes everyone'}.</p>`)+positions.map(p=>`<h4>${esc(p.character.name)}</h4><p>${p.position?'Last known: '+esc(p.position.locationName)+' · '+esc(p.position.status):'Unknown'}${p.scene?' · '+esc(dateLabel(p.scene)):''}</p><p class="maps-hint">${esc(p.reason)}</p>${p.scene?sceneButton(p.scene,'Inspect evidence: '+p.scene.sceneTitle):''}${p.position?locationLinks(p.position,p.scene):''}`).join('');}
if(!html&&state.lens==='scene'){const s=scenes.get(state.sceneID);html=s?sceneDetails(s):'<p>No scenes in this scope.</p>';}