// Run through Tools/BrowserAcceptance/run.py against the committed Development release. const {open}=require('./dev-acceptance.cjs'); const assert=require('node:assert/strict'); let session,stage='login'; (async()=>{ try{ session=await open(); const project=await session.project(); const book=await session.create('Books','?projectId='+project,{BookTitle:'Metrics acceptance',BookNumber:1}); const chapters=[]; const scenes=[]; for(let ch=1;ch<=2;ch++){ stage='chapter fixture';const chapter=await session.create('Chapters','?bookId='+book,{ChapterTitle:'Metrics chapter '+ch,ChapterNumber:ch});chapters.push(chapter); for(let n=1;n<=6;n++){ stage='scene fixture'; await session.goto('/Scenes/Create?chapterId='+chapter); await session.page.locator('#SceneTitle').fill(`Metric scene ${ch}.${n}`); await session.page.getByRole('button',{name:'Create scene',exact:true}).click(); await session.page.waitForURL('**/Scenes/Edit/*'); scenes.push(Number(new URL(session.page.url()).pathname.split('/').pop())); } } stage='metric fixture'; await session.goto('/ProjectMetrics/Index?projectId='+project); const form=session.page.locator('form[action="/ProjectMetrics/Save"]'); await form.locator('[name=MetricName]').fill('Acceptance zero scale'); await form.locator('[name=MinValue]').fill('0');await form.locator('[name=MaxValue]').fill('10');await form.locator('[name=DefaultValue]').fill('5'); await form.getByRole('button',{name:'Add Metric',exact:true}).click();await session.page.waitForURL(url=>url.pathname==='/ProjectMetrics'||url.pathname==='/ProjectMetrics/Index'); const route='/Writing/Context?'+new URLSearchParams({projectId:project,bookId:book,sceneId:scenes[6]}); await session.goto(route);let page=session.page; let navigationWrites=0;page.on('request',r=>{if(/\/(Writing\/Context|WriterWord)\/Navigate/.test(new URL(r.url()).pathname))navigationWrites++;}); const select=page.locator('[data-context-pane="0"] [data-context-tab]');await select.selectOption('metrics'); const row=()=>page.locator('[data-context-pane="0"] [data-metric-row]').filter({hasText:'Acceptance zero scale'}); await row().waitFor();const metricId=Number(await row().getAttribute('data-metric-row')); assert.equal(await row().locator('output').innerText(),'Unset'); const payload=await page.locator('[data-metrics-payload]').evaluate(el=>JSON.parse(el.textContent)); assert.deepEqual(payload.scenes.map(s=>s.sceneId),scenes.slice(1)); assert.equal(payload.metrics.find(m=>m.metricTypeId===metricId).points.length,0); stage='keyboard save';await row().locator('input').focus();await page.keyboard.press('ArrowRight'); await page.waitForFunction(id=>document.querySelector(`[data-metric-row="${id}"] input`).dataset.savedValue==='1',metricId); stage='zero save';await row().locator('input').focus();await page.keyboard.press('Home'); await page.waitForFunction(id=>document.querySelector(`[data-metric-row="${id}"] input`).dataset.savedValue==='0',metricId); stage='reload';await page.reload();await row().waitFor();assert.equal(await row().locator('output').innerText(),'0'); stage='pointer save';const range=row().locator('input');const box=await range.boundingBox(); await page.mouse.move(box.x+box.width*.3,box.y+box.height/2);await page.mouse.down();await page.mouse.move(box.x+box.width*.7,box.y+box.height/2,{steps:4});await page.mouse.up(); await page.waitForFunction(id=>Number(document.querySelector(`[data-metric-row="${id}"] input`).dataset.savedValue)>1,metricId); const saved=Number(await row().locator('input').getAttribute('data-saved-value')); stage='narrow layout';await page.setViewportSize({width:580,height:1000}); const layout=await page.locator('[data-context-pane="0"] .context-metrics-panels').evaluate(el=>{const a=el.querySelector('.context-metrics-curve'),b=el.querySelector('.context-metrics-controls');return {stacked:b.getBoundingClientRect().top>=a.getBoundingClientRect().bottom,overflow:el.scrollWidth>el.clientWidth+2};}); assert(layout.stacked&&!layout.overflow); await page.setViewportSize({width:1440,height:1000}); stage='split panes';await page.locator('[data-context-layout]').selectOption('columns');await page.locator('[data-context-pane="1"] [data-context-tab]').selectOption('metrics'); await page.locator('[data-context-pane="1"] [data-metric-slider]').first().waitFor(); assert.equal(await page.locator('[data-context-pane="1"] [data-metric-row="'+metricId+'"] input').getAttribute('data-saved-value'),String(saved)); stage='second window';const second=await page.context().newPage();await second.goto('https://dev.plotdirector.com'+route+'&contextWindow=12100000-0000-4000-8000-000000000001'); await second.locator('[data-context-pane="0"] [data-context-tab]').selectOption('metrics');await second.locator('[data-metric-row="'+metricId+'"] input').waitFor(); assert.equal(await second.locator('[data-metric-row="'+metricId+'"] input').getAttribute('data-saved-value'),String(saved));await second.close(); assert.equal(navigationWrites,0); stage='Timeline agreement';await session.goto('/Timeline?projectId='+project+'&bookId='+book); const timeline=await page.locator('[data-metric-shape-chart] script[type="application/json"]').evaluate(el=>JSON.parse(el.textContent)); assert.equal(timeline.metrics.find(m=>m.metricTypeId===metricId).points.find(p=>p.sceneId===scenes[6]).value,saved); await session.close();session=await open();page=session.page; stage='fresh login';await session.goto(route);await page.locator('[data-context-pane="0"] [data-context-tab]').selectOption('metrics'); await page.locator('[data-context-pane="0"] [data-metric-row="'+metricId+'"] input').waitFor(); assert.equal(await page.locator('[data-context-pane="0"] [data-metric-row="'+metricId+'"] input').getAttribute('data-saved-value'),String(saved)); console.log(JSON.stringify({status:'passed',featureUrl:'https://dev.plotdirector.com'+route,checks:['cross-chapter eleven-scene window','unset versus saved zero','keyboard and pointer commits','reload and fresh-login persistence','Timeline agreement','narrow stacking','split panes','two windows','no Word navigation']})); }catch{console.error('Context Metrics Development acceptance failed at '+stage+'; no credentials logged.');process.exitCode=1;} finally{if(session){try{await session.cleanup();console.log('Disposable fixture cleanup confirmed');}finally{await session.close();}}} })();