15 lines
6.2 KiB
JavaScript
15 lines
6.2 KiB
JavaScript
// Both consumers in one authenticated fixture session: shared appearance, independent preferences.
|
|
const{chromium}=require('playwright'),fs=require('fs'),assert=require('node:assert/strict');const base='http://127.0.0.1:5238',out='/tmp/pd-refinements-evidence',installed=process.argv.includes('--installed'),taxonomy=JSON.parse(fs.readFileSync(process.env.PD_TAXONOMY_FIXTURE||'/tmp/pd-refinements-taxonomy.json'));
|
|
(async()=>{let browser,context,cdp,profile;try{if(installed){profile=fs.mkdtempSync('/tmp/pd-shared-attributes-pwa-');context=await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1440,height:1000}});browser=context.browser();cdp=await browser.newBrowserCDPSession();await context.pages()[0].goto(base+'/fixture?page=calendar-test');await cdp.send('PWA.install',{manifestId:base+'/Projects',installUrlOrBundleUrl:base+'/fixture?page=calendar-test'});await cdp.send('PWA.changeAppUserSettings',{manifestId:base+'/Projects',displayMode:'standalone'});}else{browser=await chromium.launch();context=await browser.newContext({viewport:{width:1440,height:1000}});}let page;if(installed){const opened=context.waitForEvent('page');await cdp.send('PWA.launch',{manifestId:base+'/Projects',url:base+'/fixture?page=calendar-test'});page=await opened;await page.waitForLoadState();assert(await page.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}else page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));const groups=await(await page.request.get(base+'/character-attribute-definitions-fixture')).json();
|
|
await page.route('**/CharacterAttributes/Directory?*',r=>r.fulfill({json:{canEdit:true,groups,characters:Array.from({length:20},(_,i)=>({id:i+1,name:`Fixture character ${i+1}`,version:'v1',values:{importance:i%2?'6':'10',life:i%2?'0':'1',sex:i%2?'1':'2',type:'person',quickAdd:i%2?'0':'1'}}))}}));
|
|
await page.route('**/LocationWorkspace/Directory?*',r=>r.fulfill({json:{canEdit:true,types:taxonomy.filter(t=>t.assignable),taxonomy,locations:Array.from({length:20},(_,i)=>({id:i+1,name:`Zone ${i+1}`,parent:i?1:null,type:taxonomy.find(t=>t.key===(i%2?'room':'house')).value,classification:'',description:'Complete synthetic location description. '.repeat(i%5+1),aliases:[],maps:[],floors:[],scenes:0,characters:0,assets:0,relationships:0,quickAdd:'0',detection:'0',version:'v1'}))}}));
|
|
const theme=async name=>page.evaluate(name=>{document.documentElement.dataset.appTheme=name;document.documentElement.dataset.bsTheme=name.endsWith('dark')?'dark':'light';document.documentElement.dataset.theme=name.endsWith('dark')?'dark':'light';},name);
|
|
await page.goto(base+'/locations-workspace-fixture?count=20');await page.locator('[data-location-records][aria-busy=false]').waitFor();await page.locator('[data-value="@premises"] .pd-attribute-expand').click();const residential=taxonomy.find(t=>t.key==='residential').value;await page.locator(`[data-attribute=type][data-value="${residential}"] .pd-attribute-expand`).click();await page.getByRole('separator',{name:'Resize left panel'}).press('ArrowRight');await page.waitForTimeout(100);const locationStorage=await page.evaluate(()=>Object.fromEntries(Object.keys(localStorage).filter(k=>k.includes('locations')).map(k=>[k,localStorage.getItem(k)])));
|
|
for(const name of ['plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue']){await theme(name);await page.locator('.locations-attributes').screenshot({path:`${out}/locations-attributes-${installed?'pwa':'browser'}-${name}.png`});}
|
|
await page.goto(base+'/character-attributes-fixture?count=20');await page.locator('[data-attribute=importance]').first().waitFor();const group=page.locator('details[data-attribute-group=type]');await group.locator('summary').click();assert.equal(await group.evaluate(n=>n.open),false);const divider=page.getByRole('separator',{name:'Resize Attributes panel'});await divider.press('ArrowRight');const charWidth=await page.locator('[data-attribute-sidebar]').evaluate(n=>Math.round(n.getBoundingClientRect().width));
|
|
for(const name of ['plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue']){await theme(name);await page.locator('[data-attribute-sidebar]').screenshot({path:`${out}/characters-attributes-${installed?'pwa':'browser'}-${name}.png`});}
|
|
await theme('modern-light');await page.screenshot({path:`${out}/characters-cards-${installed?'pwa':'browser'}.png`});const biography=await page.locator('.character-card').first().locator('.visual-card-heading p.muted').textContent();assert(biography.includes('Complete biography for character 1'));const heights=await page.locator('.character-card').evaluateAll(ns=>ns.slice(0,9).map(n=>Math.round(n.getBoundingClientRect().height)));assert(new Set(heights).size>1);
|
|
await page.goto(base+'/locations-workspace-fixture?count=20');await page.locator('[data-location-records][aria-busy=false]').waitFor();await page.waitForTimeout(100);assert.deepEqual(await page.evaluate(()=>Object.fromEntries(Object.keys(localStorage).filter(k=>k.includes('locations')).map(k=>[k,localStorage.getItem(k)]))),locationStorage);assert(await page.locator(`[data-attribute=type][data-value="${taxonomy.find(t=>t.key==='house').value}"]`).isVisible());
|
|
await page.goto(base+'/character-attributes-fixture?count=20');await page.locator('[data-attribute=importance]').first().waitFor();assert.equal(await page.locator('details[data-attribute-group=type]').evaluate(n=>n.open),false);assert.equal(await page.locator('[data-attribute-sidebar]').evaluate(n=>Math.round(n.getBoundingClientRect().width)),charWidth);assert.deepEqual(errors,[]);fs.writeFileSync(`${out}/shared-${installed?'pwa':'browser'}.json`,JSON.stringify({status:'passed',themes:7,checks:['both real consumers use shared renderer','same-session independent group/width preferences','width and nested expansion restore','unaltered character biographies and variable card dimensions']},null,2));console.log('PASS same-session shared Attributes styling, seven themes, independent state and unaltered character cards.');
|
|
}finally{if(cdp)await cdp.send('PWA.uninstall',{manifestId:base+'/Projects'}).catch(()=>{});if(context)await context.close();if(browser?.isConnected())await browser.close();if(profile)fs.rmSync(profile,{recursive:true,force:true});}})().catch(e=>{console.error(e);process.exitCode=1;});
|