12 lines
6.5 KiB
JavaScript
12 lines
6.5 KiB
JavaScript
const {chromium}=require('playwright'),assert=require('assert/strict'),fs=require('fs'),os=require('os'),path=require('path');
|
|
(async()=>{const installed=process.argv.includes('--installed'),base='http://127.0.0.1:5238',profile=installed?fs.mkdtempSync(path.join(os.tmpdir(),'pd-icons-pwa-')):null,b=installed?null:await chromium.launch(),c=installed?await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1920,height:1200}}):await b.newContext({viewport:{width:1920,height:1200}});let p=installed?c.pages()[0]:await c.newPage(),cdp;try{
|
|
if(installed){await p.goto(base+'/fixture?page=calendar-test');cdp=await c.browser().newBrowserCDPSession();await cdp.send('PWA.install',{manifestId:base+'/Projects',installUrlOrBundleUrl:p.url()});await cdp.send('PWA.changeAppUserSettings',{manifestId:base+'/Projects',displayMode:'standalone'});const opened=c.waitForEvent('page');await cdp.send('PWA.launch',{manifestId:base+'/Projects',url:p.url()});p=await opened;await p.waitForLoadState();assert(await p.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}
|
|
const groups=await (await p.request.get(base+'/character-attribute-definitions-fixture')).json(),records=Array.from({length:48},(_,i)=>({id:i+1,name:`Fixture character ${i+1}`,version:'v1',values:{importance:['10','6','2',''][i%4],life:'',sex:['1','2','3','','legacy:Recorded legacy sex','legacy:Male','legacy:Female','legacy: female '][i%8],type:'unclassified',quickAdd:'0'}}));await p.route('**/CharacterAttributes/Directory?*',r=>r.fulfill({json:{canEdit:true,groups,characters:records}}));await p.goto(base+'/character-attributes-fixture?count=48');await p.locator('[data-attribute-indicators] svg').first().waitFor();assert.deepEqual(await p.locator('[data-attribute-groups] summary').allTextContents(),['Story importance','Life status','Sex','Character Type','Quick Add Bar']);
|
|
assert.equal(await p.locator('[data-attribute="importance"][data-value="10"] path').getAttribute('fill'),'currentColor');assert.equal(await p.locator('[data-attribute="importance"][data-value="6"] path').getAttribute('fill-rule'),'evenodd');assert.equal(await p.locator('[data-attribute="importance"][data-value="2"] path').getAttribute('fill'),'none');
|
|
const male=p.locator('.character-card[data-drag-id="6"] [title="Sex: Male"]'),female=p.locator('.character-card[data-drag-id="7"] [title="Sex: Female"]');assert.equal(await male.locator('path').getAttribute('d'),groups.find(g=>g.id==='sex').values.find(v=>v.label==='Male').path);assert.equal(await female.locator('path').getAttribute('d'),groups.find(g=>g.id==='sex').values.find(v=>v.label==='Female').path);assert.equal(await p.locator('.character-card[data-drag-id="8"] [title="Sex: Female"]').count(),1);assert(await male.locator('svg').evaluate(n=>n.classList.contains('text-info')));assert(await female.locator('svg').evaluate(n=>n.classList.contains('text-data-7')));const maleFilter=p.locator('[data-attribute="sex"][data-value="1"] button').first();await maleFilter.click();assert(await p.locator('.character-card[data-drag-id="6"]').isVisible());assert(await p.locator('.character-card[data-drag-id="7"]').isHidden());await maleFilter.click();
|
|
await p.locator('.character-card[data-drag-id="7"]').scrollIntoViewIfNeeded();await p.evaluate(()=>getSelection()?.removeAllRanges());await p.locator('.character-card[data-drag-id="7"]').click({button:'right'});await p.getByRole('menuitem',{name:'Sex',exact:true}).hover();assert.equal(await p.getByRole('menuitemradio',{name:'Female',exact:true}).getAttribute('aria-checked'),'true');assert.equal(await p.getByRole('menuitemradio',{name:'Male',exact:true}).getAttribute('aria-checked'),'false');await p.keyboard.press('Escape');await p.evaluate(()=>scrollTo({top:0,behavior:'instant'}));
|
|
const out='/tmp/pd-ui-refinements';fs.mkdirSync(out,{recursive:true});const contrast=[];
|
|
for(const theme of ['plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue']){await p.evaluate(theme=>{document.documentElement.dataset.appTheme=theme;document.documentElement.dataset.bsTheme=theme.endsWith('dark')?'dark':'light';document.documentElement.dataset.theme=theme.endsWith('dark')?'dark':'light';},theme);const ratios=await p.evaluate(()=>{const canvas=document.createElement('canvas');canvas.width=canvas.height=1;const context=canvas.getContext('2d');function luminance(color){context.clearRect(0,0,1,1);context.fillStyle=color;context.fillRect(0,0,1,1);const rgb=[...context.getImageData(0,0,1,1).data].slice(0,3).map(x=>x/255).map(x=>x<=.04045?x/12.92:((x+.055)/1.055)**2.4);return .2126*rgb[0]+.7152*rgb[1]+.0722*rgb[2];}const bg=luminance(getComputedStyle(document.querySelector('[data-attribute-sidebar]')).backgroundColor);return [...document.querySelectorAll('[data-attribute="importance"] svg,[data-attribute="sex"] svg')].map(svg=>{const fg=luminance(getComputedStyle(svg).color);return (Math.max(fg,bg)+.05)/(Math.min(fg,bg)+.05)});});assert(ratios.every(x=>x>=3),theme+' icon contrast '+ratios);contrast.push({theme,minimumIconContrast:Math.min(...ratios)});for(const button of await p.getByRole('button',{name:/Dismiss .* notification/}).all())await button.click().catch(()=>{});await p.screenshot({path:`${out}/icons-${installed?'pwa':'browser'}-${theme}.png`});}
|
|
const card=p.locator('.character-card').first(),box=await card.boundingBox();await card.click({button:'right',position:{x:box.width-8,y:box.height-8}});const menus=await p.getByRole('menuitem').allTextContents();assert(menus.indexOf('Story importance')<menus.indexOf('Sex')&&menus.indexOf('Sex')<menus.indexOf('Character Type')&&menus.indexOf('Character Type')<menus.indexOf('Quick Add Bar'));await p.getByRole('menuitem',{name:'Story importance',exact:true}).hover();await p.getByRole('menuitemradio',{name:'Supporting',exact:true}).waitFor();assert.equal(await p.getByRole('menuitemradio',{name:'Supporting',exact:true}).locator('path').getAttribute('fill'),'currentColor');await p.screenshot({path:`${out}/importance-menu-${installed?'pwa':'browser'}.png`});await p.keyboard.press('Escape');fs.writeFileSync(`${out}/contrast-${installed?'pwa':'browser'}.json`,JSON.stringify(contrast,null,2));console.log('PASS shared importance/sex symbols, canonical order, legacy/custom labels, menu filled SVG and all seven theme icon contrasts',contrast);
|
|
}finally{if(cdp)await cdp.send('PWA.uninstall',{manifestId:base+'/Projects'}).catch(()=>{});await c.close();if(b)await b.close();if(profile)fs.rmSync(profile,{recursive:true,force:true});}})().catch(e=>{console.error(e.name+': '+e.message.split('Call log:')[0]);process.exitCode=1});
|