/* Explicit Development-only smoke. Requires a dedicated identity from --dev-browser-identity. It creates a project owned by that identity; clean up with the matching identity cleanup command. */ const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'); const identityPath=process.argv[2]; if(!identityPath?.startsWith('/tmp/pd-dev-browser-'))throw Error('A dedicated Development identity file is required.'); const identity=JSON.parse(fs.readFileSync(identityPath,'utf8')); if(identity.Database!=='PlotDirector_Development'||!identity.Email.startsWith('pwa-browser-'))throw Error('Development fixture identity required.'); const base='https://dev.plotdirector.com'; (async()=>{ const browser=await chromium.launch(); try{ const context=await browser.newContext({viewport:{width:1700,height:1100}}),page=await context.newPage(),errors=[]; page.on('pageerror',e=>errors.push(e.message)); page.on('dialog',dialog=>dialog.accept()); 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()]); await page.goto(base+'/Projects/Create');await page.locator('#ProjectName').fill('Settlement Development acceptance '+Date.now());await page.getByRole('button',{name:'Save project',exact:true}).click(); await page.waitForURL(/\/Projects(?:\/Details)?\//);const projectId=Number(page.url().match(/\/(\d+)(?:\?|$)/)[1]); await page.goto(base+'/Maps');assert(await page.locator(`a[href="/Maps?projectId=${projectId}"]`).isVisible(),'direct Maps launcher lists the signed-in author’s project'); await page.goto(base+'/Maps?projectId='+projectId);await page.locator('#mapsNew').click(); await page.locator('#mapsNewForm [name=Name]').fill('Working world');await page.locator('#mapsNewForm [name=Kind]').selectOption('World');await page.locator('#mapsNewForm [name=Starter]').selectOption('island'); await Promise.all([page.waitForURL(/&id=\d+/),page.locator('#mapsNewForm button[type=submit]').click()]); await page.waitForFunction(()=>window.PlotDirectorMapWorkspace?.document?.features.length===1);const rootURL=page.url(); async function place(type,x,y){await page.locator('#mapsAssetSearch').fill(type);await page.locator(`[data-asset="${type}"]`).click();const b=await page.locator('#mapsCanvas').boundingBox();await page.mouse.click(b.x+b.width*x,b.y+b.height*y);} await place('Town',.5,.5);await place('House',.51,.51);await place('Road',.3,.5); const ids=await page.evaluate(()=>{const d=window.PlotDirectorMapWorkspace.document;return Object.fromEntries(['Town','House','Road'].map(t=>[t,d.features.find(f=>f.type===t).featureID]));}); const select=id=>page.evaluate(id=>window.PlotDirectorMapWorkspace.select(id),id); await select(ids.Road);await page.locator('[data-field=endFeatureID]').selectOption(ids.Town); await select(ids.Town);assert.equal(await page.locator('[data-boundary-feature-id="'+ids.Town+'"]').count(),1); await page.locator('[data-area-frame=width]').fill('480');await page.locator('[data-area-frame=width]').blur(); const road=()=>page.locator('[data-feature-id="'+ids.Road+'"] .map-shape').getAttribute('d');const originalRoad=await road(); await page.locator('[data-geometry=coast]').selectOption('Gentle');assert.equal(await road(),originalRoad); await page.locator('[data-settlement-mode=anchor]').click();await page.locator('[data-feature-id="'+ids.Town+'"]').focus();await page.keyboard.press('ArrowRight');assert.notEqual(await road(),originalRoad); await page.locator('#mapsUndo').evaluate(e=>e.click());assert.equal(await road(),originalRoad);await page.locator('#mapsRedo').evaluate(e=>e.click()); await page.locator('#mapsSave').click();await page.waitForFunction(()=>document.getElementById('mapsStatus').textContent==='Saved'); const saved=await page.evaluate(()=>JSON.stringify(window.PlotDirectorMapWorkspace.document.features));await page.reload();await page.waitForFunction(()=>!!window.PlotDirectorMapWorkspace); assert.equal(await page.evaluate(()=>JSON.stringify(window.PlotDirectorMapWorkspace.document.features)),saved,'real authenticated Save and reload preserve geometry and references'); assert.equal(await page.evaluate(id=>window.PlotDirectorMapWorkspace.document.features.find(f=>f.featureID===id.Road).endFeatureID===id.Town,ids),true); assert.deepEqual(errors,[]);console.log('PASS authenticated Development settlement creation, boundary/smoothing edit, anchor road recalculation, Undo/Redo, Save and reload. Isolated project '+projectId); await context.close(); }finally{await browser.close();} })().catch(e=>{console.error(e);process.exitCode=1;});