Files
mxaccessgw/docs/ui-validation/native_dialog_lifecycle.py
T

38 lines
2.8 KiB
Python

"""Focused native lifecycle checks; no broad screenshot iteration."""
import asyncio,json
from pathlib import Path
from playwright.async_api import async_playwright
ROOT=Path(__file__).resolve().parent;BASE=json.load(open('/tmp/mx-ui-canary-state.json'))['origin']
async def main():
async with async_playwright() as p:
browser=await p.chromium.launch(channel='chromium',headless=True);page=await browser.new_page()
release=asyncio.Event();requested=asyncio.Event()
async def hold(route):
requested.set();await release.wait();await route.continue_()
await page.route('**/js/dashboard-dialog.js',hold)
await page.goto(BASE);await page.wait_for_selector('html[data-mx-ready="true"]')
await page.get_by_role('button',name='Create API Key',exact=True).click();await asyncio.wait_for(requested.wait(),10)
dialog=page.locator('dialog.api-key-create-modal');assert await dialog.count()==1
assert not await dialog.is_visible(), 'Requested native dialog must stay hidden until showModal'
# Close the parent while its import is pending. Completion must not resurrect it.
await page.locator('#outside').focus()
# Its visible trigger remains usable while native activation has not happened.
await page.evaluate("document.querySelector('dialog.api-key-create-modal button[aria-label=\"Close create API key\"]').click()")
await page.wait_for_function("!document.querySelector('dialog.api-key-create-modal')")
release.set();await page.wait_for_timeout(300)
assert await page.locator('dialog:modal').count()==0
await page.unroute('**/js/dashboard-dialog.js',hold)
# Reopen after disposal, then make the connected trigger unusable before cancel.
trigger=page.get_by_role('button',name='Create API Key',exact=True)
await trigger.click();await page.locator('dialog:modal').wait_for()
await trigger.evaluate('(e)=>e.disabled=true')
await page.keyboard.press('Escape');await page.wait_for_function("!document.querySelector('dialog:modal')")
await page.wait_for_function("document.activeElement.tagName==='H1'")
assert await page.locator('h1').get_attribute('tabindex')=='-1'
await page.locator('#outside').focus();assert await page.locator('h1').get_attribute('tabindex') is None
# Idempotent listener cleanup permits another instance after cancelled/disposed import.
await page.locator('#slow-trigger').click();await page.locator('dialog:modal').wait_for();await page.keyboard.press('Escape');await page.wait_for_function("!document.querySelector('dialog:modal')")
(ROOT/'evidence/mx02/lifecycle.json').write_text(json.dumps({'pendingImportHidden':True,'disposeBeforeImportCompletionNoResurrection':True,'reopenAfterDisposal':True,'connectedDisabledTriggerFallsBackToHeading':True,'headingTabindexRemovedOnBlur':True,'subsequentInstanceOpensAndCancels':True},indent=2))
await browser.close();print('Focused native lifecycle checks passed')
asyncio.run(main())