diff --git a/Docs/Maps/GeographicalRepositioning.md b/Docs/Maps/GeographicalRepositioning.md new file mode 100644 index 00000000..04b4747b --- /dev/null +++ b/Docs/Maps/GeographicalRepositioning.md @@ -0,0 +1,38 @@ +# Hierarchy-aware geographical repositioning + +## Cause and scope + +The former operation projected only resolved Marker features. It neither followed canonical Location parents nor changed road frames/control points. Road rendering substitutes the current anchor coordinates for the first/last normalized point, so moving settlements alone pulled endpoints away from bends left in the original frame. + +The geographical projection, provider, queue, cache and confirmation rules are unchanged. This enhancement extends the pure proposed-map calculation. No database migration or new parent/road relationship is introduced. + +## Canonical hierarchy + +`Geography/State?includeHierarchy=true` returns current resolutions plus the project's Location IDs, names and ParentLocationIDs through the existing repositories and access checks. Default callers still receive the original state array. Each preview loads this hierarchy rather than depending on an old Maps-page snapshot. + +Resolved unlocked pieces with valid coordinates participate directly, including explicitly associated areas and unanchored paths. Endpoint-anchored paths use their existing anchors instead of acquiring independent geographical references. Non-authoritative descendants walk their existing Location parent chain to the nearest participating geographical ancestor and inherit that ancestor's canvas displacement. Unmapped intermediate parents are supported. Each piece is moved once, so mapped intermediate descendants do not compound the displacement. A child with its own authoritative coordinates is positioned independently. + +Cycles, missing hierarchy entries and several map anchors for one ancestor with conflicting displacements are reported; those descendants stay unchanged. Locked pieces remain locked and stationary. A nearer locked geographical ancestor is not bypassed to inherit a more distant participant. Unassociated decoration is unchanged. No proximity or derived geometric-containment relationship is used as a substitute for story parents. + +## Curves and areas + +Path controls are normalized to the feature's X/Y, width/height and rotation; rendering replaces endpoint controls with anchor coordinates. The shared `connectionTransform` implements the similarity transform already used for free endpoint turn/extension. Geographical positioning uses it to map the entire rendered control polygon from the old to the new endpoint pair. Along-line proportions and perpendicular offsets scale/rotate together. Equal endpoint displacements produce a translation; one moving endpoint leaves the other fixed. + +The transformed polygon is stored back in the existing frame/points representation. The label reference point follows the same transform, with its offsets adjusted for the normalised frame. Coincident or near-zero endpoint separation has no unique orientation; the fallback blends endpoint displacements along control-point order while retaining bends. Non-finite/out-of-range geometry or a locked path whose endpoints would move blocks the entire Apply operation. Existing paths are individual segments with at most a start/end anchor; adjoining segments transform through their shared anchors. There is no new per-control-point anchoring model. + +Settlement boundaries remain offsets relative to their authoritative anchor, so moving the whole settlement translates its boundary without changing controls, smoothing or styling. Associated forests/lakes/buildings inherit only displacement. Their shapes and local canvas offsets are not geographically scaled. Manual map movement keeps its previous independent-object behaviour. + +## Preview and persistence + +One pure calculation returns the entire proposed feature array, direct and inherited movements, transformed paths, unchanged counts and attention items. The preview renders that array through the normal scene, including drawing-order overrides and overlays. Apply assigns that same array with one existing Undo checkpoint; it does not recalculate. Cancel leaves the live document unchanged. Redo and the normal revision-protected Save preserve the complete operation. Existing GeometryJson storage and project export/import/backup/restore carry transformed curves and boundaries. + +## Verification + +- Build and executable regression harness use the repository's normal gates. +- `node PlotLine.Tests/Browser/maps-geography-hierarchy-engine.cjs`: hierarchy depth/nearest authority, independent children, mapped/unmapped intermediates, areas/decorations, duplicates/cycles/missing links, equal/different/single-moving endpoints, degenerate/reversed/rotated connections and atomic safety refusal. +- `node PlotLine.Tests/Browser/maps-geography-hierarchy.cjs`: normal/PWA and light/dark layouts; isolated Rubery/Frankley/Redditch/Barmouth scenario, exact preview/Apply geometry, Cancel, one-step Undo/Redo, Save contract/reopen and unchanged manual behaviour. +- Existing geography, Maps engine, settlement and drawing-order regressions cover compatibility. +- `--map-geography-hierarchy-database /tmp/pd-dev-browser-/identity.json`: verifies the effective Development database and disposable account, creates only its own unique project, tests complete transformed-map Save/reload and project backup/export/import/restore, then leaves that owned map at its original positions for browser acceptance. +- `node PlotLine.Tests/Browser/maps-geography-hierarchy-development.cjs /tmp/pd-dev-browser-/identity.json`: authenticated Development verification using the real hierarchy API and real Map Save/reload. Coordinates are explicit fixture responses; the test makes no external geocoder requests and does not modify provider/cache/resolution data. Standard disposable identity cleanup removes the fixtures. + +Tests never open the author's actual Birmingham map. Adding a distant place legitimately changes the projection scale; dependent objects preserve their requested local offsets rather than inventing physical distances or a new regional-map system. diff --git a/PlotLine.Tests/Browser/maps-geography-engine.cjs b/PlotLine.Tests/Browser/maps-geography-engine.cjs index c66ef4c7..75d0b2d6 100644 --- a/PlotLine.Tests/Browser/maps-geography-engine.cjs +++ b/PlotLine.Tests/Browser/maps-geography-engine.cjs @@ -10,8 +10,8 @@ assert(r.features[1].yr.f const north=r.features[0].y-r.features[1].y,east=r.features[2].x-r.features[0].x; assert(Math.abs(east/north-Math.cos(52*Math.PI/180))<.002,'geographical distance ratio and a single aspect scale'); for(const p of r.features.slice(0,3)){assert(p.x>=80&&p.x<=1120);assert(p.y>=80&&p.y<=720);} -assert.deepEqual(r.features.slice(3),fs.slice(3),'locks, paths and unrelated drawings remain byte-equivalent'); -assert.equal(r.skipped.length,2); +assert.deepEqual(r.features[3],fs[3],'locks remain byte-equivalent');assert.deepEqual(r.features[5],fs[5],'unassociated decorations remain byte-equivalent');assert.notDeepEqual(r.features[4],fs[4],'an explicitly located unanchored path can use its own geographical coordinates'); +assert.equal(r.skipped.length,1); for(const coords of [[[52,0]],[[52,0],[52,0]],[[52,0],[52,1]],[[0,179.9],[0,-179.9]],[[89,0],[89,1]]]){ const result=position(coords.map((_,i)=>marker(i+1)),coords.map((p,i)=>state(i+1,...p)),box); assert(result.features.every(p=>Number.isFinite(p.x)&&Number.isFinite(p.y)),'single/two/coincident/antimeridian/polar points finite'); diff --git a/PlotLine.Tests/Browser/maps-geography-hierarchy-development.cjs b/PlotLine.Tests/Browser/maps-geography-hierarchy-development.cjs new file mode 100644 index 00000000..91b704f4 --- /dev/null +++ b/PlotLine.Tests/Browser/maps-geography-hierarchy-development.cjs @@ -0,0 +1,23 @@ +// Explicit authenticated Development acceptance; requires the disposable database fixture from --map-geography-hierarchy-database. +const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path'); +const identityPath=process.argv[2];if(!identityPath?.startsWith('/tmp/pd-dev-browser-'))throw Error('Dedicated Development identity required.'); +const identity=JSON.parse(fs.readFileSync(identityPath,'utf8')),fixture=JSON.parse(fs.readFileSync(path.join(path.dirname(identityPath),'hierarchy-fixture.json'),'utf8')); +if(identity.Database!=='PlotDirector_Development'||!identity.Email.startsWith('pwa-browser-'))throw Error('Wrong account scope.'); +const base='https://dev.plotdirector.com'; +(async()=>{const browser=await chromium.launch();try{ + const context=await browser.newContext({viewport:{width:1700,height:1150}}),page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message)); + await page.goto(base+'/Account/Login');await page.locator('#Email').fill(identity.Email);await page.locator('#Password').fill(identity.Password);await Promise.all([page.waitForURL('**/Projects'),page.locator('form[action="/Account/Login"] button[type=submit]').click()]); + const response=await context.request.get(base+'/Geography/State?projectId='+fixture.projectId+'&includeHierarchy=true');assert.equal(response.status(),200);const live=await response.json();assert(Array.isArray(live.states)&&Array.isArray(live.locations),'deployed API supplies fresh hierarchy'); + const maggie=live.locations.find(l=>l.locationName==="Maggie's flat"),middle=live.locations.find(l=>l.locationName==='The Doweries'),rubery=live.locations.find(l=>l.locationName==='Rubery');assert.equal(maggie.parentLocationID,middle.locationID);assert.equal(middle.parentLocationID,rubery.locationID); + // Use bounded, explicit fixture coordinates without calling or modifying the provider/cache/resolution database. + await page.route('**/Geography/State?*',r=>r.fulfill({json:{states:fixture.states,locations:live.locations}})); + await page.goto(base+'/Maps?projectId='+fixture.projectId+'&id='+fixture.mapId);await page.waitForFunction(()=>!!window.PlotDirectorMapWorkspace); + const read=()=>page.evaluate(()=>JSON.stringify(window.PlotDirectorMapWorkspace.document.features)),before=await read(); + const expected=await page.evaluate(({states,locations})=>window.PlotDirectorGeography.position(window.PlotDirectorMapWorkspace.document.features,states,window.PlotDirectorMapWorkspace.view,locations),{states:fixture.states,locations:live.locations});assert(expected.canApply);assert.equal(expected.counts.paths,2);assert(expected.inherited.some(f=>f.name==="Maggie's flat"&&f.ancestor==='Rubery'&&f.via[0]==='The Doweries')); + const command=id=>page.evaluate(id=>document.getElementById(id).click(),id); + await command('mapsGeographic');await page.locator('#mapsGeographicDialog').waitFor({state:'visible'});assert.equal(await read(),before);await command('mapsGeographicCancel');assert.equal(await read(),before); + await command('mapsGeographic');await page.locator('#mapsGeographicDialog').waitFor({state:'visible'});const preview=await page.locator('#mapsScene').innerHTML();await command('mapsGeographicApply');assert.equal(await page.locator('#mapsScene').innerHTML(),preview);assert.deepEqual(JSON.parse(await read()),expected.features); + const applied=await read();await command('mapsUndo');assert.equal(await read(),before);await command('mapsRedo');assert.equal(await read(),applied); + await command('mapsSave');await page.waitForFunction(()=>document.getElementById('mapsStatus').textContent==='Saved');await page.reload();await page.waitForFunction(()=>!!window.PlotDirectorMapWorkspace);assert.equal(await read(),applied,'actual server Save and reload retain all positions, curves, boundaries and drawing order'); + assert.deepEqual(errors,[]);console.log('PASS authenticated Development hierarchy geography: real hierarchy endpoint, Barmouth proposal, descendants through unmapped parent, complete road/boundary preview, Cancel, one-step Undo/Redo, server Save/reload and preserved identities. Isolated project '+fixture.projectId);await context.close(); + }finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine.Tests/Browser/maps-geography-hierarchy-engine.cjs b/PlotLine.Tests/Browser/maps-geography-hierarchy-engine.cjs new file mode 100644 index 00000000..3b52a342 --- /dev/null +++ b/PlotLine.Tests/Browser/maps-geography-hierarchy-engine.cjs @@ -0,0 +1,30 @@ +const assert=require('node:assert/strict'),E=require('../../PlotLine/wwwroot/js/maps-engine.js'),G=require('../../PlotLine/wwwroot/js/maps-geography-engine.js'); +const box={x:-600,y:-400,w:1200,h:800},make=(type,id,locationID,x,y)=>Object.assign(E.makeFeature(type,x,y,id),{locationID,name:id,isProvisional:false}),state=(id,lat,lon)=>({locationID:id,status:'Resolved',matchJson:JSON.stringify({Latitude:lat,Longitude:lon})}); +const places=[{locationID:1,locationName:'Rubery'},{locationID:2,locationName:'The Doweries',parentLocationID:1},{locationID:3,locationName:"Maggie's flat",parentLocationID:2},{locationID:4,locationName:'Frankley'},{locationID:5,locationName:'Barmouth'},{locationID:6,locationName:'Forest',parentLocationID:1},{locationID:7,locationName:'Lake',parentLocationID:1},{locationID:8,locationName:'Own coordinates',parentLocationID:1}]; +const features=[make('Town','Rubery',1,100,80),make('Town','Frankley',4,600,200),make('Town','Barmouth',5,-300,-200),make('House','Maggie',3,120,90),make('Forest','forest',6,60,40),make('Lake','lake',7,105,95),make('House','own',8,99,99),make('House','decoration',null,500,500)]; +const road=make('Road','road',null,350,130);road.startFeatureID='Rubery';road.endFeatureID='Frankley';road.geometryJson=JSON.stringify({points:[[-.5,0],[-.1,.4],[.2,-.3],[.5,0]],drawingOrder:345678});features.push(road); +const states=[state(1,52.39,-2.016),state(4,52.41,-2.022),state(5,52.72,-4.05),state(8,52.4,-2.0)],before=JSON.stringify(features),r=G.position(features,states,box,places),find=(result,id)=>result.features.find(f=>f.featureID===id); +assert(r.canApply);assert.equal(places.find(l=>l.locationID===3).parentLocationID,2);assert.equal(places.find(l=>l.locationID===2).parentLocationID,1);assert.equal(JSON.stringify(features),before);const delta=[find(r,'Rubery').x-features[0].x,find(r,'Rubery').y-features[0].y]; +for(const id of ['Maggie','forest','lake']){const old=features.find(f=>f.featureID===id),next=find(r,id);assert(Math.abs(next.x-old.x-delta[0])<1e-8);assert(Math.abs(next.y-old.y-delta[1])<1e-8);assert.equal(next.geometryJson,old.geometryJson);} +assert.deepEqual(r.inherited.find(p=>p.name==='Maggie').via,['The Doweries']);assert.equal(find(r,'Rubery').geometryJson,features[0].geometryJson,'boundary/style/order remain relative to translated anchor');assert.deepEqual(find(r,'decoration'),features[7]);assert.notEqual(find(r,'own').x-features[6].x,delta[0]);assert.equal(r.counts.paths,1); +const oldPoints=E.pathPoints(road,features),nextPoints=E.pathPoints(find(r,'road'),r.features),transform=E.connectionTransform(oldPoints[0],oldPoints.at(-1),nextPoints[0],nextPoints.at(-1));for(let i=0;ia.name==='Maggie'));} +const deep=Array.from({length:180},(_,i)=>({locationID:20+i,locationName:'Level '+i,parentLocationID:i?19+i:1})),deepPiece=make('House','deep',199,10,15),deepResult=G.position([...features,deepPiece],states,box,[...places,...deep]);assert(Math.abs(find(deepResult,'deep').x-deepPiece.x-delta[0])<1e-7,'hierarchy inheritance has no shallow depth limit'); +const locked=E.copy(features);locked.find(f=>f.featureID==='road').isLocked=true;const blocked=G.position(locked,states,box,places);assert.equal(blocked.canApply,false);assert.deepEqual(blocked.features,locked,'unsafe locked connections prevent partial application'); +const duplicate=E.copy(features[0]);duplicate.featureID='second Rubery';duplicate.x+=20;const ambiguous=G.position([...features,duplicate],states,box,places);assert(ambiguous.attention.some(a=>a.name==='Maggie'&&a.reason.includes('several')));assert.deepEqual(find(ambiguous,'Maggie'),features[3]); +// Exact path cases, independent of geographical projection; frame and local coordinates are implementation details. +function pathCase(a,b,c,d){const start=make('Town','a',null,...a),end=make('Town','b',null,...b),p=make('Road','p',null,0,0);p.startFeatureID='a';p.endFeatureID='b';p.geometryJson=JSON.stringify({points:[[-.5,0],[-.1,.3],[.2,-.2],[.5,0]]});const old=[start,end,p],next=[{...start,x:c[0],y:c[1]},{...end,x:d[0],y:d[1]},p],q=E.transformAnchoredPath(p,old,next),points=E.pathPoints(q,next);assert.deepEqual(points[0],c);assert.deepEqual(points.at(-1),d);assert(points.flat().every(Number.isFinite));return {old:E.pathPoints(p,old),points,label:[q.x+q.labelX,q.y+q.labelY]};} +const translated=pathCase([0,0],[100,0],[30,-10],[130,-10]);assert(Math.hypot(translated.label[0]-30,translated.label[1]+10)<1e-7,'the road label translates with the curve despite frame normalization');translated.old.forEach((p,i)=>assert(Math.hypot(translated.points[i][0]-p[0]-30,translated.points[i][1]-p[1]+10)<1e-7)); +for(const args of [[[0,0],[100,0],[0,0],[200,100]],[[0,0],[100,0],[100,0],[0,0]],[[0,0],[100,0],[0,0],[0,100]],[[0,0],[0,0],[0,0],[100,0]],[[0,0],[.00001,0],[30,40],[30,40]],[[0,0],[100,0],[10,10],[10,10]]])pathCase(...args); +assert.throws(()=>pathCase([0,0],[.02,0],[0,0],[1000,0]),/safe|large/,'extreme separation changes cannot explode curve offsets'); +const short=make('Road','short',null,0,0);short.startFeatureID='Rubery';short.endFeatureID='Frankley';short.geometryJson=JSON.stringify({points:[[-.5,0],[.5,0]]});assert.equal(E.geometry(E.transformAnchoredPath(short,features,r.features)).points.length,2); +// Single anchored endpoint, stationary free end; no proximity-based attachment. +const single=E.copy(road);single.endFeatureID=null;const oldEnd=E.pathPoints(single,features).at(-1),singleNext=E.transformAnchoredPath(single,features,r.features);assert.deepEqual(E.pathPoints(singleNext,r.features).at(-1),oldEnd); +const invalid=E.copy(features);invalid.at(-1).endFeatureID='missing';const invalidResult=G.position(invalid,states,box,places);assert.equal(invalidResult.canApply,false);assert.deepEqual(invalidResult.features,invalid); +assert.throws(()=>E.transformAnchoredPath(road,features,[{...features[0],x:1e8},...features.slice(1)]),/safe|large/); +console.log('PASS hierarchy inheritance, unmapped intermediate, nearest authority, independent child, malformed/cyclic/duplicate hierarchy, boundary/area/decor preservation, complete atomic proposal, anchored similarities, single/multiple segments, degenerate/reversed/rotated paths and bounds.'); diff --git a/PlotLine.Tests/Browser/maps-geography-hierarchy-fixture.cjs b/PlotLine.Tests/Browser/maps-geography-hierarchy-fixture.cjs new file mode 100644 index 00000000..b91e2519 --- /dev/null +++ b/PlotLine.Tests/Browser/maps-geography-hierarchy-fixture.cjs @@ -0,0 +1,11 @@ +// Isolated persistence/deployment fixture; all Location IDs are supplied by a disposable account's project. +const fs=require('node:fs'),{randomUUID}=require('node:crypto'),E=require('../../PlotLine/wwwroot/js/maps-engine.js'),G=require('../../PlotLine/wwwroot/js/maps-geography-engine.js'); +const input=JSON.parse(fs.readFileSync(process.argv[2],'utf8')),places=new Map(input.locations.map(l=>[l.locationName,l.locationID])); +const make=(type,name,x,y)=>Object.assign(E.makeFeature(type,x,y,randomUUID()),{name,locationID:places.get(name)||null,isProvisional:false}); +const rubery=make('Town','Rubery',0,0),frankley=make('Town','Frankley',300,-40),redditch=make('Town','Redditch',100,300),barmouth=make('Town','Barmouth',-350,-200),house=make('House',"Maggie's flat",25,20),forest=make('Forest','Forest',-50,-40),lake=make('Lake','Reservoir',320,-30),own=make('House','Own place',80,90),child=make('House','Own child',95,100),decor=make('Landmark','Decoration',600,450); +const road=make('Road','A38',150,0);road.startFeatureID=rubery.featureID;road.endFeatureID=frankley.featureID;E.updateArea(road,g=>g.points=[[-.5,0],[-.1,.35],[.2,-.3],[.5,0]]); +const trail=make('Trail','Trail',200,100);trail.startFeatureID=frankley.featureID;trail.endFeatureID=redditch.featureID; +const before=[rubery,frankley,redditch,barmouth,house,forest,lake,own,child,decor,road,trail];E.reorder(before,[lake.featureID],'front'); +const states=[['Rubery',52.391,-2.016],['Frankley',52.412,-2.023],['Redditch',52.306,-1.942],['Barmouth',52.72,-4.05],['Own place',52.4,-2.01]].map(([name,Latitude,Longitude])=>({locationID:places.get(name),status:'Resolved',matchJson:JSON.stringify({Latitude,Longitude,Attribution:'Isolated acceptance coordinates; no live-provider requests'})})); +const result=G.position(before,states,{x:-600,y:-400,w:1200,h:800},input.locations);if(!result.canApply)throw Error(result.message); +fs.writeFileSync(process.argv[3],JSON.stringify({...input,before,after:result.features,states,counts:result.counts}),{mode:0o600}); diff --git a/PlotLine.Tests/Browser/maps-geography-hierarchy.cjs b/PlotLine.Tests/Browser/maps-geography-hierarchy.cjs new file mode 100644 index 00000000..46f00992 --- /dev/null +++ b/PlotLine.Tests/Browser/maps-geography-hierarchy.cjs @@ -0,0 +1,28 @@ +const{chromium}=require('playwright'),assert=require('node:assert/strict');const base=process.env.PD_MAPS_TEST_URL||'http://127.0.0.1:5238'; +(async()=>{const browser=await chromium.launch();try{for(const pwa of [false,true])for(const theme of ['modern-light','modern-dark']){ + const context=await browser.newContext({viewport:{width:1700,height:1150}});if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));const page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message));let saved; + const locations=[[11,'Rubery',null],[12,'Frankley',null],[13,'Redditch',null],[14,'Barmouth',null],[15,'The Doweries',11],[16,"Maggie's flat",15],[17,'Reservoir',12],[18,'Forest',11],[19,'Independent place',11],[20,'Independent child',19]].map(([locationID,locationName,parentLocationID])=>({locationID,locationName,parentLocationID})); + const states=[[11,52.391,-2.016],[12,52.412,-2.023],[13,52.306,-1.942],[14,52.72,-4.05],[19,52.4,-2.01]].map(([locationID,Latitude,Longitude])=>({locationID,status:'Resolved',matchJson:JSON.stringify({Latitude,Longitude,Attribution:'Isolated synthetic coordinates; no external provider calls'})})); + await page.route('**/Geography/State?*',r=>{assert.equal(new URL(r.request().url()).searchParams.get('includeHierarchy'),'true');return r.fulfill({json:{states,locations}});}); + await page.route('**/Maps/Save',r=>{saved=r.request().postDataJSON();saved.map.revision++;return r.fulfill({json:saved});}); + await page.goto(base+'/fixture?page=maps&theme='+theme);await page.waitForFunction(()=>!!window.PlotDirectorMapWorkspace); + await page.evaluate(()=>{const W=window.PlotDirectorMapWorkspace,E=window.PlotDirectorMaps;W.edit(()=>{ + const f=(type,id,locationID,x,y)=>Object.assign(E.makeFeature(type,x,y,id),{name:id,locationID,isProvisional:false}); + const rubery=f('Town','Rubery',11,0,0),frankley=f('Town','Frankley',12,300,-40),redditch=f('Town','Redditch',13,100,300),barmouth=f('Town','Barmouth',14,-350,-200),house=f('House',"Maggie's flat",16,25,20),forest=f('Forest','Forest',18,-50,-40),lake=f('Lake','Reservoir',17,320,-30),own=f('House','Independent place',19,80,90),child=f('House','Independent child',20,95,100),decor=f('Landmark','Decoration',null,600,450); + const road=f('Road','A38',null,150,0);road.startFeatureID='Rubery';road.endFeatureID='Frankley';const g=E.geometry(road);g.points=[[-.5,0],[-.1,.35],[.2,-.3],[.5,0]];g.drawingOrder=310000;road.geometryJson=JSON.stringify(g); + const segment=f('Trail','Trail',null,200,100);segment.startFeatureID='Frankley';segment.endFeatureID='Redditch';W.document.features=[rubery,frankley,redditch,barmouth,house,forest,lake,own,child,decor,road,segment];});W.fit();}); + const read=()=>page.evaluate(()=>JSON.stringify(window.PlotDirectorMapWorkspace.document.features)),before=await read(); + const expected=await page.evaluate(({states,locations})=>window.PlotDirectorGeography.position(window.PlotDirectorMapWorkspace.document.features,states,window.PlotDirectorMapWorkspace.view,locations),{states,locations});assert(expected.canApply); + const command=id=>page.evaluate(id=>document.getElementById(id).click(),id); + await command('mapsGeographic');await page.locator('#mapsGeographicDialog').waitFor({state:'visible'});assert.equal(await read(),before);await page.locator('#mapsGeographicList').evaluate(n=>n.open=true);assert.match(await page.locator('#mapsGeographicSummary').innerText(),/Maggie's flat → Follows Rubery via The Doweries/);assert.match(await page.locator('#mapsGeographicSummary').innerText(),/2 roads\/paths/);assert(await page.locator('#mapsGeographicPreview svg').isVisible()); + const scene=await page.locator('#mapsScene').innerHTML();await command('mapsGeographicCancel');assert.equal(await read(),before); + await command('mapsGeographic');await page.locator('#mapsGeographicDialog').waitFor({state:'visible'});await command('mapsGeographicApply');assert(!await page.locator('#mapsGeographicDialog').isVisible());assert.deepEqual(JSON.parse(await read()),expected.features,'Apply takes the exact complete proposal');assert.equal(await page.locator('#mapsScene').innerHTML(),scene,'preview and applied renderer have identical roads/boundaries'); + const applied=await read();await command('mapsUndo');assert.equal(await read(),before);await command('mapsRedo');assert.equal(await read(),applied); + await command('mapsSave');await page.waitForFunction(()=>document.getElementById('mapsStatus').textContent==='Saved');assert.deepEqual(saved.features,expected.features); + // Reopen a document supplied by the Save contract, before workspace initialization. + await page.route('**/fixture?**',async route=>{const response=await route.fetch();let html=await response.text();html=html.replace(/(