PlotDirector/PlotLine.Tests/Browser/maps-story-dev-smoke.cjs

45 lines
10 KiB
JavaScript

// Explicit Development-only acceptance. Uses a dedicated normal account and owned fixture project.
const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs');
const [identityPath,fixturePath]=process.argv.slice(2);
if(!identityPath?.startsWith('/tmp/pd-dev-browser-')||!fixturePath?.startsWith('/tmp/pd-dev-browser-'))throw Error('Dedicated Development identity and fixture files required.');
const identity=JSON.parse(fs.readFileSync(identityPath,'utf8')),f=JSON.parse(fs.readFileSync(fixturePath,'utf8')),base='https://dev.plotdirector.com';
if(identity.Database!=='PlotDirector_Development'||!identity.Email.startsWith('pwa-browser-'))throw Error('Development fixture identity required.');
(async()=>{const browser=await chromium.launch();try{
const context=await browser.newContext({viewport:{width:1800,height:1100}}),page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message));page.setDefaultTimeout(20000);
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 rootURL=`${base}/Maps?projectId=${f.ProjectID}&id=${f.MapID}&mode=story`;
const before=await(await context.request.get(`${base}/Maps/State?projectId=${f.ProjectID}&id=${f.MapID}`)).json();
async function ready(p){await p.waitForFunction(()=>!!window.PlotDirectorStoryOverlay?.data);}
async function group(p,locator){for(const menu of await locator.locator('xpath=ancestor::details').all())if(await menu.getAttribute('open')===null)await menu.locator(':scope > summary').click();}
async function choose(p,id,value,pwa=false){const source=p.locator('#'+id);if(pwa){const label=await source.getAttribute('aria-label'),proxy=p.locator('[data-pwa-context-controls]').getByRole('combobox',{name:label,exact:true,includeHidden:true}).or(p.locator('[data-pwa-context-controls]').getByRole('listbox',{name:label,exact:true,includeHidden:true}));await group(p,proxy);await proxy.selectOption(String(value));}else await source.selectOption(String(value));}
async function action(p,id,pwa=false){const node=pwa?p.locator(`[data-pwa-context-controls] [data-command-identity="handler:${id}"]`):p.locator('#'+id);await group(p,node);await node.click();}
await page.goto(rootURL);await ready(page);assert.equal(await page.evaluate(()=>window.PlotDirectorStoryOverlay.data.scenes.length),6);assert.equal(await page.locator('#mapsStoryLayer >g').count(),2);
await choose(page,'mapStoryLens','scene');await choose(page,'mapStoryScene',f.SceneAID);await action(page,'mapStoryNext');assert.match(await page.locator('#mapsDetailContent').innerText(),/Hill arrival/);await action(page,'mapStoryNext');assert.match(await page.locator('#mapsDetailContent').innerText(),/Harbour revisit/);await action(page,'mapStoryPrevious');assert.match(await page.locator('#mapsDetailContent').innerText(),/Hill arrival/);
assert.equal(await page.locator(`a[href="/Scenes/Edit/${f.SceneBID}"]`).count(),1);
await choose(page,'mapStoryLens','character');await choose(page,'mapStoryCharacter1',f.CharacterID);await choose(page,'mapStoryCharacter2',f.CompareCharacterID);assert.match(await page.locator('#mapsDetailContent').innerText(),/Ari/);assert.match(await page.locator('#mapsDetailContent').innerText(),/Bea/);assert.match(await page.locator('#mapsDetailContent').innerText(),/3\. Harbour/);
await page.locator('.maps-story-leg').first().focus();await page.keyboard.press('Enter');assert.match(await page.locator('#mapsDetailContent').innerText(),/Possible travel timing to review/);
await page.locator('#mapsDetailContent details').filter({has:page.locator('summary:text-is("Author-selected travel context")')}).locator('summary').click();
await page.locator('#mapStoryJourneyForm [name=routeFeatureID]').selectOption(f.RouteFeatureID);await page.locator('#mapStoryJourneyForm [name=travelMethod]').fill('Boat');await page.locator('#mapStoryJourneyForm [name=typicalMinutes]').fill('180');await page.locator('#mapStoryJourneyForm button[type=submit]').click();await page.waitForFunction(()=>window.PlotDirectorStoryOverlay.data.legs.some(l=>l.note?.travelMethod==='Boat'));
assert(await page.evaluate(route=>window.PlotDirectorStoryOverlay.data.legs.some(l=>l.note?.routeFeatureID===route),f.RouteFeatureID));
await choose(page,'mapStoryLens','chapter');await choose(page,'mapStoryChapter',f.ChapterID);assert.match(await page.locator('#mapsDetailContent').innerText(),/3 scenes/);
await choose(page,'mapStoryLens','plot');await choose(page,'mapStoryPlot1',f.PlotLineID);assert.equal(await page.locator('#mapsStoryLayer >g').count(),1);assert.match(await page.locator('#mapsDetailContent').innerText(),/100%/);
await choose(page,'mapStoryLens','time');await choose(page,'mapStoryCharacter1',0);await choose(page,'mapStoryCharacter2',0);await choose(page,'mapStoryTime','2026-01-01T09:30:00');assert.match(await page.locator('#mapsDetailContent').innerText(),/Last known: Hill town/);await choose(page,'mapStoryTime','2026-01-01T10:30:00');assert.match(await page.locator('#mapsDetailContent').innerText(),/latest confirmed appearance has no known Location/);
await choose(page,'mapStoryLens','overview');await action(page,'mapStoryGaps');assert.match(await page.locator('#mapsDetailContent').innerText(),/Unmapped town/);assert.match(await page.locator('#mapsDetailContent').innerText(),/No Location assigned/);
await page.locator(`[data-story-place="${f.UnmappedLocationID}"]`).click();assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.mode),'create');assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.dirty),false,'resolving a gap never places it automatically');await page.evaluate(()=>window.PlotDirectorMapWorkspace.setMode('explore'));assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.dirty),false);
await page.evaluate(()=>window.PlotDirectorMapWorkspace.setMode('story'));await ready(page);await choose(page,'mapStoryLens','scene');await choose(page,'mapStoryScene',f.DetailSceneID);
const floorLink=page.locator(`a[href*="/FloorPlans/Edit/${f.FloorPlanID}?storySceneId=${f.DetailSceneID}"]`);assert.equal(await floorLink.count(),1);await floorLink.click();await page.waitForURL(/\/FloorPlans\/Edit/);await page.locator('.floor-plan-editor--occupancy').waitFor();assert.equal(await page.locator('[data-occupancy-scene-select]').inputValue(),String(f.DetailSceneID));
await page.getByRole('link',{name:'← Back to map Story Mode'}).click();await ready(page);assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.mode),'story');
await page.locator(`#mapsDetailContent a[href*="id=${f.ChildMapID}&mode=story"]`).click();await ready(page);assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.document.map.parentMapID),f.MapID);assert.match(await page.locator('#mapsDetailContent').innerText(),/House room/);
const parent=page.locator(`#mapsBreadcrumbs a[href*="id=${f.MapID}&mode=story"]`);await parent.click();await ready(page);assert.equal(await page.evaluate(()=>window.PlotDirectorMapWorkspace.mode),'story');
await page.locator('a[href="/Scenes/Edit/'+f.DetailSceneID+'"]').click();await page.waitForURL('**/Scenes/Edit/'+f.DetailSceneID);assert(await page.locator('main').isVisible());await page.goto(rootURL);await ready(page);
const denied=await context.request.get(`${base}/Maps/Story?projectId=${f.ProjectID}&id=-1`);assert.equal(denied.status(),404);const scenario=await context.request.get(`${base}/Maps/Story?projectId=${f.ProjectID}&id=${f.MapID}&scenarioId=-1`);assert.equal(scenario.status(),404);
const csrf=await context.request.post(`${base}/Maps/Journey?projectId=${f.ProjectID}`,{data:{mapID:f.MapID,characterID:f.CharacterID,fromSceneID:f.SceneAID,toSceneID:f.SceneBID}});assert.equal(csrf.status(),400);
const pwaContext=await browser.newContext({viewport:{width:1800,height:1100},storageState:await context.storageState()});await pwaContext.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));const app=await pwaContext.newPage();app.on('pageerror',e=>errors.push(e.message));await app.goto(rootURL);await ready(app);
assert(await app.locator('#mapsStoryToolbar').isHidden());assert(await app.locator('.maps-toolbar').isHidden());const bounds=await app.locator('#mapsCanvas').boundingBox();
await choose(app,'mapStoryLens','character',true);await choose(app,'mapStoryCharacter1',f.CharacterID,true);await choose(app,'mapStoryCharacter2',f.CompareCharacterID,true);assert.match(await app.locator('#mapsDetailContent').innerText(),/Bea/);await choose(app,'mapStoryLens','chapter',true);await choose(app,'mapStoryChapter',f.ChapterID,true);await choose(app,'mapStoryLens','plot',true);await choose(app,'mapStoryPlot1',f.PlotLineID,true);await choose(app,'mapStoryLens','time',true);await choose(app,'mapStoryTime','2026-01-01T09:30:00',true);assert.match(await app.locator('#mapsDetailContent').innerText(),/Last known/);assert.deepEqual(await app.locator('#mapsCanvas').boundingBox(),bounds,'PWA lens changes preserve canvas geometry');
await choose(app,'mapStoryLens','character',true);await app.screenshot({path:'/tmp/maps-story-development-pwa.png'});await page.screenshot({path:'/tmp/maps-story-development-web.png'});
for(const width of [1440,800,390]){await app.setViewportSize({width,height:1100});assert(await app.locator('#mapsApp').evaluate(e=>e.scrollWidth<=e.clientWidth+1),'responsive workspace must not overflow at '+width);}
const after=await(await context.request.get(`${base}/Maps/State?projectId=${f.ProjectID}&id=${f.MapID}`)).json();assert.deepEqual(after,before,'all Story navigation and travel annotation save must leave geography and revision unchanged');assert.deepEqual(errors,[]);
console.log('PASS authenticated Development Maps Story: six lenses, scene/editor navigation, character comparison/revisits, explicit saved route/method/time, chronology/unknown semantics, honest gaps, child/ancestor maps, Floor Plan occupancy/back navigation, PWA/responsive layout, CSRF/scenario access and unchanged geography revision.');await context.close();await pwaContext.close();
}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});