// Development acceptance against real authenticated routes and a disposable owned fixture. const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'); const [identityPath,fixturePath]=process.argv.slice(2); if(![identityPath,fixturePath].every(p=>p?.startsWith('/tmp/pd-dev-browser-')))throw Error('Dedicated Development fixture files required'); const identity=JSON.parse(fs.readFileSync(identityPath)),f=JSON.parse(fs.readFileSync(fixturePath)); if(identity.Database!=='PlotDirector_Development'||!identity.Email.startsWith('pwa-browser-'))throw Error('Development identity required'); const base='https://dev.plotdirector.com',root=`${base}/Maps?projectId=${f.ProjectID}&id=${f.MapID}`; (async()=>{const browser=await chromium.launch();try{ const login=await browser.newContext(),lp=await login.newPage();await lp.goto(base+'/Account/Login');await lp.locator('#Email').fill(identity.Email);await lp.locator('#Password').fill(identity.Password);await Promise.all([lp.waitForURL('**/Projects'),lp.locator('form[action="/Account/Login"] button[type=submit]').click()]); for(const pwa of [false,true]){ const context=await browser.newContext({storageState:await login.storageState(),viewport:{width:1800,height:1100}}),errors=[]; if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true})); const page=await context.newPage();page.on('pageerror',e=>errors.push(e.message));page.setDefaultTimeout(15000); const ready=p=>p.waitForFunction(()=>!!window.PlotDirectorMapWorkspace); async function command(id){ const source=page.locator('#'+id);if(await source.isVisible()){await source.click();return;} const proxy=page.locator(`[data-pwa-context-controls] [data-command-identity="handler:${id}"]`); for(const menu of await proxy.locator('xpath=ancestor::details').all())if(await menu.getAttribute('open')===null)await menu.locator(':scope > summary').click();await proxy.click(); } async function maximise(selector,id,snapshot){ const before=await page.evaluate(snapshot),box=await page.locator(selector).boundingBox();await command(id); await page.waitForFunction(s=>document.querySelector(s).classList.contains('pd-workspace-maximised'),selector); await page.waitForTimeout(150);const full=await page.locator(selector).boundingBox();assert(full.x<=5&&full.y<=5&&full.width>=1790);assert(full.height>box.height);if(id==='floorPlanMaximise')assert((await page.locator('.floor-plan-editor-toolbar').boundingBox()).height<120,'Maximised PWA toolbar must retain its compact layout'); assert.equal(await page.locator('.pd-application-header').evaluate(n=>getComputedStyle(n).visibility),'hidden'); assert.deepEqual(await page.evaluate(snapshot),before); await page.setViewportSize({width:1600,height:1000});await page.waitForTimeout(100);assert.deepEqual(await page.evaluate(snapshot),before);await page.setViewportSize({width:1800,height:1100}); await page.screenshot({path:`/tmp/workspace-${id}-${pwa?'pwa':'web'}-max.png`}); await page.locator('#'+id).click();await page.waitForTimeout(150);const restored=await page.locator(selector).boundingBox();assert(Math.abs(restored.height-box.height)<2,'Restore must recalculate height after viewport resizing');assert.deepEqual(await page.evaluate(snapshot),before);assert.equal(await page.locator('.pd-application-header').evaluate(n=>getComputedStyle(n).visibility),'visible'); } await page.goto(`${base}/FloorPlans?projectId=${f.ProjectID}`);const index=await page.locator('.floor-plan-index-shell').boundingBox();assert(index.width<=1201);assert(Math.abs(index.x-(1800-index.width)/2)<2);const card=await page.locator('.floor-plan-index-shell .edit-panel').first().boundingBox();assert(Math.abs(card.x+card.width/2-900)<2,'Create form itself must be centred'); await page.screenshot({path:`/tmp/workspace-floor-index-${pwa?'pwa':'web'}.png`}); await page.goto(`${base}/FloorPlans/Edit/${f.FloorPlanID}`);await page.waitForFunction(()=>document.querySelector('[data-floor-plan-editor]')?.dataset.floorPlanInitialized==='true'); assert((await page.locator('[data-floor-plan-workspace]').boundingBox()).width>1750); for(const tab of ['add','transitions'])assert(await page.locator(`.floor-plan-build [data-toolbox-tab=${tab}]`).count()); for(const tab of ['selected','floors','background'])assert(await page.locator(`.floor-plan-inspector [data-toolbox-tab=${tab}]`).count()); await page.locator('[data-toolbox-tab=floors]').click();assert(await page.locator('.floor-plan-inspector [data-toolbox-panel=floors]').isVisible()); const block=page.locator('.floor-plan-floor.active [data-block]').first();await block.click();assert(await page.locator('[data-toolbox-panel=selected]').isVisible()); await maximise('[data-floor-plan-workspace]','floorPlanMaximise',()=>({selected:document.querySelector('[data-block].selected')?.dataset.block, floor:document.querySelector('.floor-plan-floor.active')?.dataset.floorPanel,scroll:[...document.querySelectorAll('.floor-plan-floor.active .floor-plan-grid-wrap')].map(n=>[n.scrollLeft,n.scrollTop])})); await page.screenshot({path:`/tmp/workspace-floor-${pwa?'pwa':'web'}.png`}); await page.goto(`${base}/Maps?projectId=${f.ProjectID}`);await ready(page);assert.equal(await page.locator('#mapsWelcomeNew').textContent(),'Create new map'); await page.goto(root);await ready(page);assert.equal(await page.locator('#mapsContext').count(),0);assert.equal(await page.locator('[data-command-identity="handler:mapsContext"]').count(),0); assert(Math.abs((await page.locator('#mapsDefine').boundingBox()).width-(await page.locator('#mapsAssets').boundingBox()).width)<2); await page.evaluate(()=>{const w=window.PlotDirectorMapWorkspace;w.select(w.document.features[0].featureID);});await command('mapsZoomIn'); await maximise('#mapsApp','mapsMaximise',()=>({view:{...window.PlotDirectorMapWorkspace.view},selected:window.PlotDirectorMapWorkspace.selected,mode:window.PlotDirectorMapWorkspace.mode})); await page.locator('#mapsCanvas').click({button:'right',position:{x:30,y:30}});await page.locator('.pd-context-popup').waitFor();await page.keyboard.press('Escape'); const firstPromise=page.waitForEvent('popup');await command('mapsDetach');const first=await firstPromise;await ready(first); const secondPromise=page.waitForEvent('popup');await command('mapsDetach');const second=await secondPromise;await ready(second);assert.notEqual(first,second); await first.locator('#mapsSelect').selectOption(String(f.ChildMapID));await first.waitForURL(u=>u.searchParams.get('id')===String(f.ChildMapID));await ready(first);await page.waitForTimeout(200); assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.document.map.mapID),f.MapID);assert.equal(await second.evaluate(()=>window.PlotDirectorMapWorkspace.document.map.mapID),f.MapID); const retained=await page.evaluate(()=>({view:{...window.PlotDirectorMapWorkspace.view},selected:window.PlotDirectorMapWorkspace.selected,mode:window.PlotDirectorMapWorkspace.mode})); await first.evaluate(()=>window.PlotDirectorMapWorkspace.setMode('explore'));await first.locator('#mapsZoomIn').click();assert.deepEqual(await page.evaluate(()=>({view:{...window.PlotDirectorMapWorkspace.view},selected:window.PlotDirectorMapWorkspace.selected,mode:window.PlotDirectorMapWorkspace.mode})),retained); // Both clients hold the same revision. The server must accept one and reject the stale write. const original=await page.evaluate(()=>window.PlotDirectorMapWorkspace.document.features[0].name); await second.evaluate(()=>{const w=window.PlotDirectorMapWorkspace;w.edit(()=>w.document.features[0].name='Stale window acceptance edit');}); await page.evaluate(()=>{const w=window.PlotDirectorMapWorkspace;w.edit(()=>w.document.features[0].name+=' acceptance saved');});assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.save()),true); const rejected=second.waitForResponse(r=>r.url().endsWith('/Maps/Save')&&r.status()===409);assert.equal(await second.evaluate(()=>window.PlotDirectorMapWorkspace.save()),false);await rejected; assert.equal(await second.evaluate(()=>window.PlotDirectorMapWorkspace.dirty),true);assert.equal(await second.evaluate(()=>window.PlotDirectorMapWorkspace.document.features[0].name),'Stale window acceptance edit'); const stored=await(await context.request.get(`${base}/Maps/State?projectId=${f.ProjectID}&id=${f.MapID}`)).json();assert.equal(stored.features[0].name,original+' acceptance saved'); await page.evaluate(name=>{const w=window.PlotDirectorMapWorkspace;w.edit(()=>w.document.features[0].name=name);},original);assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.save()),true); await first.screenshot({path:`/tmp/workspace-independent-child-${pwa?'pwa':'web'}.png`});await page.screenshot({path:`/tmp/workspace-independent-main-${pwa?'pwa':'web'}.png`}); assert.deepEqual(errors,[]);console.log(`PASS Development ${pwa?'PWA':'web'}: centred index, full-width floor editor, panel arrangement, maximise/restore and retained state, Maps palette/context, three independent windows, real HTTP 409 conflict with retained edits`);await context.close(); } }finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});