فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(q01): exercise safe native navigation, filters, editors and cancel-only destructive prompts
davoodmehraban89 committed
Oct 31, 2026 at 07:59 UTC
91a0e3d01599e00c503e05445dbfdbd698d04060
1 file changed
+75
-5
tests/windows-vm-ui-interaction-audit-browser.js
+75
-5
@@ -32,7 +32,14 @@
32
].join('|');
33
const dangerous = /(?:^|[.\s])(?:_?(?:save|delete|wipe|restore|post|submit|confirm|activate|seed|commit|final|approve|logout|export|import|download|print|settle|apply|reset|changeStatus|remove)\w*)\s*\(/i;
34
const safeTab = /\.(?:_switchTab|switchTab|_switchPeriod|_setPreset)\s*\(/;
35
- const safeOpen = /\.(?:openNewInvoice|openProductModal|openUnitModal|openCategoryModal|openContactModal|openExpenseModal|openChequeModal|openAccountModal|openReceiptModal|openPaymentModal|openTransferModal|openCompanyModal|openCompanySwitcher|openExportSectionModal|openSignedLicenseModal|openAuditTrail|openWipeModal|openRestoreModal|openPeriodModal|openJournalModal|openWarehouse|openStocktakeCreate|openTransfer|openReversal|_openQuickProduct|_openQuickContact|openLedger|openKardex|openStocktake|showJournal)\s*\(/;
35
+ const safeNavigate = /FINORA\.Router\.go\s*\(/;
36
+ const safeFilter = /\.(?:_togglePreInvoice|_setStockFilter|_clearFilters|_applyCustom|refresh|setTheme)\s*\(/;
37
+ // These handlers only open an editor/preview/diagnostic dialog. The audit
38
+ // closes it without saving; a separate fixture-backed test owns commits.
39
+ const safeOpen = /\.(?:openNewInvoice|openProductModal|openUnitModal|openCategoryModal|openContactModal|openExpenseModal|openChequeModal|openAccountModal|openReceiptModal|openPaymentModal|openTransferModal|openCompanyModal|openCompanySwitcher|openExportSectionModal|openSignedLicenseModal|openAuditTrail|openWipeModal|openRestoreModal|openPeriodModal|openJournalModal|openWarehouse|openStocktakeCreate|openTransfer|openReversal|_openQuickProduct|_openQuickContact|openLedger|openKardex|openStocktake|showJournal|editInvoice|editProduct|editContact|editCheque|editAccount|changeStatus|openAdjustModal|_printInvoice|printInvoice|createCompany|checkHolooMigrationReadiness|runFinancialDiagnostics)\s*\(/;
40
+ // A delete/close-period/seed action is safe to probe only up to its
41
+ // confirmation prompt. The audit must cancel and prove zero database writes.
42
+ const safeConfirm = /\.(?:deleteInvoice|deleteProduct|deleteContact|deleteCheque|deleteTransaction|deleteExpense|deleteAccount|closePeriod|seedChart)\s*\(/;
43
const clickables = (root) => [...root.querySelectorAll(
44
'button, a, [role="button"], input[type="button"], input[type="submit"], [onclick]'
45
)].filter(isVisible);
@@ -132,7 +139,7 @@
139
handler:handler(el).slice(0,170),changed,afterModal});
140
if (row) {row.status='clicked';row.reason=changed?'visible-state-changed':'no-observable-DOM-change';}
141
if (!changed) {
135
- const expectedNoop = /\._clearFilters\(\)|\.switchTab\('journals'\)/.test(handler(el));
142
+ const expectedNoop = /\._clearFilters\(\)|\._applyCustom\(\)|\.refresh\(\)|\.switchTab\('journals'\)/.test(handler(el));
143
if (expectedNoop) {
144
if (row) row.reason='idempotent-click-on-already-selected-or-clear-filter-state';
145
} else {
@@ -143,7 +150,7 @@
150
} catch(error) {
151
failures.push({route,section,kind:'click-error',label:name(el),error:String(error.message).slice(0,170)});
152
if (row) {row.status='failed';row.reason='UI click error';}
146
- } finally { if (category !== 'open') dismiss(); }
153
+ } finally { if (category !== 'open' && category !== 'confirm-request') dismiss(); }
154
}
155
// Explicit shell regression: semantic links, keyboard focus, active route,
156
// persistent sidebar collapse and reversible theme toggle.
@@ -588,14 +595,77 @@
595
row.status='broken-handler';row.reason='target function missing';
596
failures.push({route,section:ctx.section,kind:'missing-function',callee:parsed.callee});
597
} else if (el.disabled) {row.status='disabled';row.reason='disabled state';}
591
- else if (dangerous.test(code)) {
598
+ else if (!safeConfirm.test(code) && !safeNavigate.test(code) && !safeFilter.test(code) && !safeOpen.test(code) && dangerous.test(code)) {
599
row.status='not-clicked';row.reason='financial or destructive action needs explicit fixture-backed test';
600
} else if (!code) {
601
row.status='not-clicked';row.reason='dynamic event listener or no inline action; requires focused audit';
595
- } else if (!safeTab.test(code) && !safeOpen.test(code)) {
602
+ } else if (!safeTab.test(code) && !safeNavigate.test(code) && !safeFilter.test(code) && !safeOpen.test(code) && !safeConfirm.test(code)) {
603
row.status='not-clicked';row.reason='not on audited safe-action allowlist';
604
}
605
}
606
+ // Exercise read-only navigation, filters and reversible view settings.
607
+ const safeActions=[...new Set(controls
608
+ .filter(el=>!el.disabled && (safeNavigate.test(handler(el)) || safeFilter.test(handler(el))))
609
+ .map(el=>handler(el)))];
610
+ for (const action of safeActions) {
611
+ await go(route);
612
+ if (ctx.tabAction) {
613
+ const tab=clickables(target()).find(el=>handler(el)===ctx.tabAction);
614
+ if(tab){tab.click();await wait(160);}
615
+ }
616
+ const el=clickables(target()).find(x=>handler(x)===action);
617
+ if(!el){failures.push({route,section:ctx.section,kind:'safe-action-vanished',handler:action});continue;}
618
+ inventory(route,ctx.section);
619
+ await press(el,route,ctx.section,safeNavigate.test(action)?'navigation':'filter');
620
+ }
621
+ // Open destructive confirmation prompts, but NEVER approve them here.
622
+ // Compare every persistent store before/after Cancel to prove no write.
623
+ const confirmStores=['users','companies','contacts','products','units','categories',
624
+ 'treasury','invoices','invoice_items','stock_movements','transactions','cheques',
625
+ 'expenses','settings','logs','account_chart','fiscal_periods','journal_entries',
626
+ 'journal_lines','warehouses','inventory_balances','stocktakes','stocktake_lines',
627
+ 'settlements','account_mappings','audit_events','document_corrections'];
628
+ const confirmSnapshot=async()=>JSON.stringify(await Promise.all(confirmStores.map(async store=>
629
+ [store,await FINORA.Storage.getAll(store)])));
630
+ const confirmActions=[...new Set(controls
631
+ .filter(el=>!el.disabled && safeConfirm.test(handler(el)))
632
+ .map(el=>handler(el)))].slice(0,30);
633
+ for(const action of confirmActions){
634
+ await go(route);
635
+ if(ctx.tabAction){
636
+ const tab=clickables(target()).find(el=>handler(el)===ctx.tabAction);
637
+ if(tab){tab.click();await wait(160);}
638
+ }
639
+ const el=clickables(target()).find(x=>handler(x)===action);
640
+ if(!el){failures.push({route,section:ctx.section,kind:'confirm-action-vanished',handler:action});continue;}
641
+ const before=await confirmSnapshot();
642
+ inventory(route,ctx.section);
643
+ await press(el,route,ctx.section,'confirm-request');
644
+ const overlay=document.querySelector('.modal-backdrop');
645
+ if(!overlay){
646
+ failures.push({route,section:ctx.section,kind:'confirmation-prompt-missing',handler:action});
647
+ continue;
648
+ }
649
+ const cancel=clickables(overlay).find(x=>
650
+ /FINORA\.Modal\.close|Modal\.closeAll/.test(handler(x)) ||
651
+ /^(انصراف|بستن|بازگشت|✕|×)$/.test(name(x)));
652
+ if(!cancel){
653
+ failures.push({route,section:ctx.section,kind:'confirmation-cancel-missing',handler:action});
654
+ dismiss();continue;
655
+ }
656
+ cancel.click();await wait(80);
657
+ clicks.push({route,section:ctx.section+'/confirm',category:'confirm-cancel',
658
+ label:name(el),handler:action.slice(0,170),
659
+ changed:!document.querySelector('.modal-backdrop')});
660
+ if(document.querySelector('.modal-backdrop')){
661
+ failures.push({route,section:ctx.section,kind:'confirmation-cancel-did-not-close',handler:action});
662
+ dismiss();
663
+ }
664
+ const after=await confirmSnapshot();
665
+ if(before!==after){
666
+ failures.push({route,section:ctx.section,kind:'cancel-mutated-persistent-data',handler:action});
667
+ }
668
+ }
669
// Open every safe modal/editor visible in this context without saving.
670
const openActions=[...new Set(controls
671
.filter(el=>!el.disabled && safeOpen.test(handler(el)))