PlotDirector/PlotLine.Tests/Browser/context-spatial-layout-development.cjs
2026-12-01 20:01:50 +00:00

32 lines
5.3 KiB
JavaScript

// Genuine Development layout interactions; server records use ordinary forms.
const assert=require('node:assert/strict'),{open}=require('./dev-acceptance.cjs');
let session,stage='login';
(async()=>{try{
session=await open();const p=session.page,project=await session.project();
const place=await session.create('Locations','?projectId='+project,{LocationName:'Layout harbour',Description:'Scrollable saved detail.\n'.repeat(150)});
const book=await session.create('Books','?projectId='+project,{BookTitle:'Spatial layout acceptance',BookNumber:1});
const chapter=await session.create('Chapters','?bookId='+book,{ChapterTitle:'Layout chapter',ChapterNumber:1});
await session.goto('/Scenes/Create?chapterId='+chapter);await p.locator('#SceneTitle').fill('Layout scene');await p.locator('#PrimaryLocationID').selectOption(String(place));await p.getByRole('button',{name:'Create scene',exact:true}).click();await p.waitForURL('**/Scenes/Edit/*');const scene=Number(new URL(p.url()).pathname.split('/').at(-1));
const feature=`/Writing/Context?projectId=${project}&bookId=${book}&chapterId=${chapter}&sceneId=${scene}&pinned=true`;
await session.goto(feature);await p.setViewportSize({width:1280,height:850});
const pane=p.locator('[data-context-pane="0"]'),tab=pane.locator('[data-context-tab]'),handle=pane.getByRole('separator'),layout=pane.locator('[data-spatial-layout]'),orientation=pane.locator('[data-spatial-orientation]');
const initial=await p.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position}));
for(const kind of ['locations','maps','floorplans']){
stage=kind+' resize';await tab.selectOption(kind);await handle.waitFor();assert.equal(await handle.getAttribute('aria-valuenow'),'30');
if(kind==='locations'){await pane.getByRole('heading',{name:'Layout harbour',exact:true}).waitFor();const scroll=await pane.locator('[data-spatial-details]').evaluate(n=>{n.scrollTop=100;return {top:n.scrollTop,scroll:n.scrollHeight,height:n.clientHeight};});assert(scroll.top>0&&scroll.scroll>scroll.height);assert.equal(await pane.locator('[data-spatial-scenes]').evaluate(n=>n.scrollTop),0);}
await handle.focus();await handle.press('ArrowRight');assert.equal(await handle.getAttribute('aria-valuenow'),'32');
await orientation.selectOption('vertical');assert.equal(await handle.getAttribute('aria-valuenow'),'30');await handle.focus();await handle.press('ArrowDown');assert.equal(await handle.getAttribute('aria-valuenow'),'32');
const box=await layout.boundingBox(),grip=await handle.boundingBox();await p.mouse.move(grip.x+grip.width/2,grip.y+grip.height/2);await p.mouse.down();await p.mouse.move(box.x+box.width/2,box.y+box.height*.45,{steps:10});await p.mouse.up();const stacked=Number(await handle.getAttribute('aria-valuenow'));assert(stacked>=43&&stacked<=47);
await orientation.selectOption('horizontal');assert.equal(await handle.getAttribute('aria-valuenow'),'32');
const horizontal=await layout.boundingBox(),h=await handle.boundingBox();await p.mouse.move(h.x+h.width/2,h.y+h.height/2);await p.mouse.down();await p.mouse.move(horizontal.x+horizontal.width*.4,h.y+h.height/2,{steps:10});await p.mouse.up();assert(Number(await handle.getAttribute('aria-valuenow'))>=38);
await p.reload();await handle.waitFor();assert.equal(await tab.inputValue(),kind);assert.equal(await orientation.inputValue(),'horizontal');assert(Number(await handle.getAttribute('aria-valuenow'))>=38);await orientation.selectOption('vertical');assert.equal(Number(await handle.getAttribute('aria-valuenow')),stacked);
await p.setViewportSize({width:460,height:850});assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1));const panels=await layout.evaluate(n=>[...n.children].filter(x=>x.tagName!=='DIV').map(x=>({w:x.clientWidth,h:x.clientHeight})));assert(panels.every(x=>x.w>0&&x.h>0));await p.setViewportSize({width:1280,height:850});
}
stage='window isolation';const other=await p.context().newPage();await other.goto('https://dev.plotdirector.com'+feature);await other.selectOption('[data-context-pane="0"] [data-context-tab]','floorplans');assert.equal(await other.locator('[data-spatial-splitter]').getAttribute('aria-valuenow'),'30');await other.close();
stage='pane isolation';await p.selectOption('[data-context-layout]','columns');await p.selectOption('[data-context-pane="1"] [data-context-tab]','floorplans');assert.equal(await p.locator('[data-context-pane="1"] [data-spatial-orientation]').inputValue(),'horizontal');assert.equal(await p.locator('[data-context-pane="1"] [data-spatial-splitter]').getAttribute('aria-valuenow'),'30');assert.equal(await orientation.inputValue(),'vertical');
assert.deepEqual(await p.evaluate(()=>({...document.querySelector('[data-context-workspace]').contextController.position})),initial);
console.log(JSON.stringify({passed:true,checks:['all three tools pointer and keyboard resizing in both orientations','independent proportions restored on reload','narrow viewport boundaries','pane isolation','manuscript focus preserved'],featureUrl:'https://dev.plotdirector.com'+feature}));
}catch(e){console.error('Spatial layout acceptance failed at '+stage+' ('+e.name+').');if(e.name==='AssertionError')console.error(e.message);process.exitCode=1;}
finally{if(session){try{await session.cleanup();console.log('PASS disposable project cleanup');}finally{await session.close();}}}
})();