22 lines
4.1 KiB
Python
22 lines
4.1 KiB
Python
import json,re,hashlib,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
|
|
origin=re.search(r'Now listening on: (http://127.0.0.1:\d+)',Path('/tmp/ot13-alerts-after-host.log').read_text()).group(1)
|
|
out=Path('docs/ui-consistency/evidence/ot13-alert-operations');results=[]
|
|
with sync_playwright() as p:
|
|
with zoom_browser(p) as (ctx,worker):
|
|
for width,zoom in [(1440,1),(390,1),(1440,2),(390,2)]:
|
|
pg=ctx.new_page();pg.set_viewport_size({'width':width,'height':1500});errors=[];pg.on('pageerror',lambda e:errors.append(str(e)))
|
|
pg.goto(origin+'/live-tail-pilot?sample=alerts',wait_until='networkidle');set_browser_zoom(worker,pg,zoom);pg.wait_for_timeout(300);pg.request.post(origin+'/fixture/alarm-feed/alarm-a');row=pg.locator('tbody tr').filter(has_text='alarm-a');row.locator('input').wait_for();checks={}
|
|
f=row.locator('input');f.focus();pg.evaluate('window.beforeInput=document.querySelector("tbody input")');pg.request.post(origin+'/fixture/alarm-feed/alarm-b');pg.wait_for_timeout(350)
|
|
checks['focusedConditionRetained']=pg.evaluate('document.activeElement===window.beforeInput&&window.beforeInput.closest("tr").textContent.includes("alarm-a")');checks['uniqueIds']=pg.locator('tbody input').evaluate_all('(es)=>new Set(es.map(e=>e.id)).size===es.length&&es.every(e=>document.querySelector(`label[for="${e.id}"]`)&&e.getAttribute("aria-labelledby").split(" ").every(id=>document.getElementById(id)))')
|
|
f.fill('');f.press('e');bad=f.evaluate('(e)=>({value:e.value,badInput:e.validity.badInput})');row.get_by_role('button',name='Timed shelve alarm-a',exact=True).click();pg.wait_for_timeout(150);pg.locator('#fixture-alarm-observe').click();checks['nativeIncompleteRejected']=bad['badInput'] and pg.locator('#fixture-alarm-count').inner_text()=='0'
|
|
f.fill('7');row.get_by_role('button',name='Timed shelve alarm-a',exact=True).click();pg.wait_for_timeout(150);pg.locator('#fixture-alarm-observe').click();pg.wait_for_timeout(200);checks['validTimedAccepted']=pg.locator('#fixture-alarm-count').inner_text()=='1' and bool(pg.locator('#fixture-alarm-until').inner_text())
|
|
pg.locator('#fixture-alarm-pending').click();row.get_by_role('button',name='Acknowledge alarm-a',exact=True).click();pg.wait_for_timeout(150);checks['allActionsBusy']=pg.locator('tbody button:not([disabled]),tbody input:not([disabled])').count()==0 and 'Request pending' in pg.locator('[role=status]').all_inner_texts()[-1];pg.locator('#fixture-alarm-observe').click();pg.wait_for_timeout(200);checks['pendingOneRequest']=pg.locator('#fixture-alarm-count').inner_text()=='2';pg.locator('#fixture-alarm-complete').click();row.get_by_role('button',name='Acknowledge alarm-a',exact=True).wait_for(state='visible');pg.wait_for_timeout(100)
|
|
pg.locator('#fixture-alarm-failure').click();row.get_by_role('button',name='Acknowledge alarm-a',exact=True).click();details=pg.locator('details').filter(has=pg.locator(':scope > summary',has_text='Request details')).last;details.locator('summary').click();checks['fullEscapedException']='END-DIAGNOSTIC' in details.inner_text() and '<script>ignored()</script>' in details.inner_text() and details.locator('script').count()==0
|
|
checks['shortOutcome']='END-DIAGNOSTIC' not in ' '.join(pg.locator('[role=status]').all_inner_texts());checks['noPageOverflow']=pg.evaluate('document.documentElement.scrollWidth<=innerWidth');checks['noErrors']=not errors
|
|
pg.screenshot(path=str(out/f'after-{width}-zoom{zoom}.png'),full_page=False);results.append({'width':width,'zoom':zoom,'actualViewport':pg.evaluate('({width:innerWidth,dpr:devicePixelRatio,scroll:document.documentElement.scrollWidth})'),'badInput':bad,'observedFakeCount':pg.locator('#fixture-alarm-count').inner_text(),'observedUntil':pg.locator('#fixture-alarm-until').inner_text(),'checks':checks,'errors':errors});pg.close()
|
|
(out/'after-native.json').write_text(json.dumps(results,indent=2));print(json.dumps(results));assert all(all(x['checks'].values()) for x in results)
|