17 lines
3.0 KiB
JavaScript
17 lines
3.0 KiB
JavaScript
const {chromium}=require('playwright');const assert=require('node:assert/strict');
|
|
(async()=>{const b=await chromium.launch();try{const page=await b.newPage({viewport:{width:1440,height:1000}});await page.goto('http://127.0.0.1:5238/fixture?page=dashboard');
|
|
await page.locator('#accountMenuButton').click();assert.equal(await page.locator('[data-app-theme-choice]').count(),7);const picker=await page.locator('.pd-theme-picker').boundingBox();const house=await page.locator('[data-app-theme-choice=plotdirector]').boundingBox();assert(Math.abs(picker.width-house.width)<1);const other=await page.locator('[data-app-theme-choice=modern-light]').boundingBox();assert(other.y>house.y&&other.width<house.width/2);await page.locator('[data-app-theme-choice=plotdirector]').click();await page.waitForFunction(()=>!document.querySelector('[data-app-theme-choice]').disabled);await page.keyboard.press('Escape');assert.equal(await page.locator('html').getAttribute('data-app-theme'),'plotdirector');
|
|
const pairs=await page.evaluate(()=>{
|
|
const style=getComputedStyle(document.documentElement),ctx=document.createElement('canvas').getContext('2d');
|
|
const lum=color=>{ctx.fillStyle=color;ctx.fillRect(0,0,1,1);return [...ctx.getImageData(0,0,1,1).data].slice(0,3).map(n=>n/255).map(n=>n<=.04045?n/12.92:((n+.055)/1.055)**2.4).reduce((a,n,i)=>a+n*[.2126,.7152,.0722][i],0)};
|
|
const token=n=>style.getPropertyValue('--pd-'+n).trim();const ratio=(a,c)=>(Math.max(lum(a),lum(c))+.05)/(Math.min(lum(a),lum(c))+.05);
|
|
const checks=[];for(const bg of ['workspace','surface','surface-2','selected','hover','elevated'])for(const fg of ['text','muted','heading'])checks.push([fg+'/'+bg,ratio(token(fg),token(bg)),4.5]);
|
|
checks.push(['button',ratio(token('on-accent'),token('accent')),4.5],['button hover',ratio(token('on-accent'),token('accent-hover')),4.5],['control boundary',ratio(token('border'),token('surface')),3]);
|
|
for(const bg of ['workspace','surface','selected'])checks.push(['focus/'+bg,ratio(token('focus'),token(bg)),3]);
|
|
for(const fg of ['success','danger','warning','info'])checks.push([fg+' badge',ratio(token('on-accent'),token(fg)),4.5]);
|
|
for(let i=1;i<=11;i++)for(const bg of ['surface','surface-2','workspace'])checks.push(['data '+i+'/'+bg,ratio(token('data-'+i),token(bg)),3]);return checks;
|
|
});for(const[name,value,minimum]of pairs)assert(value>=minimum,`${name}: ${value}`);console.log('CONTRAST',JSON.stringify(pairs));
|
|
for(const size of [390,768,1440]){await page.setViewportSize({width:size,height:1000});for(const view of ['dashboard','timeline','relationships']){await page.goto('http://127.0.0.1:5238/fixture?page='+view);assert.equal(await page.locator('html').getAttribute('data-app-theme'),'plotdirector');await page.screenshot({path:`/tmp/house-theme-${view}-${size}.png`});}}
|
|
console.log('PASS house theme: seven choices, selection persists, all surface text/button/status/focus/data contrasts; dashboard, Timeline, relationships at 390/768/1440');
|
|
}finally{await b.close();}})().catch(e=>{console.error(e);process.exit(1)});
|