PlotDirector/PlotLine.Tests/Browser/spatial-main-live-updates.cjs

3 lines
3.2 KiB
JavaScript

const{chromium}=require('playwright'),assert=require('node:assert/strict');(async()=>{const browser=await chromium.launch();try{const p=await browser.newPage();const errors=[];p.on('pageerror',e=>errors.push(e.message));await p.goto('http://127.0.0.1:5238/fixture?page=maps');await p.waitForFunction(()=>!!window.PlotDirectorMapWorkspace);await p.addScriptTag({url:'http://127.0.0.1:5238/js/spatial-live-updates.js'});await p.waitForFunction(()=>!!window.PlotDirectorSpatialLiveUpdates);await p.evaluate(()=>PlotDirectorMapWorkspace.setView({x:30,y:40,w:900,h:650}));const doc=await p.evaluate(()=>structuredClone(PlotDirectorMapWorkspace.document));doc.map.revision++;doc.features.push({featureID:'11111111-2222-4333-8444-555555555555',mapID:1,name:'Persisted elsewhere',type:'Custom',geometryClass:'Marker',layer:'Places',x:90,y:100,width:48,height:48,isPlaced:true,showLabel:true,geometryJson:'{}'});let reads=0;await p.route('**/Maps/State?*',r=>{reads++;return r.fulfill({json:doc});});await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'maps'}));assert.equal(await p.evaluate(()=>PlotDirectorMapWorkspace.document.features.length),1);assert.equal(await p.evaluate(()=>PlotDirectorMapWorkspace.view.w),900);await p.evaluate(()=>PlotDirectorMapWorkspace.select(PlotDirectorMapWorkspace.document.features[0].featureID));const name=p.locator('[data-field=name]');await name.fill('Uncommitted typed name');const typedReads=reads;await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'maps'}));assert.equal(reads,typedReads);assert.equal(await name.inputValue(),'Uncommitted typed name');await name.blur();await p.evaluate(()=>PlotDirectorMapWorkspace.edit(()=>PlotDirectorMapWorkspace.document.features[0].x=333));const before=reads;await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'maps'}));assert.equal(reads,before);assert.equal(await p.evaluate(()=>PlotDirectorMapWorkspace.document.features[0].x),333);
await p.goto('http://127.0.0.1:5238/fixture?page=floorplans');await p.waitForSelector('[data-floor-plan-initialized=true]');await p.route('**/FloorPlans/Edit/31',async r=>{const response=await r.fetch({url:'http://127.0.0.1:5238/fixture?page=floorplans'});return r.fulfill({response,body:(await response.text()).replace('data-location-id=""','data-location-id="99"')});});const original=await p.locator('[data-floor-plan-workspace]').elementHandle();await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'floorplans'}));assert.equal(await original.evaluate(n=>n.isConnected),false);await p.waitForSelector('[data-floor-plan-initialized=true]');const current=await p.locator('[data-floor-plan-workspace]').elementHandle();await p.evaluate(()=>document.querySelector('[data-save-status]').dataset.saveState='dirty');await p.evaluate(()=>PlotDirectorSpatialLiveUpdates.refresh({projectId:7,kind:'floorplans'}));assert.equal(await current.evaluate(n=>n.isConnected),true);assert.deepEqual(errors,[]);console.log('PASS main spatial live updates: existing connection, in-place clean map refresh, retained viewport, clean floor workspace refresh, unsaved map/floor protection');}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});