37 lines
9.8 KiB
JavaScript
37 lines
9.8 KiB
JavaScript
const{chromium}=require('playwright'),fs=require('fs'),assert=require('node:assert/strict');
|
|
const identity=process.env.PD_LAYOUT_IDENTITY?JSON.parse(fs.readFileSync(process.env.PD_LAYOUT_IDENTITY)):null,w=identity||{UserID:4,project:7,book:12,chapter:21,chapter2:22};
|
|
const base=identity?'https://dev.plotdirector.com':'http://127.0.0.1:5238',before=process.env.PD_LAYOUT_STAGE==='before',out=process.env.PD_LAYOUT_SCREENSHOTS;
|
|
const paths=['Write','Explore','Plan','Review','Reflect'];
|
|
(async()=>{const b=await chromium.launch();const results=[];try{for(const pwa of(before?[true]:[false,true])){
|
|
const c=await b.newContext({viewport:{width:1440,height:1000}});await c.addInitScript(({u,pwa})=>{localStorage.setItem('plotdirector.desktop.v1.'+u,JSON.stringify({dismissedAt:Date.now()}));if(pwa)Object.defineProperty(navigator,'standalone',{value:true});},{u:w.UserID,pwa});const p=await c.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));
|
|
if(identity){await p.goto(base+'/Account/Login');await p.locator('[name=Email]').fill(w.Email);await p.locator('[name=Password]').fill(w.Password);await Promise.all([p.waitForURL('**/Projects'),p.locator('button[type=submit]').click()]);}
|
|
const expand=async()=>{const x=p.locator('[data-ribbon-collapse]');if(await x.getAttribute('aria-expanded')==='false')await x.click();await p.waitForFunction(()=>!document.querySelector('[data-ribbon-collapse]').disabled);};
|
|
const snap=async name=>{if(out&&pwa){await p.mouse.move(2,995);await p.waitForTimeout(200);fs.mkdirSync(out,{recursive:true});await p.screenshot({path:out+'/'+name+'.png',animations:'disabled'});}};
|
|
for(const d of paths){await p.goto(`${base}/Writer/${d}?projectId=${w.project}&bookId=${w.book}`);await p.evaluate(()=>{for(const k of Object.keys(localStorage).filter(k=>k.startsWith('plotdirector.writerLayout.')))localStorage.removeItem(k)});await p.reload();if(!before)await expand();await p.waitForTimeout(150);if(!before&&['Explore','Plan','Reflect'].includes(d)){assert.equal(await p.locator('.writer3-reference').count(),0,d+' intentionally has one working surface without a Word/reference column');assert(await p.locator('[data-writer-companion-toggle]').isHidden());assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));assert.equal(await p.locator('.writer3-layout-tools').count(),0);assert.equal(await p.locator('.writer3-header .writer3-cover').count(),0);await snap(d+'-working-surface');results.push({pwa,d,layout:'phase2-purposeful-surface'});continue;}const toggle=p.locator(before?'.writer3-layout-tools button':'[data-writer-companion-toggle]').first();assert(await p.locator('.writer3-reference').isVisible());const measure=()=>p.locator('.writer3-main').evaluate(n=>({working:(n.querySelector('.reader-controls')||n.querySelector('.writer-focus-wizard,.writer-objective-form,.writer3-explore-paths,.writer3-stat-grid,.writer3-inset')||n).getBoundingClientRect().width,width:n.clientWidth,scroll:getComputedStyle(n).overflowY,child:[...n.children].filter(n=>n.getBoundingClientRect().width>0).map(n=>n.getBoundingClientRect().width),max:Math.max(...[...n.children].map(n=>n.getBoundingClientRect().width))}));const shown=await measure();await snap(d+'-shown');await toggle.click();await p.waitForTimeout(100);assert(await p.locator('.writer3-reference').isHidden());const hidden=await measure();await snap(d+'-hidden');
|
|
if(!before){assert(hidden.width>shown.width+200);assert(hidden.working>shown.working+150,d+' internal working surface reflow');assert.equal(hidden.scroll,'visible');assert.equal(await p.locator('.writer3-layout-tools').count(),0);assert.equal(await p.locator('.writer3-header .writer3-cover').count(),0);assert.equal(await p.locator('.writer3-connection').count(),0);assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));await p.reload();assert(await p.locator('.writer3-reference').isHidden());await p.locator('[data-writer-companion-toggle]').click();assert(await p.locator('.writer3-reference').isVisible());const divider=p.locator('.writer3-divider');await divider.focus();const a=await p.locator('.writer3-reference').evaluate(n=>n.getBoundingClientRect().width);await p.keyboard.press('ArrowLeft');const z=await p.locator('.writer3-reference').evaluate(n=>n.getBoundingClientRect().width);assert(z>=a+5);await p.locator('[data-help-key="writer3.layout"] button').click();await p.locator('.plotline-help-popover').waitFor();await p.keyboard.press('Escape');}
|
|
results.push({pwa,d,shown,hidden});
|
|
}
|
|
for(const [name,path]of[['Home','/Writer/Index'],['Desk-alias','/Writer/Overview'],['Scene-queues','/Writer/Workspaces'],['Reader-alias','/manuscript/reader']]){await p.goto(`${base}${path}?projectId=${w.project}&bookId=${w.book}&chapterId=${w.chapter}`);await snap(name);if(!before&&name==='Scene-queues'){assert(await p.locator('.writer-workspaces').isVisible());assert.equal(await p.locator('.writer-studio').evaluate(n=>[...n.children].filter(c=>getComputedStyle(c).display!=='none'&&!c.matches('.writer-heading,.writer-workspaces')).length),0);}if(!before&&name==='Reader-alias'){assert(p.url().includes('/Writer/Review'));assert(await p.locator('.manuscript-reader[data-reading=true]').count());}}
|
|
if(!before){
|
|
await p.goto(`${base}/Writer/Review?bookId=${w.book}&chapterId=${w.chapter}`);const t=p.locator('[data-writer-companion-toggle]');if(await p.locator('.writer3-reference').isVisible())await t.click();if(await p.locator('.writer2-chapter-context[open] > summary').isVisible())await p.locator('.writer2-chapter-context > summary').click();const centred=await p.locator('.reader-page').evaluate(n=>{const a=n.getBoundingClientRect(),b=n.closest('.writer3-main').getBoundingClientRect();return Math.abs((a.left+a.right-b.left-b.right)/2)});assert(centred<3);const nav=await p.locator('.reader-controls').evaluate(n=>({width:n.getBoundingClientRect().width,main:n.closest('.writer3-main').clientWidth}));assert(nav.width>nav.main*.9);await snap('Review-centred-toolbar');await p.locator('.reader-mode-controls a').click();assert(await p.locator('.writer3-reference').isHidden());await snap('Reading-mode');await p.locator('#reader-focus').click();assert.equal(await p.locator('.manuscript-reader').getAttribute('data-focus'),'true');await snap('Focus-reading');await p.locator('.reader-controls a[rel=next]').click();assert.equal(await p.locator('.manuscript-reader').getAttribute('data-focus'),'true');assert.equal(await p.locator('.manuscript-reader').getAttribute('data-chapter-id'),String(w.chapter2));await snap('Focus-next-chapter');await p.locator('#reader-focus').click();assert.equal(await p.locator('.manuscript-reader').getAttribute('data-focus'),'false');
|
|
for(const width of[1920,1024,800]){await p.setViewportSize({width,height:1000});await p.goto(`${base}/Writer/Review?bookId=${w.book}`);assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));await snap('Review-'+width);}
|
|
await p.setViewportSize({width:1440,height:1000});await p.goto(`${base}/Writer/Review?bookId=${w.book}&reader-long=true`);if(await p.locator('.writer3-reference').isHidden())await p.locator('[data-writer-companion-toggle]').click();for(const collapsed of[false,true]){const collapse=p.locator('[data-ribbon-collapse]');if((await collapse.getAttribute('aria-expanded')==='false')!==collapsed)await collapse.click();await p.evaluate(()=>window.scrollTo(0,1100));await p.waitForTimeout(200);const pos=await p.evaluate(()=>({top:document.querySelector('.writer3-reference').getBoundingClientRect().top,bottom:document.querySelector('.pd-application-header').getBoundingClientRect().bottom}));if(pwa)assert(pos.top>=pos.bottom-1);await snap(collapsed?'Sticky-collapsed':'Sticky-expanded');await p.evaluate(()=>window.scrollTo(0,0));}
|
|
// An external history boundary must be disabled; all subsequent Back actions stay native/internal.
|
|
await c.route('http://outside.invalid/**',r=>r.fulfill({contentType:'text/html',body:`<a href="${base}/Writer/Index?projectId=${w.project}&bookId=${w.book}">Enter</a>`}));await p.goto('http://outside.invalid/start');await p.getByText('Enter').click();await expand();assert(await p.locator('[data-app-back]').isDisabled());
|
|
for(const d of['Write','Explore','Plan'])await p.locator('#ribbon-panel-writer').getByRole('link',{name:d,exact:true}).click();await expand();for(const d of['Explore','Write','Index']){await p.locator('[data-app-back]').click();await p.waitForURL(u=>u.pathname.toLowerCase()==='/writer/'+d.toLowerCase());}assert(await p.locator('[data-app-back]').isDisabled());await snap('Ribbon-back-boundary');
|
|
if(identity){
|
|
// Follow actual authenticated ribbon links and nested entry points across modules.
|
|
const trail=[];
|
|
for(const [tab,label]of[['Characters','Characters'],['World','Locations'],['Project','Overview'],['Writer','Review']]){
|
|
await expand();await p.getByRole('tab',{name:tab,exact:true}).click();if(tab==='Writer'){await p.waitForURL(u=>u.pathname==='/Writer'||u.pathname==='/Writer/Index');trail.push(p.url());await expand();}
|
|
await p.locator('.pd-ribbon-panel:not([hidden])').getByRole('link',{name:label,exact:true}).first().click();
|
|
await p.waitForLoadState('load');trail.push(p.url());assert(await p.locator('[data-app-back]').isEnabled());if(tab==='Project'){await p.locator('a[href="/Books/Details/'+w.book+'"]:visible').first().click();await p.waitForLoadState('load');trail.push(p.url());}
|
|
}
|
|
for(const expected of trail.slice(0,-1).reverse()){await p.locator('[data-app-back]').click();await p.waitForURL(expected);}
|
|
await snap('Back-across-sections');results.push({pwa,crossSectionTrail:trail.map(u=>new URL(u).pathname)});
|
|
}
|
|
|
|
}
|
|
assert.deepEqual(errors,[]);await c.close();}
|
|
console.log(JSON.stringify(results,null,2));console.log('PASS Writer layout Phase1: rendered reflow, persistent ribbon companion, divider, help, shared reading/focus, sticky chrome and native safe Back; before='+before);}finally{await b.close();}})().catch(e=>{console.error(e.stack);process.exitCode=1});
|