Files
ScadaBridge/infra/tools/confirm_topology_focus.py
T

28 lines
3.4 KiB
Python

"""Focused technical confirmation: await native smooth scrolling and verify real touch emulation."""
import json,sys
from pathlib import Path
from playwright.sync_api import sync_playwright
sys.path.insert(0,'/Users/dohertj2/.codex/worktrees/scada-ui-consistency/scadaproj/components/ui-theme/validation/theme-1.0.0/canary')
from browser_zoom import zoom_browser,set_browser_zoom
out=[]
with sync_playwright() as p:
with zoom_browser(p) as (context,worker):
for scheme in ['light','dark']:
for w,h,z in [(768,480,1),(390,844,1),(1440,900,2)]:
page=context.new_page();page.set_viewport_size({'width':w,'height':h});page.goto('http://127.0.0.1:5201/topology-canary?role=Deployer',wait_until='networkidle');page.evaluate('s=>window.sbTheme.set(s)',scheme);set_browser_zoom(worker,page,z)
page.locator('[role=treeitem][tabindex="0"]').first.focus();page.keyboard.press('End')
page.wait_for_function("document.activeElement === [...document.querySelectorAll('[role=treeitem]')].at(-1)")
page.wait_for_function("document.activeElement.querySelector('.tv-row').getBoundingClientRect().bottom <= innerHeight + 1")
record=page.evaluate("""() => ({width:innerWidth,document:document.documentElement.scrollWidth,dpr:devicePixelRatio,scheme:document.documentElement.dataset.bsTheme,top:document.activeElement.querySelector('.tv-row').getBoundingClientRect().top,bottom:document.activeElement.querySelector('.tv-row').getBoundingClientRect().bottom,height:innerHeight,focused:document.activeElement.getAttribute('role')})""")
record.update(requested=[w,h],zoom=z,kind='keyboard');record['passed']=record['top']>=0 and record['bottom']<=record['height']+1 and record['document']<=record['width'];out.append(record);page.close()
b=p.chromium.launch(channel='chromium')
for w,h in [(390,844),(768,480)]:
context=b.new_context(viewport={'width':w,'height':h},is_mobile=True,has_touch=True);page=context.new_page();page.goto('http://127.0.0.1:5201/topology-canary?role=Deployer',wait_until='networkidle')
requested=page.evaluate('({coarse:matchMedia("(pointer:coarse)").matches,touch:navigator.maxTouchPoints})')
cdp=context.new_cdp_session(page);cdp.send('Emulation.setTouchEmulationEnabled',{'enabled':True,'maxTouchPoints':1});page.wait_for_function('matchMedia("(pointer:coarse)").matches')
record=page.evaluate("""() => ({width:innerWidth,document:document.documentElement.scrollWidth,coarse:matchMedia('(pointer:coarse)').matches,touch:navigator.maxTouchPoints,overflow:getComputedStyle(document.querySelector('.topology-tree')).overflowY,rows:[...document.querySelectorAll('.tv-row')].slice(0,8).map(e=>e.getBoundingClientRect().height),toggles:[...document.querySelectorAll('.tv-toggle')].slice(0,8).map(e=>({width:e.getBoundingClientRect().width,height:e.getBoundingClientRect().height}))})""")
record.update(requested=[w,h],initialRequestedContext=requested,kind='touch');record['passed']=record['coarse'] and record['touch']==1 and record['document']<=record['width'] and min(record['rows'])>=44 and all(x['width']>=44 and x['height']>=44 for x in record['toggles']) and record['overflow']=='visible';out.append(record)
page.screenshot(path=f'docs/ui-consistency/evidence/sb10-12/browser-final/topology-verified-touch-{w}-{h}.png');context.close()
b.close()
Path('docs/ui-consistency/evidence/sb10-12/focused-keyboard-touch-confirmation.json').write_text(json.dumps(out,indent=2));print(json.dumps({'cases':len(out),'passed':sum(r['passed'] for r in out)},indent=2))