PlotDirector/PlotLine.Tests/Browser/writer2-dashboard.cjs

50 lines
5.3 KiB
JavaScript

const {chromium}=require('playwright');
const assert=require('node:assert/strict');
const fs=require('node:fs');
(async()=>{const browser=await chromium.launch();try{
for(const pwa of [false,true]){
const context=await browser.newContext();if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
await context.route('**/signalr.min.js',route=>route.fulfill({contentType:'application/javascript',body:fs.readFileSync(require.resolve('@microsoft/signalr/dist/browser/signalr.min.js'),'utf8')}));
const page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));
for(const populated of [false,true])for(const theme of ['modern-light','modern-dark','warm-light','warm-dark'])for(const width of [390,1024,1440]){
await page.setViewportSize({width,height:1000});await page.addInitScript(theme=>localStorage.setItem('plotdirector.applicationTheme',theme),theme);
await page.goto(`http://127.0.0.1:5238/writer2-fixture?populated=${populated}`);
assert.equal(await page.locator('h1').textContent(),'A Distant Shore');
assert.equal(await page.getByRole('heading',{name:'Start Here',exact:true}).isVisible(),true);
assert.equal(await page.locator('.writer-start-paths a').count(),3);
assert((await page.getByRole('link',{name:/Explore your manuscript/}).getAttribute('href')).includes('/Books/Details/12#chapters'));
await page.getByRole('link',{name:/Continue an existing manuscript/}).click();
await page.locator('[data-objective-chapter]').selectOption('21');
await page.locator('[data-objective-scene]').selectOption('31');
assert.equal(await page.locator('[data-objective-scene] option[value="32"]').evaluate(option=>option.disabled),true);
await page.locator('[data-objective-chapter]').selectOption('22');
assert.equal(await page.locator('[data-objective-scene]').inputValue(),'');
assert.equal(await page.locator('#ribbon-tab-writer').count(),1);
assert.equal(await page.locator('#ribbon-panel-writer').isVisible(),true);
assert.equal(await page.locator('.writer-tabs a').count(),5);
assert.equal(await page.locator('.writer-heading select').count(),0,'Book/project selection belongs to common shell');
const choices=await page.locator('[data-app-book-choice]').evaluateAll(nodes=>nodes.map(n=>n.getAttribute('href')));assert(choices.length>0);assert(choices.every(href=>new URL(href,'http://127.0.0.1:5238').pathname==='/Writer'),'Common book selection stays in Writer');
assert.equal(await page.locator('[data-start-writing-workspace]').isVisible(),false,'No linked document exposes no workspace reapply action');
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth+2),false,`${theme} ${width} overflow`);
await page.locator('.writer-queue-details > summary').click();
assert.equal(await page.locator('[data-writer-queue="WriteNext"]').isVisible(),true);
assert.equal(await page.locator('[data-writer-queue="Revision"]').isVisible(),false);
if(populated){assert.equal(await page.locator('.writer-day').count(),28);assert.equal(await page.locator('.writer-day-observed').count(),2);assert((await page.locator('.writer-activity-graphic').textContent()).includes('+120'));assert((await page.locator('.writer-day-observed').first().getAttribute('href')).includes('day='));}
else{assert((await page.locator('.writer-progress .writer-empty').textContent()).includes('Earlier writing'));assert.equal(await page.locator('.writer-activity-graphic').count(),0);}
await page.getByRole('link',{name:'Connection & Display Setup'}).click();await page.waitForFunction(()=>document.getElementById('display-setup').open);assert.equal(await page.locator('#display-setup').getAttribute('open'),'');
if(theme==='warm-light'&&width===1440&&populated&&!pwa)await page.screenshot({path:'/home/nick/writer2-correction/overview-initial.png',fullPage:true});
if(theme==='warm-light'&&width===390&&populated&&!pwa)await page.screenshot({path:'/home/nick/writer2-correction/overview-small.png',fullPage:true});
}
await page.goto('http://127.0.0.1:5238/writer2-fixture?objective=true');
assert.equal(await page.getByRole('heading',{name:'Continue Writing',exact:true}).isVisible(),true);
assert((await page.getByRole('link',{name:'Continue Writing',exact:true}).getAttribute('href')).includes('/Scenes/Edit/31'));
for(const state of [{connected:true,linked:false,text:'Connected · no linked manuscript open'},{connected:true,linked:true,text:'Connected · linked manuscript open'},{connected:false,linked:false,text:'Disconnected'}]){
await page.evaluate(state=>{const leases=state.linked?[{bookId:12,wordAvailable:true}]:[];leases.connectionState=state.connected?'Connected':'Disconnected';window.dispatchEvent(new CustomEvent('native-companion-presence',{detail:leases}));},state);
assert.equal(await page.locator('[data-writing-workspace-word]').textContent(),state.text);
}
if(!pwa)await page.screenshot({path:'/home/nick/writer2-correction/overview-objective.png',fullPage:true});
assert.deepEqual(errors,[]);await context.close();
}
console.log('PASS Writer 2 overview: real Razor, 48 theme/viewport/history/PWA combinations, single navigation, book scope, honest empty states, chart links and contextual controls.');
}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});