Files
lmxopcua/docs/ui-consistency/evidence/ot13-simple-modals/browser.py
T

49 lines
5.0 KiB
Python

"""Five real wrappers, synthetic callbacks/providers only; no operational endpoints."""
import argparse,json,sys
from pathlib import Path
from playwright.sync_api import sync_playwright,expect
sys.path.insert(0,'/Users/dohertj2/Desktop/ignitionoee/docs/ui-validation/router-canary')
from browser_zoom import zoom_browser,set_browser_zoom
parser=argparse.ArgumentParser();parser.add_argument('--final-guard',action='store_true');args=parser.parse_args()
out=Path(__file__).parent;origin='http://127.0.0.1:58846';r={'origin':origin,'scenes':[]}
with sync_playwright() as p:
for mode,width,zoom in ([('phone',390,1)] if args.final_guard else [('desktop',1440,1),('phone',390,1),('real200',1440,2)]):
for kind in (['area','line'] if args.final_guard else ['name','driver','message','area','line']):
with zoom_browser(p,width=width,height=900) as(ctx,worker):
page=ctx.new_page();errors=[];page.on('pageerror',lambda e:errors.append(str(e)));page.set_default_timeout(10000)
assert page.request.get(origin+'/fixture/provenance').json()['backend'].startswith('No DB, driver, gateway')
page.goto(origin+'/?kind='+kind);expect(page.locator('#ready')).to_have_text('ready');factor=set_browser_zoom(worker,page,zoom)
before=int(page.locator('#operations').inner_text());checks=[]
def check(n,v):checks.append({'name':n,'passed':bool(v)});assert v,n
page.locator('#open').click();modal=page.locator('[role=dialog]');expect(modal).to_be_visible();safe=modal.locator('[data-initial-focus]');expect(safe).to_be_focused()
check('Dialog has resolved accessible name',modal.evaluate("n=>!!document.getElementById(n.getAttribute('aria-labelledby'))?.textContent.trim()"))
page.locator('#outside').evaluate('n=>n.focus()');check('Outside focus denied',modal.evaluate('n=>n.contains(document.activeElement)'))
for _ in range(10):page.keyboard.press('Tab');assert modal.evaluate('n=>n.contains(document.activeElement)')
check('Ten Tab steps remain scoped',True)
for field in modal.locator('input:not([type=hidden]),select,textarea').all():
id=field.get_attribute('id');label=modal.locator('label').filter(has=page.locator('nonexistent')) if False else modal.locator('label[for="'+id+'"]')
label.click();expect(field).to_be_focused()
check('Label focus and descriptions resolve '+label.inner_text(),field.evaluate("n=>(n.getAttribute('aria-describedby')||'').split(/\\s+/).filter(Boolean).every(id=>!!document.getElementById(id))"))
modal.screenshot(path=str(out/(mode+'-'+kind+'.png')))
if kind in ['area','line']:
closed_before=int(page.locator('#closes').inner_text());safe.click();expect(modal).to_have_attribute('aria-busy','true');page.keyboard.press('Escape');check('Pending cancel cannot dismiss twice',modal.count()==1);expect(modal).to_have_count(0);check('One delayed cancel callback',int(page.locator('#closes').inner_text())==closed_before+1)
else:
page.keyboard.press('Escape');expect(modal).to_have_count(0)
expect(page.locator('#open')).to_be_focused();check('Idle cancel returns to trigger',True)
page.locator('#open').click();expect(modal).to_be_visible()
if kind=='message':
safe.click();expect(modal).to_have_count(0);check('Message Close invokes no synthetic operation',int(page.locator('#operations').inner_text())==before)
else:
submit=modal.locator('.modal-footer .btn-primary');submit.click()
if kind in ['name','driver']:
expect(modal.locator('[role=alert]')).not_to_have_text('');page.get_by_label('Name',exact=True).fill('fixture-item')
else:
expect(modal.locator('.validation-message').first).to_be_visible();page.get_by_label('UnsAreaId' if kind=='area' else 'UnsLineId',exact=True).fill('FIXTURE-ID');page.get_by_label('Name',exact=True).fill('fixture-item')
check('Invalid submit dispatched nothing',int(page.locator('#operations').inner_text())==before)
submit.click();expect(modal).to_have_attribute('aria-busy','true');check('Busy fieldset disables body controls',modal.locator('fieldset').evaluate('n=>n.disabled') and all(x.is_disabled() for x in modal.locator('input:not([type=hidden]),select,textarea').all()));page.keyboard.press('Escape')
check('Busy Escape preserves dispatched action',modal.count()==1 and modal.locator('.btn-close').is_disabled() and modal.locator('.modal-footer .btn-outline-secondary').is_disabled())
expect(modal).to_have_count(0);expect(page.locator('#open')).to_be_focused();check('Exactly one synthetic callback, then focus return',int(page.locator('#operations').inner_text())==before+1)
geometry=page.evaluate('()=>({innerWidth,scrollWidth:document.documentElement.scrollWidth,dpr:devicePixelRatio})');check('No horizontal overflow',geometry['scrollWidth']<=geometry['innerWidth']);check('No page errors',not errors)
r['scenes'].append({'mode':mode,'kind':kind,'zoom':factor,'geometry':geometry,'checks':checks,'errors':errors});(out/('browser-final-target-guard.json' if args.final_guard else 'browser-results.json')).write_text(json.dumps(r,indent=2)+'\n')
print(json.dumps({'scenes':len(r['scenes']),'checks':sum(len(s['checks'])for s in r['scenes'])}))