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

test(ux): exercise native Tab focus wrap and actual Cancel/Confirm clicks with synthetic no-write callbacks

davoodmehraban89 committed Oct 30, 2026 at 23:44 UTC ba53a00272c1a11c3d5142c786bf6766355096e6
1 file changed +50 -1
tests/windows-vm-ui-interaction-audit-browser.js
+50 -1
@@ -198,6 +198,26 @@
198 const stack=[...document.querySelectorAll('.modal-card[role="dialog"]')];
199 if(stack.length!==2 || stack[0].getAttribute('aria-hidden')!=='true' ||
200 !stack[1].contains(document.activeElement)) throw Error('nested dialog focus/isolation failed');
201 + // Check a real Tab/Shift+Tab wrap, which an accessibility contract
202 + // cannot prove from source alone. Neither key may escape the top dialog.
203 + const topControls=[...stack[1].querySelectorAll(
204 + 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])'
205 + )].filter(el=>el.getClientRects().length>0 && getComputedStyle(el).visibility!=='hidden');
206 + if(topControls.length<2)throw Error('nested modal focus order unexpectedly empty');
207 + const firstModalControl=topControls[0],lastModalControl=topControls[topControls.length-1];
208 + lastModalControl.focus();
209 + const tabForward=new KeyboardEvent('keydown',{key:'Tab',bubbles:true,cancelable:true});
210 + lastModalControl.dispatchEvent(tabForward);
211 + if(!tabForward.defaultPrevented || document.activeElement!==firstModalControl){
212 + throw Error('Tab escaped the top modal instead of wrapping to its first control');
213 + }
214 + firstModalControl.focus();
215 + const tabBackward=new KeyboardEvent('keydown',
216 + {key:'Tab',shiftKey:true,bubbles:true,cancelable:true});
217 + firstModalControl.dispatchEvent(tabBackward);
218 + if(!tabBackward.defaultPrevented || document.activeElement!==lastModalControl){
219 + throw Error('Shift+Tab escaped the top modal instead of wrapping to its last control');
220 + }
221 // Simulate pressing Enter on a focused CANCEL button in an actual installed
222 // WebView2 dialog. The global shortcut MUST NOT hijack it as "confirm".
223 const nestedCancel=stack[1].querySelector('[data-action="cancel"]');
@@ -229,9 +249,38 @@
249 await wait(15);
250 if(document.querySelector('.modal-backdrop') || document.activeElement!==modalTrigger ||
251 unexpectedConfirm) throw Error('Escape did not restore focus to original control');
252 + // Open a fresh synthetic confirmation: a user clicking Cancel must NOT
253 + // execute the callback. Deliberate Confirm should execute exactly once.
254 + let syntheticConfirmed=0;
255 + FINORA.Modal.confirm({title:'Q01 Cancel-button regression',
256 + message:'No real account or customer data',
257 + onConfirm:()=>{syntheticConfirmed++;}});
258 + await wait(25);
259 + const cancelDialog=FINORA.Modal.stack[FINORA.Modal.stack.length-1]?.card;
260 + const cancelClick=cancelDialog?.querySelector('[data-action="cancel"]');
261 + if(!cancelClick)throw Error('synthetic Cancel action missing');
262 + cancelClick.focus();
263 + cancelClick.click();await wait(25);
264 + if(syntheticConfirmed!==0 || FINORA.Modal.stack.length ||
265 + document.activeElement!==modalTrigger){
266 + throw Error('Cancel click triggered financial confirm or failed to restore focus');
267 + }
268 + FINORA.Modal.confirm({title:'Q01 Confirm-button regression',
269 + message:'Only increment a synthetic counter',
270 + onConfirm:()=>{syntheticConfirmed++;}});
271 + await wait(25);
272 + const confirmDialog=FINORA.Modal.stack[FINORA.Modal.stack.length-1]?.card;
273 + const confirmClick=confirmDialog?.querySelector('[data-action="confirm"]');
274 + if(!confirmClick)throw Error('synthetic Confirm action missing');
275 + confirmClick.click();await wait(25);
276 + if(syntheticConfirmed!==1 || FINORA.Modal.stack.length){
277 + throw Error('synthetic Confirm callback not exactly once or dialog not dismissed');
278 + }
279 const modalKeyboard={roleAndLabel:true,nestedDialogIsolation:true,
280 escapeClosesWithoutConfirm:true,focusReturnsToTrigger:true,
234 - enterOnFocusedCancelDoesNotSave:true,enterOnInputDoesNotSubmit:true};
281 + enterOnFocusedCancelDoesNotSave:true,enterOnInputDoesNotSubmit:true,
282 + tabAndShiftTabStayInsideTopDialog:true,
283 + cancelDoesNotConfirmAndRestoresFocus:true,syntheticConfirmRunsExactlyOnce:true};
284 // Notification flood: transient success/info messages should never
285 // cover the dashboard. Important errors remain until explicitly dismissed.
286 for(let n=0;n<9;n++) FINORA.Toast.info('Q01 synthetic notice '+n);