45 lines
10 KiB
JavaScript
45 lines
10 KiB
JavaScript
// Real Development UI, normal writer authentication, and registered disposable data only.
|
|
const assert=require('node:assert/strict'),{open}=require('./dev-acceptance.cjs');
|
|
let session,stage='login';
|
|
(async()=>{try{
|
|
session=await open();const p=session.page;const project=await session.project();
|
|
const place=await session.create('Locations','?projectId='+project,{LocationName:'Acceptance room',Description:'Original description'});
|
|
const book=await session.create('Books','?projectId='+project,{BookTitle:'Context acceptance one',BookNumber:1});
|
|
const otherBook=await session.create('Books','?projectId='+project,{BookTitle:'Context acceptance two',BookNumber:2});
|
|
const chapter=await session.create('Chapters','?bookId='+book,{ChapterTitle:'Context chapter one',ChapterNumber:1});
|
|
const otherChapter=await session.create('Chapters','?bookId='+otherBook,{ChapterTitle:'Context chapter two',ChapterNumber:1});
|
|
async function scene(chapter,title){await session.goto('/Scenes/Create?chapterId='+chapter);await p.locator('#SceneTitle').fill(title);await p.locator('#PrimaryLocationID').selectOption(String(place));await p.getByRole('button',{name:'Create scene',exact:true}).click();await p.waitForURL('**/Scenes/Edit/*');return Number(new URL(p.url()).pathname.split('/').at(-1));}
|
|
const sceneId=await scene(chapter,'Held acceptance scene'),otherScene=await scene(otherChapter,'Isolated acceptance scene');
|
|
stage='map creation';await session.goto('/Maps?projectId='+project);await p.locator('#mapsWelcomeNew').click();await p.locator('#mapsNewForm [name=Name]').fill('Acceptance geometry');await p.locator('#mapsNewForm [name=Starter]').selectOption('land');await p.locator('#mapsNewForm button[type=submit]').click();await p.waitForFunction(()=>window.PlotDirectorMapWorkspace?.document?.features.length>0&&!window.PlotDirectorMapWorkspace.busy);const map=await p.evaluate(()=>PlotDirectorMapWorkspace.document.map.mapID);
|
|
stage='floor plan creation';await session.goto('/FloorPlans?projectId='+project);const create=p.locator('form[action="/FloorPlans/Create"]');await create.locator('[name=Name]').fill('Acceptance plan');await create.locator('[name=LocationID]').selectOption(String(place));await create.locator('button[type=submit]').click();await p.waitForURL('**/FloorPlans/Edit/*');const plan=Number(new URL(p.url()).pathname.split('/').at(-1));
|
|
const context=p.context(),a=await context.newPage(),b=await context.newPage(),c=await context.newPage(),reads=[];
|
|
for(const page of [a,b,c])page.on('request',r=>{const path=new URL(r.url()).pathname;if(path.startsWith('/SpatialContext/')||path.includes('/Context/Tabs/'))reads.push({page,path});});
|
|
const url=(bk,ch,sc)=>`https://dev.plotdirector.com/Writing/Context?projectId=${project}&bookId=${bk}&chapterId=${ch}&sceneId=${sc}&pinned=true`;
|
|
const setTab=(page,i,tool)=>page.selectOption(`[data-context-pane="${i}"] [data-context-tab]`,tool);
|
|
await a.goto(url(book,chapter,sceneId));await a.selectOption('[data-context-layout]','columns');await setTab(a,0,'maps');await setTab(a,1,'floorplans');
|
|
await a.locator('[data-context-pane="0"] [data-spatial-resource]').selectOption(String(map));await a.locator('[data-context-pane="1"] [data-spatial-resource]').selectOption(String(plan));
|
|
await a.waitForFunction(()=>document.querySelector('iframe')?.contentWindow?.PlotDirectorMapWorkspace?.document);
|
|
await a.locator('[data-floor-grid]').first().waitFor();
|
|
await b.goto(url(book,chapter,sceneId));await b.selectOption('[data-context-layout]','columns');await setTab(b,0,'locations');await setTab(b,1,'overview');await b.getByRole('heading',{name:'Acceptance room',exact:true}).waitFor();
|
|
await c.goto(url(otherBook,otherChapter,otherScene));await c.locator('[data-context-tab-fragment]').waitFor();
|
|
await Promise.all([a,b,c].map(page=>page.waitForFunction(()=>document.querySelector('[data-context-workspace]').contextController.connection?.state==='Connected')));
|
|
await a.locator('[data-context-pane="0"] [data-spatial-zoom="in"]').click();await a.locator('[data-context-pane="1"] [data-spatial-zoom="in"]').click();await a.waitForTimeout(400);
|
|
const snapshot=()=>a.evaluate(()=>({position:{...document.querySelector('[data-context-workspace]').contextController.position},view:{...document.querySelector('iframe').contentWindow.PlotDirectorMapWorkspace.view},floor:document.querySelector('[data-spatial-floor]').value,transform:document.querySelector('[data-spatial-floor-world]').style.transform}));
|
|
const before=await snapshot();
|
|
stage='committed geometry save and relevant refresh';await session.goto(`/Maps?projectId=${project}&id=${map}`);await p.locator('[data-feature-id]').first().click();const width=p.locator('[data-field=width]').first();const savedWidth=Number(await width.inputValue())+37;reads.length=0;await width.fill(String(savedWidth));await p.waitForTimeout(300);assert.equal(reads.length,0,'unsaved geometry emits no saved-data read');
|
|
await p.locator('#mapsSave').click();await p.waitForFunction(()=>!PlotDirectorMapWorkspace.dirty&&!PlotDirectorMapWorkspace.busy);
|
|
await a.waitForFunction(w=>document.querySelector('iframe')?.contentWindow.PlotDirectorMapWorkspace?.document.features[0].width===w,savedWidth);await a.waitForTimeout(300);
|
|
assert.equal(reads.filter(r=>r.path==='/SpatialContext/Floor').length,0);assert.equal(reads.filter(r=>r.page===c).length,0,'project-wide geometry does not refresh unrelated Overview');assert.deepEqual(await snapshot(),before);
|
|
stage='failed save does not invalidate';reads.length=0;const failed=await p.evaluate(async()=>{const doc=structuredClone(PlotDirectorMapWorkspace.document);doc.map.revision=-1;const token=document.querySelector('[name=__RequestVerificationToken]').value;return (await fetch('/Maps/Save',{method:'POST',headers:{'Content-Type':'application/json','RequestVerificationToken':token},body:JSON.stringify(doc)})).status;});assert(failed>=400);await a.waitForTimeout(400);assert.equal(reads.length,0);
|
|
stage='floor layout persistence and viewport retention';await session.goto('/FloorPlans/Edit/'+plan);const floorWidth=p.locator('[data-floor-width]').first();await floorWidth.evaluate(e=>{for(let node=e.parentElement;node;node=node.parentElement)if(node.tagName==='DETAILS')node.open=true;});const savedFloorWidth=Number(await floorWidth.inputValue())+1;await floorWidth.fill(String(savedFloorWidth));reads.length=0;await Promise.all([p.waitForResponse(r=>r.url().includes('/FloorPlans/SaveLayout')&&r.status()===200),p.locator('[data-save-layout-button]').first().click()]);await a.waitForFunction(w=>Number(document.querySelector('[data-floor-grid]').dataset.gridWidth)===w,savedFloorWidth);await a.waitForTimeout(300);assert.equal(reads.filter(r=>r.path==='/SpatialContext/Map').length,0);assert.equal(reads.filter(r=>r.page===b||r.page===c).length,0);assert.deepEqual(await snapshot(),before);
|
|
stage='held location saved-data update';await session.goto('/Locations/Edit/'+place);await p.locator('[name=Description]').fill('Saved description after refresh');await p.locator('form.pd-record-form button[type=submit]').first().click();await p.waitForURL('**/Locations/Details/*');await b.getByText('Saved description after refresh',{exact:true}).waitFor();assert.equal(await b.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.position.sceneId),sceneId);
|
|
stage='date-only save targets Overview and preserves book isolation';await session.goto('/Scenes/SceneDetailsEditor?sceneId='+sceneId);const exact=await p.locator('[name=TimeModeID] option').evaluateAll(options=>options.find(o=>/exact/i.test(o.textContent))?.value);assert(exact);await p.locator('[name=TimeModeID]').selectOption(exact);await p.locator('[name=StartDateTime]').fill('2030-05-06T10:00');reads.length=0;await Promise.all([p.waitForResponse(r=>r.url().includes('/Scenes/SaveSceneDetails')&&r.status()===200),p.getByRole('button',{name:'Save details',exact:true}).click()]);await b.waitForFunction(()=>document.querySelector('[data-context-pane="1"]').textContent.includes('2030'));await b.waitForTimeout(300);assert.equal(reads.filter(r=>r.page===a||r.page===c).length,0,'date-only save does not refresh spatial or other-book panes');
|
|
stage='book-scoped intent and isolation';await session.goto('/Scenes/Edit/'+sceneId);reads.length=0;await session.post('/Scenes/SaveScenePurpose',{SceneID:sceneId,ScenePurposeNotes:'Saved acceptance purpose',SceneOutcomeNotes:'Saved acceptance outcome'});await b.waitForTimeout(700);assert.equal(reads.filter(r=>r.page===c).length,0);assert.equal(reads.filter(r=>r.page===a).length,0,'intent does not refresh spatial panes');
|
|
stage='existing main window navigation';await p.waitForTimeout(600);const held=b.url();await b.getByRole('link',{name:'Location Details',exact:true}).click();await p.waitForURL('**/Locations/Details/'+place);assert.equal(b.url(),held);assert.equal(await b.evaluate(()=>document.querySelector('[data-context-workspace]').contextController.position.sceneId),sceneId);
|
|
await session.close();session=null;
|
|
stage='fresh normal login and durable reload';session=await open();await session.goto(`/Maps?projectId=${project}&id=${map}`);await session.page.waitForFunction(w=>window.PlotDirectorMapWorkspace?.document.features[0].width===w,savedWidth);await session.goto('/FloorPlans/Edit/'+plan);assert.equal(Number(await session.page.locator('[data-floor-width]').first().inputValue()),savedFloorWidth);await session.goto('/Locations/Edit/'+place);assert.equal(await session.page.locator('[name=Description]').inputValue(),'Saved description after refresh');await session.goto('/Scenes/SceneDetailsEditor?sceneId='+sceneId);assert.match(await session.page.locator('[name=StartDateTime]').inputValue(),/^2030-05-06T10:00/);await session.goto('/Scenes/ScenePurposeEditor?sceneId='+sceneId);assert.equal(await session.page.locator('[name=ScenePurposeNotes]').inputValue(),'Saved acceptance purpose');
|
|
console.log(JSON.stringify({passed:true,project,book,otherBook,sceneId,map,plan,checks:['real committed map geometry','unsaved and failed saves silent','floor layout and map/floor viewport retention','held saved location refresh','book isolation','date-only targeting','relevant panels only','existing main navigation','fresh-login persistence'],featureUrl:`https://dev.plotdirector.com/Writing/Context?bookId=${book}&sceneId=${sceneId}&pinned=true`}));
|
|
}catch{console.error('Development Context acceptance failed at '+stage+'; no credentials logged.');process.exitCode=1;}
|
|
finally{if(session){try{await session.cleanup();console.log('PASS disposable project cleanup');}catch{console.error('Cleanup incomplete; preserve journal and resume documented scoped cleanup.');process.exitCode=1;}finally{await session.close();}}}
|
|
})();
|