15 lines
8.2 KiB
JavaScript
15 lines
8.2 KiB
JavaScript
// Compiled production pages; the existing shared divider and local preference store.
|
||
const {chromium}=require('playwright'),assert=require('assert/strict'),fs=require('fs'),os=require('os'),path=require('path');
|
||
(async()=>{const installed=process.argv.includes('--installed'),profile=fs.mkdtempSync(path.join(os.tmpdir(),'pd-directory-dividers-')),base='http://127.0.0.1:5238',manifestId=base+'/Projects',out='/tmp/pd-directory-dividers';fs.mkdirSync(out,{recursive:true});let c,cdp,p;const errors=[],calls={attributes:0,search:0,details:0,other:0},saved={},measurements=[];
|
||
async function launch(restart=false){c=await chromium.launchPersistentContext(profile,{headless:!installed,viewport:{width:1920,height:1080}});p=c.pages()[0];await c.route('https://cdn.jsdelivr.net/**',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(path.join(__dirname,'node_modules',r.request().url().includes('chart.umd')?'chart.js/dist/chart.umd.js':'@microsoft/signalr/dist/browser/signalr.min.js'))}));const groups=await(await p.request.get(base+'/character-attribute-definitions-fixture')).json();await c.route('**/CharacterAttributes/Directory?*',r=>{calls.attributes++;return r.fulfill({json:{canEdit:true,groups,characters:Array.from({length:100},(_,n)=>({id:n+1,name:'Fixture character '+(n+1),version:'v1',values:{importance:'6',life:'',sex:'',type:'unclassified',quickAdd:'0'}}))}})});for(const part of ['Results','Details'])await c.route('**/Names/'+part+'?*',async r=>{calls[part==='Results'?'search':'details']++;const u=new URL(r.request().url());return r.fulfill({response:await p.request.get(base+'/names-workspace-fixture/'+part.toLowerCase()+'?'+u.searchParams)})});c.on('request',r=>{if(/\/NameVerification\/|\/CharacterAttributes\/(Assign|Undo)/.test(new URL(r.url()).pathname))calls.other++});await p.goto(base+'/fixture?page=calendar-test');if(installed){cdp=await c.browser().newBrowserCDPSession();if(!restart){await cdp.send('PWA.install',{manifestId,installUrlOrBundleUrl:p.url()});await cdp.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'})}const opened=c.waitForEvent('page');await cdp.send('PWA.launch',{manifestId,url:p.url()});p=await opened;await p.waitForLoadState();assert(await p.evaluate(()=>matchMedia('(display-mode: standalone)').matches));await p.setViewportSize({width:1920,height:1080})}p.on('pageerror',e=>errors.push(e.message));}
|
||
const width=selector=>p.locator(selector).evaluate(n=>n.getBoundingClientRect().width),pause=()=>p.evaluate(()=>new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r))));
|
||
async function drag(handle,delta){const b=await handle.boundingBox(),y=Math.max(220,Math.min(550,b.y+40));await p.mouse.move(b.x+b.width/2,y);await p.mouse.down();await p.mouse.move(b.x+b.width/2+delta,y,{steps:15});await p.mouse.up();await pause();assert.equal(await p.evaluate(()=>document.documentElement.classList.contains('pd-panel-resizing')),false)}
|
||
async function preference(name){return p.evaluate(name=>{const key=Object.keys(localStorage).find(k=>k.startsWith('plotdirector.workspace.panels.'+name+'.'));return {key,...JSON.parse(localStorage.getItem(key))}},name)}
|
||
try{await launch();await p.goto(base+'/character-attributes-fixture?count=100');await p.locator('[data-attribute-groups] details').first().waitFor();const ch=p.getByRole('separator',{name:'Resize Attributes panel'}),side='[data-attribute-sidebar]',grid='.character-card-grid';await ch.waitFor();const biographies=await p.locator('.visual-card-heading p.muted').allTextContents(),gridBefore=await width(grid),before={...calls};await drag(ch,160);assert(Math.abs(await width(side)-416)<2);assert(await width(grid)<gridBefore-150);await ch.press('ArrowLeft');assert(Math.abs(await width(side)-406)<2);await drag(ch,1000);assert(Math.abs(await width(side)-480)<2);await drag(ch,-1000);assert(Math.abs(await width(side)-224)<2);await ch.press('Home');assert(Math.abs(await width(side)-256)<2);await drag(ch,150);saved.characters=await preference('characters');assert.deepEqual(calls,before);await p.reload();await ch.waitFor();assert(Math.abs(await width(side)-406)<2);await p.locator('[data-attributes-toggle]').click();await pause();assert(await ch.isHidden());assert(await width(grid)>gridBefore+250);await p.locator('[data-attributes-toggle]').click();await ch.waitFor();assert(Math.abs(await width(side)-406)<2);await p.evaluate(()=>scrollTo({top:1200,behavior:'instant'}));const sticky=await p.locator(side).boundingBox();assert(sticky.y>=0&&sticky.y+sticky.height<=1081);await p.evaluate(()=>scrollTo({top:0,behavior:'instant'}));assert.deepEqual(await p.locator('.visual-card-heading p.muted').allTextContents(),biographies);
|
||
await p.goto(base+'/names-workspace-fixture/page');await p.locator('[name=Search]').fill('George');await p.locator('[name=SortOrder]').selectOption('name-desc');await p.waitForFunction(()=>JSON.parse(document.querySelector('[data-names-applied]').textContent).SortOrder==='name-desc');await p.locator('[data-name-select]').first().click();await p.locator('[data-name-details-fragment]').waitFor();const nh=p.getByRole('separator',{name:'Resize name results and details'}),results='[data-names-results-host]';await nh.waitFor();const initial=await width(results),namesBefore={...calls},selected=await p.locator('[data-name-details-fragment] h2').innerText();await drag(nh,-150);assert(Math.abs(await width(results)-(initial-150))<2);await drag(nh,5000);assert(await width('[data-names-details]')>=319);await drag(nh,-5000);assert(Math.abs(await width(results)-280)<2);await drag(nh,initial-150-280);saved.names=await preference('names');assert(saved.names.left!==saved.characters.left);assert.deepEqual(calls,namesBefore);assert.equal(await p.locator('[name=SortOrder]').inputValue(),'name-desc');assert.equal(await p.locator('[data-name-details-fragment] h2').innerText(),selected);await p.reload();await nh.waitFor();assert(Math.abs(await width(results)-saved.names.left)<2);
|
||
for(const kind of ['names','characters']){await p.goto(base+(kind==='names'?'/names-workspace-fixture/page':'/character-attributes-fixture?count=100'));const handle=kind==='names'?nh:ch;await handle.waitFor();for(const w of [1280,1920,2560,3840,800,390,1920]){await p.setViewportSize({width:w,height:1080});await pause();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2),kind+' overflow '+w);if(w===390)assert(await handle.isHidden());const current=await preference(kind);assert.equal(current.left,saved[kind].left,'viewport changes must not overwrite preference');if(w===2560)await p.screenshot({path:`${out}/${installed?'pwa':'browser'}-${kind}-2560.png`});measurements.push({kind,viewport:w,leftWidth:await width(kind==='names'?results:side),columns:kind==='characters'?await p.locator(grid).evaluate(n=>getComputedStyle(n).gridTemplateColumns.split(' ').length):null});}for(const theme of ['plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue']){await p.evaluate(t=>{document.documentElement.dataset.appTheme=t;document.documentElement.dataset.bsTheme=t.endsWith('dark')?'dark':'light'},theme);await p.screenshot({path:`${out}/${installed?'pwa':'browser'}-${kind}-${theme}.png`})}}
|
||
// Persisted main Names state remains untouched by these panel controls; Context never mounts them.
|
||
await c.close();await launch(true);for(const kind of ['names','characters']){await p.goto(base+(kind==='names'?'/names-workspace-fixture/page':'/character-attributes-fixture?count=100'));await p.getByRole('separator').waitFor();assert(Math.abs(await width(kind==='names'?results:side)-saved[kind].left)<2,kind+' survives complete Chromium/PWA restart')}
|
||
assert.equal(calls.other,0);assert.deepEqual(errors,[]);fs.writeFileSync(`${out}/${installed?'pwa':'browser'}.json`,JSON.stringify({status:'passed',actualInstalledPwa:installed,restartedPersistentProfile:true,saved,calls,measurements,biographiesPreserved:true},null,2));console.log('PASS independent pointer/keyboard dividers, bounds, sticky/collapse, no lookup/AI requests on resize, navigation/refresh/profile restart, seven themes, 390–3840 widths and '+(installed?'actual installed PWA':'browser'));
|
||
}finally{if(cdp)await cdp.send('PWA.uninstall',{manifestId}).catch(()=>{});await c?.close();fs.rmSync(profile,{recursive:true,force:true})}})().catch(e=>{console.error(e.name+': '+e.message.split('Call log:')[0]);process.exitCode=1});
|