24 lines
4.2 KiB
JavaScript
24 lines
4.2 KiB
JavaScript
// 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;});
|