"""One bounded real-component inspection of the handed Theme package on loopback.""" from pathlib import Path import json from playwright.sync_api import sync_playwright from browser_zoom import zoom_browser, set_browser_zoom ORIGIN = 'http://127.0.0.1:5199' OUT = Path(__file__).parent / 'scadabridge-first-inspection' OUT.mkdir(exist_ok=True) FAMILIES = { 'default': ('#2f5fd0','#1e3f99','#eef2fc'), 'historian': ('#2f855a','#1c6540','#edf5f0'), 'btdb': ('#1b7f8e','#125764','#eaf5f6'), 'overview': ('#6d28d9','#4c1d95','#f2ecfc'), } results=[] def rgb(h): return 'rgb('+', '.join(str(int(h[i:i+2],16)) for i in (1,3,5))+')' def css(page, selector): return page.locator(selector).first.evaluate('''e=>{let c=getComputedStyle(e);return {color:c.color,background:c.backgroundColor,border:c.borderColor,outlineStyle:c.outlineStyle,outlineWidth:c.outlineWidth,outlineColor:c.outlineColor,boxShadow:c.boxShadow,opacity:c.opacity,animationName:c.animationName,animationDuration:c.animationDuration,transform:c.transform,focusVisible:e.matches(':focus-visible')};}''') def check(record,name,passed,actual=None): record['checks'].append({'name':name,'passed':bool(passed),'actual':actual}) def tab_to(page,selector): page.locator('body').click(position={'x':2,'y':2}) for _ in range(40): page.keyboard.press('Tab') if page.locator(selector).first.evaluate('(e)=>e===document.activeElement'):return True return False def nav_probe(page,record): shell=page.locator('details.app-shell').first narrow=page.evaluate('innerWidth<992') record['nativeNav']={'narrow':narrow,'pageVisibleClosed':page.locator('main.page').first.is_visible()} if narrow: toggle=page.locator('details.app-shell>summary.rail-toggle').first if shell.get_attribute('open') is not None:toggle.click() closed=page.locator('main.page').first.is_visible() and not page.locator('.theme-rail').first.is_visible() toggle.click() opened=shell.get_attribute('open') is not None and page.locator('.theme-rail').first.is_visible() toggle.click() reclosed=shell.get_attribute('open') is None and page.locator('main.page').first.is_visible() check(record,'native nav opens/closes while retaining page',closed and opened and reclosed,{'closed':closed,'opened':opened,'reclosed':reclosed}) else:check(record,'desktop rail visible',page.locator('.theme-rail').first.is_visible()) def inspect(kind,width,scheme='light',family=None,zoom=1): page=context.new_page() page.set_viewport_size({'width':width,'height':1000}) page.emulate_media(reduced_motion='reduce',color_scheme=scheme) errors=[] page.on('pageerror',lambda e:errors.append(str(e))) route='/accent?family='+family if kind=='accent' else ('/login' if kind=='login' else '/') record={'kind':kind,'family':family,'scheme':scheme,'physicalViewport':width,'zoom':zoom,'checks':[]} try: response=page.goto(ORIGIN+route,wait_until='domcontentloaded') record['status']=response.status if kind in ('root','login'): record['immediateReducedMotion']=css(page,'#canary-rise' if kind=='root' else '.login-wrap.rise') c=record['immediateReducedMotion'];check(record,'reduced motion content immediately visible',c['opacity']=='1' and c['animationName']=='none',c) page.wait_for_load_state('networkidle') page.wait_for_function('window.Blazor!==undefined && window.sbTheme!==undefined') if scheme=='dark':page.evaluate("window.sbTheme.set('dark')") else:page.evaluate("window.sbTheme.set('light')") if zoom!=1: record['browserZoom']=set_browser_zoom(worker,page,zoom) check(record,'real 200% browser zoom',page.evaluate('innerWidth')==width/2 and page.evaluate('devicePixelRatio')==2,{'innerWidth':page.evaluate('innerWidth'),'DPR':page.evaluate('devicePixelRatio')}) record['viewport']=page.evaluate('({innerWidth,innerHeight,DPR:devicePixelRatio})') overflow=page.evaluate('document.documentElement.scrollWidth>innerWidth') check(record,'no document horizontal overflow',not overflow) if kind!='login':nav_probe(page,record) if kind=='accent': accent,deep,tint=FAMILIES[family] record['activeNav']=css(page,'.rail-link.active') check(record,'selected nav uses supplied tint',record['activeNav']['background']==rgb(tint),record['activeNav']) record['primaryNormal']=css(page,'#canary-family-primary') check(record,'primary normal uses supplied accent',record['primaryNormal']['background']==rgb(accent),record['primaryNormal']) check(record,'light primary labels white',record['primaryNormal']['color']==rgb('#ffffff')) record['link']=css(page,'#canary-family-link');record['ghost']=css(page,'#canary-family-ghost') check(record,'links and ghost use deep ink',record['link']['color']==rgb(deep) and record['ghost']['color']==rgb(deep),{'link':record['link'],'ghost':record['ghost']}) page.locator('#canary-family-primary').hover() page.wait_for_function("!document.querySelector('#canary-family-primary').getAnimations().some(a=>a.playState==='running')") record['primaryHover']=css(page,'#canary-family-primary') check(record,'primary hover uses supplied deep',record['primaryHover']['background']==rgb(deep),record['primaryHover']) page.mouse.down() record['primaryPressed']=css(page,'#canary-family-primary') check(record,'primary pressed uses supplied deep',record['primaryPressed']['background']==rgb(deep),record['primaryPressed']) page.mouse.up() reached=tab_to(page,'#canary-family-primary');record['primaryFocus']=css(page,'#canary-family-primary') check(record,'keyboard primary focus visible and supplied deep',reached and record['primaryFocus']['focusVisible'] and record['primaryFocus']['outlineStyle']=='solid' and record['primaryFocus']['outlineColor']==rgb(deep),record['primaryFocus']) check(record,'caller-disabled remains disabled',page.locator('#canary-family-disabled').is_disabled()) record['disabledPrimary']=css(page,'#canary-family-disabled') record['semanticInfo']=css(page,'.chip-info') check(record,'semantic info independent blue',record['semanticInfo']['color']==rgb('#1e3f99'),record['semanticInfo']) elif kind=='root': field=page.locator('#canary-field') record['fieldInitial']={'describedBy':field.get_attribute('aria-describedby'),'invalid':field.get_attribute('aria-invalid'),'labelFor':page.locator("label[for='canary-field']").get_attribute('for'),'errorText':page.locator('#canary-field-error').inner_text()} check(record,'field label hint error association',record['fieldInitial']['describedBy']=='canary-field-hint canary-field-error' and record['fieldInitial']['invalid']=='true',record['fieldInitial']) page.locator("label[for='canary-field']").click() check(record,'label activates input',field.evaluate('(e)=>e===document.activeElement')) field.fill('synthetic label') page.wait_for_function("document.querySelector('#canary-field').getAttribute('aria-invalid')==='false'") check(record,'field error clears and removes dead description',field.get_attribute('aria-describedby')=='canary-field-hint' and page.locator('#canary-field-error').count()==0) reached=tab_to(page,'#canary-from');record['fieldFocus']=css(page,'#canary-from') expected=rgb('#a7c1ff' if scheme=='dark' else '#1e3f99') check(record,'actual date control receives visible family focus',reached and record['fieldFocus']['focusVisible'] and record['fieldFocus']['outlineStyle']=='solid' and record['fieldFocus']['outlineColor']==expected,record['fieldFocus']) check(record,'caller-disabled local action remains disabled',page.locator('#canary-caller-disabled').is_disabled()) for case,busy_text,outcome in [('success','Saving local sample…','Local sample saved.'),('failure','Trying local sample…','Local sample failed. Try again.')]: button=page.locator('#canary-busy-'+case);button.click() page.wait_for_function("sel=>document.querySelector(sel).getAttribute('aria-busy')==='true'",arg='#canary-busy-'+case) pending={'text':button.inner_text(),'disabled':button.is_disabled(),'ariaBusy':button.get_attribute('aria-busy')} check(record,case+' pending busy label and disabled',busy_text in pending['text'] and pending['disabled'],pending) page.wait_for_function("text=>document.querySelector('#canary-outcome').textContent===text",arg=outcome) check(record,case+' local outcome distinct and action restored',not button.is_disabled() and button.get_attribute('aria-busy')=='false',page.locator('#canary-outcome').inner_text()) record['primary']=css(page,'#canary-busy-success') if scheme=='dark':check(record,'proposed supported dark on-accent ink applied',record['primary']['color']==rgb('#111827'),record['primary']) field.fill('') page.wait_for_function("document.querySelector('#canary-field').getAttribute('aria-invalid')==='true'") else: reached=tab_to(page,'#username');record['loginFocus']=css(page,'#username') check(record,'actual login keyboard focus visible',reached and record['loginFocus']['focusVisible'] and record['loginFocus']['outlineStyle']=='solid',record['loginFocus']) page.evaluate('document.fonts.ready') filename=f'{kind}-{family or "scadabridge"}-{scheme}-{width}-zoom{zoom}.png' page.screenshot(path=str(OUT/filename),full_page=True) record['screenshot']=filename except Exception as e: record['exception']=str(e) check(record,'inspection completed',False,str(e)) try:page.screenshot(path=str(OUT/f'error-{kind}-{family or scheme}-{width}-zoom{zoom}.png'),full_page=True) except Exception:pass finally: record['pageErrors']=errors check(record,'no browser page errors',not errors,errors) if zoom!=1 and page.url.startswith(ORIGIN):set_browser_zoom(worker,page,1) page.close() results.append(record) (OUT/'results.json').write_text(json.dumps({'origin':ORIGIN,'scope':'4 approved LIGHT accent families; actual CentralUI supported DARK with fixture-only proposed aliases; no other brand dark palettes','results':results},indent=2)+'\n') print(kind,family or scheme,width,zoom,'failed checks',[x['name'] for x in record['checks'] if not x['passed']],flush=True) with sync_playwright() as p: with zoom_browser(p,width=1440,height=1000) as (context,worker): for width in (1440,1024,390): for family in FAMILIES:inspect('accent',width,family=family) for scheme in ('light','dark'):inspect('root',width,scheme=scheme) for scheme in ('light','dark'): inspect('root',1440,scheme=scheme,zoom=2) inspect('login',1440,scheme=scheme) print('TOTAL CASES',len(results),'FAILED CHECKS',sum(not c['passed'] for r in results for c in r['checks']),flush=True)