storebound/tests/fixtures/console/_common.js

20 lines
1.3 KiB
JavaScript

// Shared by the console fixtures (modeled pages, not recorded): records every click on a button, link, menu item or row
// (the engine must never click a save / submit / publish / create / next control) and lets a test act as the owner
// (window.__next() shows the next step, like the owner pressing Next). Navigation pages keep the log across pages in
// sessionStorage (window.__navClicks).
window.__clicks = [];
const navLog = () => { try { return JSON.parse(sessionStorage.getItem('navClicks') || '[]'); } catch { return []; } };
window.__navClicks = navLog;
document.addEventListener('click', e => {
const b = e.target.closest('button, a, [role="button"], [role="menuitem"], [role="menuitemradio"], [role="option"], [role="link"], [role="row"], tr');
if (!b) return;
const name = (b.getAttribute('aria-label') || b.textContent).trim().replace(/\s+/g, ' ');
if (b.matches('button')) window.__clicks.push(b.textContent.trim());
try { sessionStorage.setItem('navClicks', JSON.stringify([...navLog(), name])); } catch { /* file: pages */ }
}, true);
window.__step = 0;
window.__next = () => {
const steps = [...document.querySelectorAll('[data-step]')];
window.__step = Math.min(window.__step + 1, steps.length - 1);
steps.forEach((s, i) => { s.hidden = i !== window.__step; });
};