Runs in a real DOM. Each test seeds
<div id="faq">with three header buttons (aria-expanded,aria-controls) and three panels (hiddenwhen closed).
Implement togglePanel(index) with single-open semantics:
- If the panel at
indexis closed, open it and close every other panel. - If it is already open, close it (so all panels are closed).
- Out-of-range
index: no change.
Keep aria-expanded on each button and the hidden attribute on each panel in agreement. Use aria-controls to find a button's panel rather than assuming positions. Return { expanded, hidden } - each button's aria-expanded as booleans and each panel's hidden property, read back from the DOM.