87 lines
9.4 KiB
Python
87 lines
9.4 KiB
Python
"""Bounded source-linked UNS wrapper proof. Only fixture fake actions may be dispatched."""
|
|
import hashlib,json,re,sys
|
|
from pathlib import Path
|
|
from urllib.parse import urlsplit
|
|
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
|
|
out=Path(__file__).parent;origin=sys.argv[1];results={'origin':origin,'scenes':[]}
|
|
with sync_playwright() as p:
|
|
for mode,width,zoom in [('desktop',1440,1),('phone',390,1),('real200',1440,2)]:
|
|
for kind in ['reference','import','alarm','virtual']:
|
|
with zoom_browser(p,width=width,height=900) as(ctx,worker):
|
|
page=ctx.new_page();page.set_default_timeout(12000);errors=[];external=[];checks=[]
|
|
page.on('pageerror',lambda e:errors.append(str(e)))
|
|
def route(req):
|
|
if urlsplit(req.request.url).hostname not in ['127.0.0.1','localhost']:external.append(urlsplit(req.request.url).hostname);req.abort()
|
|
else:req.continue_()
|
|
page.route('**/*',route);page.goto(origin+'/?kind='+kind);expect(page.locator('#ready')).to_have_text('ready');factor=set_browser_zoom(worker,page,zoom)
|
|
session=page.locator('#session').inner_text()
|
|
def state():return page.request.get(origin+'/fixture/state/'+session).json()
|
|
def check(name,value):checks.append({'name':name,'passed':bool(value)});assert value,name
|
|
def release(outcome='success'):assert page.request.post(origin+'/fixture/release/'+session+'/'+outcome).ok
|
|
def replace():assert page.request.post(origin+'/fixture/target/'+session+'/B').ok
|
|
def prepare():
|
|
if kind=='reference':modal.get_by_role('checkbox').check()
|
|
elif kind=='import':modal.get_by_label('Equipment CSV',exact=True).fill('Name,MachineCode,UnsLineId\nfixture,fixture-1,line-1')
|
|
else:modal.get_by_label('Name',exact=True).fill('fixture-updated');modal.get_by_label('Name',exact=True).press('Tab')
|
|
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('Named dialog with visible safe focus',modal.evaluate("n=>!!document.getElementById(n.getAttribute('aria-labelledby'))?.textContent.trim()") and safe.evaluate('n=>{const r=n.getBoundingClientRect();return r.top>=0&&r.bottom<=innerHeight}'))
|
|
page.locator('#outside').evaluate('n=>n.focus()');check('Outside focus denied',modal.evaluate('n=>n.contains(document.activeElement)'))
|
|
for _ in range(12):page.keyboard.press('Tab');assert modal.evaluate('n=>n.contains(document.activeElement)')
|
|
check('Twelve actual Tab steps stay scoped',True)
|
|
for field in modal.locator('input:not([type=hidden]),select,textarea').all():
|
|
if not field.is_visible() or field.is_disabled():continue
|
|
id=field.get_attribute('id');label=modal.locator('label[for="'+str(id)+'"]')
|
|
if id and label.count()==1:
|
|
check('Visible field labelled '+id,True)
|
|
if field.get_attribute('type')!='checkbox':label.click();expect(field).to_be_focused()
|
|
else:check('Real RawTree checkbox has accessible name',kind=='reference' and 'Synthetic raw tag A' in field.aria_snapshot())
|
|
check('Field descriptions resolve '+str(id),field.evaluate("n=>(n.getAttribute('aria-describedby')||'').split(/\\s+/).filter(Boolean).every(id=>!!document.getElementById(id))"))
|
|
geometry=modal.locator('.modal-content').evaluate('n=>{const r=n.getBoundingClientRect();return {left:r.left,right:r.right,innerWidth,scrollWidth:document.documentElement.scrollWidth,dpr:devicePixelRatio}}')
|
|
check('Header and footer remain in viewport',modal.locator('.modal-header').evaluate('n=>{const r=n.getBoundingClientRect();return r.top>=0&&r.bottom<=innerHeight}') and modal.locator('.modal-footer').evaluate('n=>{const r=n.getBoundingClientRect();return r.top>=0&&r.bottom<=innerHeight}'))
|
|
check('Page and modal fit horizontal viewport',geometry['left']>=0 and geometry['right']<=geometry['innerWidth']+1 and geometry['scrollWidth']<=geometry['innerWidth'])
|
|
modal.screenshot(path=str(out/(mode+'-'+kind+'.png')))
|
|
page.keyboard.press('Escape');expect(modal).to_have_count(0);expect(page.locator('#open')).to_be_focused();check('Idle Escape restores trigger',True)
|
|
page.locator('#open').click();expect(modal).to_be_visible();prepare();modal.locator('.modal-footer .btn-primary').click();expect(modal).to_have_attribute('aria-busy','true')
|
|
page.wait_for_function("document.querySelector('[role=dialog]')?.contains(document.activeElement)")
|
|
check('Pending focus stays inside dialog',modal.evaluate('n=>n.contains(document.activeElement)'))
|
|
page.keyboard.press('Escape');check('Pending fields and close actions disabled',modal.locator('fieldset').first.evaluate('n=>n.disabled') and modal.locator('.btn-close').is_disabled() and safe.is_disabled() and modal.count()==1)
|
|
check('Exactly one synthetic action',len(state()['operations'])==1)
|
|
release()
|
|
if kind=='import':
|
|
expect(modal.locator('[role=alert]').filter(has_text='Inserted:')).to_be_visible();check('Import summary waits for explicit close',state()['saved']==[])
|
|
modal.get_by_label('Equipment CSV',exact=True).fill('wrong,header');modal.locator('.modal-footer .btn-primary').click();expect(modal.get_by_label('Equipment CSV',exact=True)).to_be_focused()
|
|
check('Malformed retry retains Close after landed import',safe.inner_text().strip()=='Close' and len(state()['operations'])==1)
|
|
safe.click()
|
|
expect(modal).to_have_count(0);expect(page.locator('#open')).to_be_focused();check('Successful parent callback and focus restoration',state()['saved']==['A'])
|
|
page.locator('#open').click();expect(modal).to_be_visible();prepare();modal.locator('.modal-footer .btn-primary').click();expect(modal).to_have_attribute('aria-busy','true');before=state();replace()
|
|
if kind in ['alarm','virtual']:expect(modal.get_by_label('Name',exact=True)).to_have_value('B')
|
|
elif kind=='reference':expect(modal.get_by_role('checkbox',name='Synthetic raw tag B',exact=True)).to_be_visible()
|
|
else:expect(modal.get_by_label('Equipment CSV',exact=True)).to_have_value('')
|
|
page.wait_for_function("document.querySelector('[role=dialog]')?.contains(document.activeElement)")
|
|
check('Pending replacement focus stays inside dialog',modal.evaluate('n=>n.contains(document.activeElement)'))
|
|
release('failure');expect(modal).to_have_attribute('aria-busy','false');current=state()
|
|
check('Retired action cannot invoke replacement callbacks',current['saved']==before['saved'] and current['closed']==before['closed'] and len(current['operations'])==2)
|
|
check('Retired failure not installed','Synthetic current failure' not in modal.inner_text() and 'Synthetic import failure' not in modal.inner_text())
|
|
if kind=='reference':check('Replacement tree owns clean selection',not modal.get_by_role('checkbox').is_checked() and modal.locator('.modal-footer .btn-primary').is_disabled())
|
|
editorproof=None
|
|
if kind=='virtual':
|
|
modal.get_by_role('button',name='Edit source',exact=True).click();expect(modal.locator('.monaco-editor')).to_be_visible()
|
|
page.wait_for_function('window.monaco&&monaco.editor.getEditors().length===1')
|
|
page.evaluate("monaco.editor.getModels()[0].setValue('// unsynced synthetic draft\\nreturn 9.0;')")
|
|
uri=page.evaluate('monaco.editor.getModels()[0].uri.toString()');modal.get_by_role('button',name='Save script',exact=True).click();expect(modal).to_have_attribute('aria-busy','true')
|
|
page.wait_for_function('monaco.editor.getEditors()[0].getOption(monaco.editor.EditorOption.readOnly)===true')
|
|
check('Script save captures authoritative text and independent boundary',state()['operations'][-1]['method']=='UpdateScriptSourceAsync' and state()['operations'][-1]['args'][0]=='S1' and state()['operations'][-1]['args'][1]=='// unsynced synthetic draft\nreturn 9.0;' and state()['saved']==['A'])
|
|
release('failure');expect(modal).to_have_attribute('aria-busy','false');page.wait_for_function('monaco.editor.getEditors()[0].getOption(monaco.editor.EditorOption.readOnly)===false')
|
|
check('Failure retains same editor identity and draft',page.evaluate('monaco.editor.getModels()[0].uri.toString()')==uri and page.evaluate('monaco.editor.getModels()[0].getValue()')=='// unsynced synthetic draft\nreturn 9.0;')
|
|
modal.get_by_label('Script',exact=True).select_option('S2');page.wait_for_function("monaco.editor.getModels().length===1&&monaco.editor.getModels()[0].getValue().includes('synthetic S2')")
|
|
check('Script selection retires old model without orphan',page.evaluate('monaco.editor.getModels()[0].uri.toString()')!=uri and page.evaluate('monaco.editor.getEditors().length')==1)
|
|
editorproof={'uriBefore':uri,'uriAfter':page.evaluate('monaco.editor.getModels()[0].uri.toString()')}
|
|
safe.click();expect(modal).to_have_count(0);expect(page.locator('#open')).to_be_focused()
|
|
if kind=='virtual':page.wait_for_function('monaco.editor.getModels().length===0&&monaco.editor.getEditors().length===0')
|
|
check('No forbidden calls, external hosts or page errors',state()['forbidden']==0 and external==[] and errors==[])
|
|
results['scenes'].append({'kind':kind,'mode':mode,'zoom':factor,'geometry':geometry,'checks':checks,'errors':errors,'externalHosts':external,'state':state(),'editor':editorproof})
|
|
(out/'browser-results.json').write_text(json.dumps(results,indent=2)+'\n')
|
|
print(json.dumps({'scenes':len(results['scenes']),'checks':sum(len(s['checks']) for s in results['scenes'])}))
|