Files
ScadaBridge/infra/tools/test_overlay_focus.py
T
2026-11-13 17:42:14 -05:00

17 lines
1.8 KiB
Python

"""Focused native lifecycle regression against the actual local overlay script."""
import argparse,json
from pathlib import Path
from playwright.sync_api import sync_playwright
args=argparse.ArgumentParser();args.add_argument('--output',required=True);opts=args.parse_args()
script=Path('src/ZB.MOM.WW.ScadaBridge.CentralUI/wwwroot/js/dialog.js').read_text();results=[]
with sync_playwright() as p:
browser=p.chromium.launch(channel='chromium')
for state in ['disabled','hidden','unfocusable','disconnected']:
page=browser.new_page();page.set_content('<main><h1>Stable heading</h1><button id="trigger">Open</button><button id="next">Next</button></main><section id="dialog" tabindex="-1"><button>Close</button></section>');page.add_script_tag(content=script);
if state=='unfocusable':page.evaluate('()=>{const span=document.createElement("span");span.id="trigger";span.tabIndex=0;span.textContent="Open";document.querySelector("#trigger").replaceWith(span)}')
page.focus('#trigger');page.evaluate('sbDialog.activate("dialog")');page.evaluate('''s=>{const t=document.querySelector('#trigger');if(s==='disabled')t.disabled=true;if(s==='hidden')t.hidden=true;if(s==='unfocusable')t.removeAttribute('tabindex');if(s==='disconnected')t.remove();document.querySelector('#dialog').remove();}''',state);page.wait_for_timeout(30)
result=page.evaluate('({heading:document.activeElement===document.querySelector("h1"),locked:document.body.classList.contains("modal-open"),inert:!!document.querySelector("[inert]")})');page.focus('#next');result['cleaned']=page.get_attribute('h1','tabindex') is None;results.append({'state':state,**result});page.close()
browser.close()
Path(opts.output).write_text(json.dumps(results,indent=2)+'\n');print(results)
raise SystemExit(0 if all(r['heading'] and not r['locked'] and not r['inert'] and r['cleaned'] for r in results) else 1)