فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(ui): inspect actual nested modal controls and exercise dialog ARIA, Escape and focus restoration

davoodmehraban89 committed Oct 30, 2026 at 23:26 UTC 6552615dc6957ee7bee306097c5aee0fd696bf46
1 file changed +46 -2
tests/windows-vm-ui-interaction-audit-browser.js
+46 -2
@@ -108,7 +108,7 @@
108 } catch(error) {
109 failures.push({route,section,kind:'click-error',label:name(el),error:String(error.message).slice(0,170)});
110 if (row) {row.status='failed';row.reason='UI click error';}
111 - } finally {dismiss();}
111 + } finally { if (category !== 'open') dismiss(); }
112 }
113 // Explicit shell regression: semantic links, keyboard focus, active route,
114 // persistent sidebar collapse and reversible theme toggle.
@@ -145,9 +145,37 @@
145 themeButton.click();await wait(50);
146 if(document.documentElement.getAttribute('data-theme')!==originalTheme ||
147 localStorage.getItem('finora_pro_theme')!==originalTheme)throw Error('theme setting not reversible/persisted');
148 + // Cross-app dialog behavior: nested modal focus, Escape and focus return.
149 + const modalTrigger=hamburger;
150 + modalTrigger.focus();
151 + let unexpectedConfirm=false;
152 + FINORA.Modal.open({title:'Q01 Synthetic outer dialog',
153 + body:'<input id="q01ModalField" value="synthetic" />',
154 + footer:'<button class="btn" onclick="FINORA.Modal.close()">بستن</button>'});
155 + await wait(30);
156 + const outer=document.querySelector('.modal-card[role="dialog"][aria-modal="true"]');
157 + if(!outer || !outer.querySelector('[id^="finora-dialog-title-"]') ||
158 + !outer.contains(document.activeElement)) throw Error('outer dialog ARIA or focus absent');
159 + FINORA.Modal.confirm({title:'Q01 Synthetic nested confirmation',
160 + message:'Synthetic data only; no operation permitted',
161 + onConfirm:()=>{unexpectedConfirm=true;}});
162 + await wait(30);
163 + const stack=[...document.querySelectorAll('.modal-card[role="dialog"]')];
164 + if(stack.length!==2 || stack[0].getAttribute('aria-hidden')!=='true' ||
165 + !stack[1].contains(document.activeElement)) throw Error('nested dialog focus/isolation failed');
166 + document.dispatchEvent(new KeyboardEvent('keydown',{key:'Escape',bubbles:true,cancelable:true}));
167 + await wait(15);
168 + if(document.querySelectorAll('.modal-card').length!==1 ||
169 + !outer.contains(document.activeElement) || unexpectedConfirm) throw Error('Escape did not dismiss nested confirm safely');
170 + document.dispatchEvent(new KeyboardEvent('keydown',{key:'Escape',bubbles:true,cancelable:true}));
171 + await wait(15);
172 + if(document.querySelector('.modal-backdrop') || document.activeElement!==modalTrigger ||
173 + unexpectedConfirm) throw Error('Escape did not restore focus to original control');
174 + const modalKeyboard={roleAndLabel:true,nestedDialogIsolation:true,
175 + escapeClosesWithoutConfirm:true,focusReturnsToTrigger:true};
176 const shellResults={keyboardReachableSidebarLinks:navLinks.length,
177 sidebarCollapseClickAndPersistence:true,themeToggleClickAndPersistence:true,
150 - activeRouteAriaCurrent:true};
178 + activeRouteAriaCurrent:true,modalKeyboard};
179 for (const route of routes) {
180 await go(route);
181 const active=[...document.querySelectorAll('#sidebarMenu [aria-current="page"]')];
@@ -208,6 +236,13 @@
236 await press(el,route,ctx.section,'open');
237 const overlay=document.querySelector('.modal-backdrop');
238 if(overlay) {
239 + const dialog=overlay.querySelector('.modal-card[role="dialog"][aria-modal="true"]');
240 + if(!dialog || !dialog.getAttribute('aria-labelledby') ||
241 + !document.getElementById(dialog.getAttribute('aria-labelledby')) ||
242 + !dialog.contains(document.activeElement)){
243 + failures.push({route,section:ctx.section,kind:'modal-a11y-missing',
244 + handler:action.slice(0,170)});
245 + }
246 const nested=clickables(overlay);
247 const modalControls=nested.map(x=>({
248 route,section:ctx.section+'/modal',tag:x.tagName.toLowerCase(),
@@ -230,6 +265,15 @@
265 const key=[route,ctx.section+'/modal',cancel.tagName.toLowerCase(),
266 name(cancel),handler(cancel).slice(0,180)].join('|');
267 const row=all.get(key);if(row)row.status='clicked';
268 + } else {
269 + // A modal without a cancel button must still be Esc-dismissable.
270 + document.dispatchEvent(new KeyboardEvent('keydown',
271 + {key:'Escape',bubbles:true,cancelable:true}));
272 + await wait(30);
273 + }
274 + if(document.querySelector('.modal-backdrop')){
275 + failures.push({route,section:ctx.section,kind:'modal-cannot-close',
276 + handler:action.slice(0,170)});
277 }
278 }
279 dismiss();