async page => { const context = await page.context().browser().newContext(); const results = []; try { for (const origin of ['http://127.0.0.1:53202', 'http://127.0.0.1:53233']) { const p = await context.newPage(); await p.goto(origin + '/admin/secrets'); await p.locator('[data-fixture-ready=true]').waitFor(); const facts = { origin, cases: [] }; for (const scenario of ['hidden-trigger', 'hidden-ancestor', 'disabled-trigger', 'nonfocusable-trigger', 'disabled-adjacent', 'hidden-tab-controls']) { await p.evaluate(async scenario => { const mod = await import('/_content/ZB.MOM.WW.Secrets.Ui/js/secrets-dialog.js'); const id = 'focus-probe-' + scenario; const root = document.createElement('div'); root.id = id; const triggerTag = scenario === 'nonfocusable-trigger' ? 'div tabindex="0"' : 'button type="button"'; root.innerHTML = `
<${triggerTag} id="${id}-trigger">Synthetic trigger
`; document.body.append(root); const trigger = document.getElementById(id + '-trigger'); trigger.focus(); mod.open(root.querySelector('dialog'), id + '-cancel', { invokeMethodAsync: async () => mod.close(id) }, id + '-fallback', id); if (scenario === 'hidden-trigger') trigger.hidden = true; if (scenario === 'hidden-ancestor') trigger.parentElement.style.visibility = 'hidden'; if (scenario === 'disabled-trigger') trigger.disabled = true; if (scenario === 'nonfocusable-trigger') trigger.removeAttribute('tabindex'); if (scenario === 'disabled-adjacent') { trigger.remove(); document.getElementById(id + '-fallback').disabled = true; } if (scenario !== 'hidden-tab-controls') mod.close(id); }, scenario); if (scenario === 'hidden-tab-controls') { await p.keyboard.press('Tab'); const forward = await p.evaluate(() => document.activeElement?.id === 'focus-probe-hidden-tab-controls-confirm'); await p.keyboard.press('Shift+Tab'); const reverse = await p.evaluate(() => document.activeElement?.id === 'focus-probe-hidden-tab-controls-cancel'); facts.cases.push({ scenario, pass: forward && reverse }); await p.keyboard.press('Escape'); } else { if (scenario === 'disabled-adjacent') await p.evaluate(() => document.getElementById('focus-probe-disabled-adjacent-fallback').disabled = false); let pass = true; try { await p.waitForFunction(scenario => document.activeElement?.id === 'focus-probe-' + scenario + '-fallback', scenario, { timeout: 2000 }); } catch { pass = false; } facts.cases.push({ scenario, pass }); } await p.evaluate(scenario => document.getElementById('focus-probe-' + scenario).remove(), scenario); } results.push(facts); await p.close(); } } finally { await context.close(); } return results; }