فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(q01): exercise safe nested dialogs and reversible invoice draft actions
davoodmehraban89 committed
Oct 31, 2026 at 11:36 UTC
c1e9834ebca679b561559ef71989cd535940996e
1 file changed
+115
-1
tests/windows-vm-ui-interaction-audit-browser.js
+115
-1
@@ -37,7 +37,7 @@
37
const safeFilter = /\.(?:_togglePreInvoice|_setStockFilter|_clearFilters|_applyCustom|_switchPeriod|_setPreset|refresh|setTheme)\s*\(/;
38
// These handlers only open an editor/preview/diagnostic dialog. The audit
39
// closes it without saving; a separate fixture-backed test owns commits.
40
- 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|openAdjustModal|printInvoice|checkHolooMigrationReadiness|runFinancialDiagnostics)\s*\(/;
40
+ 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|openAdjustModal|_printInvoice|printInvoice|_preview|checkHolooMigrationReadiness|runFinancialDiagnostics)\s*\(/;
41
// A delete/close-period/seed action is safe to probe only up to its
42
// confirmation prompt. The audit must cancel and prove zero database writes.
43
const safeConfirmAction = /\.(?:deleteInvoice|deleteProduct|deleteContact|deleteCheque|deleteTransaction|deleteExpense|deleteAccount|closePeriod|seedChart)\s*\(/;
@@ -71,6 +71,15 @@
71
});
72
}
73
}
74
+ function registerControl(el, route, section) {
75
+ const key=sig(el,route,section);
76
+ if(!all.has(key)) all.set(key,{
77
+ route,section,tag:el.tagName.toLowerCase(),label:name(el),
78
+ handler:handler(el).slice(0,220),disabled:!!el.disabled,
79
+ hasAccessibleName:!!name(el),status:'not-clicked',reason:''
80
+ });
81
+ return all.get(key);
82
+ }
83
function inventory(route, section) {
84
const controls = clickables(target());
85
auditFields(target(),route,section);
@@ -130,6 +139,8 @@
139
const row=all.get(k);
140
const before=target().innerHTML;
141
const beforeModal=!!document.querySelector('.modal-backdrop');
142
+ const beforeModalDepth=FINORA.Modal.stack.length;
143
+ const beforeModalMarkup=FINORA.Modal.stack.at(-1)?.card.innerHTML||'';
144
const beforeRoute=FINORA.Router.current();
145
const beforeTheme=document.documentElement.getAttribute('data-theme');
146
const beforeToasts=[...document.querySelectorAll('.toast')].map(x=>x.textContent.trim()).join('|');
@@ -138,10 +149,13 @@
149
if (!noError()) throw Error('error toast or page render error');
150
const after=target()?.innerHTML||'';
151
const afterModal=!!document.querySelector('.modal-backdrop');
152
+ const afterModalDepth=FINORA.Modal.stack.length;
153
+ const afterModalMarkup=FINORA.Modal.stack.at(-1)?.card.innerHTML||'';
154
const afterRoute=FINORA.Router.current();
155
const afterTheme=document.documentElement.getAttribute('data-theme');
156
const afterToasts=[...document.querySelectorAll('.toast')].map(x=>x.textContent.trim()).join('|');
157
const changed = before !== after || beforeModal !== afterModal ||
158
+ beforeModalDepth !== afterModalDepth || beforeModalMarkup !== afterModalMarkup ||
159
beforeRoute !== afterRoute || beforeTheme !== afterTheme || beforeToasts !== afterToasts;
160
clicks.push({route,section,category,label:name(el),
161
handler:handler(el).slice(0,170),changed,afterModal});
@@ -718,6 +732,106 @@
732
const key=[x.route,x.section,x.tag,x.label,x.handler].join('|');
733
if(!all.has(key))all.set(key,x);
734
});
735
+
736
+ // Exercise safe nested dialogs inside the parent editor, then close
737
+ // only the child. This verifies quick-contact/product and invoice
738
+ // preview openers without ever invoking Save or physical Print.
739
+ const nestedOpenActions=nested.filter(x=>!x.disabled &&
740
+ safeOpen.test(handler(x)) &&
741
+ /_openQuickContact|_openQuickProduct|InvoicePrint\._preview/.test(handler(x)));
742
+ for(const nestedAction of nestedOpenActions){
743
+ const parentDepth=FINORA.Modal.stack.length;
744
+ const parentCard=FINORA.Modal.stack.at(-1)?.card;
745
+ registerControl(nestedAction,route,ctx.section+'/modal');
746
+ await press(nestedAction,route,ctx.section+'/modal','open');
747
+ await wait(60);
748
+ if(FINORA.Modal.stack.length!==parentDepth+1){
749
+ failures.push({route,section:ctx.section,kind:'nested-safe-action-did-not-open-dialog',
750
+ handler:handler(nestedAction)});
751
+ continue;
752
+ }
753
+ const child=FINORA.Modal.stack.at(-1);
754
+ const childDialog=child?.card;
755
+ if(!childDialog || childDialog.getAttribute('role')!=='dialog' ||
756
+ childDialog.getAttribute('aria-modal')!=='true' ||
757
+ !childDialog.contains(document.activeElement)){
758
+ failures.push({route,section:ctx.section,kind:'nested-modal-a11y-missing',
759
+ handler:handler(nestedAction)});
760
+ }
761
+ auditFields(childDialog,route,ctx.section+'/nested-modal');
762
+ const childCancel=clickables(childDialog).find(x=>
763
+ /FINORA\.Modal\.close|Modal\.closeAll/.test(handler(x)) ||
764
+ /^(انصراف|بستن|بازگشت|✕|×)$/.test(name(x)));
765
+ if(childCancel){
766
+ registerControl(childCancel,route,ctx.section+'/nested-modal');
767
+ await press(childCancel,route,ctx.section+'/nested-modal','open');
768
+ } else {
769
+ childDialog?.querySelector('.modal-close')?.click();
770
+ await wait(60);
771
+ }
772
+ if(FINORA.Modal.stack.length!==parentDepth ||
773
+ FINORA.Modal.stack.at(-1)?.card!==parentCard){
774
+ failures.push({route,section:ctx.section,kind:'nested-modal-cancel-did-not-restore-parent',
775
+ handler:handler(nestedAction)});
776
+ dismiss();
777
+ }
778
+ }
779
+
780
+ // Exercise invoice draft row operations without persisting them.
781
+ const itemsBody=overlay.querySelector('#itemsBody');
782
+ const addRow=nested.find(x=>/InvoiceFormView\._addRow\s*\(/.test(handler(x)));
783
+ if(itemsBody && addRow){
784
+ const initialRows=itemsBody.querySelectorAll('tr').length;
785
+ registerControl(addRow,route,ctx.section+'/modal');
786
+ await press(addRow,route,ctx.section+'/modal','open');
787
+ const afterAdd=itemsBody.querySelectorAll('tr').length;
788
+ if(afterAdd!==initialRows+1){
789
+ failures.push({route,section:ctx.section,kind:'invoice-draft-add-row-failed',
790
+ initialRows,afterAdd});
791
+ } else {
792
+ const lastRow=itemsBody.querySelector('tr:last-child');
793
+ const removeLast=clickables(lastRow).find(x=>
794
+ /InvoiceFormView\._removeRow\s*\(\d+\)/.test(handler(x)));
795
+ if(!removeLast){
796
+ failures.push({route,section:ctx.section,kind:'invoice-draft-remove-new-row-missing'});
797
+ } else {
798
+ registerControl(removeLast,route,ctx.section+'/modal');
799
+ await press(removeLast,route,ctx.section+'/modal','open');
800
+ const afterRestore=itemsBody.querySelectorAll('tr').length;
801
+ if(afterRestore!==initialRows){
802
+ failures.push({route,section:ctx.section,kind:'invoice-draft-row-count-not-restored',
803
+ initialRows,afterRestore});
804
+ }
805
+ }
806
+ }
807
+ const remainingFirst=clickables(itemsBody).find(x=>
808
+ /InvoiceFormView\._removeRow\(0\)/.test(handler(x)));
809
+ if(remainingFirst && itemsBody.querySelectorAll('tr').length===1){
810
+ registerControl(remainingFirst,route,ctx.section+'/modal');
811
+ const beforeGuard=itemsBody.querySelectorAll('tr').length;
812
+ await press(remainingFirst,route,ctx.section+'/modal','open');
813
+ const afterGuard=itemsBody.querySelectorAll('tr').length;
814
+ if(afterGuard!==beforeGuard){
815
+ failures.push({route,section:ctx.section,kind:'invoice-last-row-removal-not-blocked',
816
+ beforeGuard,afterGuard});
817
+ }
818
+ }
819
+ }
820
+
821
+ // Adding a contact tag changes only the unsaved form DOM. Verify it,
822
+ // then let the parent Cancel discard it; never click Save.
823
+ const tagAction=nested.find(x=>/ContactsView\.addNewTag\s*\(/.test(handler(x)));
824
+ const tagInput=overlay.querySelector('#newTagInput');
825
+ if(tagAction && tagInput){
826
+ const testTag='Q01-AUDIT-TAG';
827
+ tagInput.value=testTag;
828
+ registerControl(tagAction,route,ctx.section+'/modal');
829
+ await press(tagAction,route,ctx.section+'/modal','open');
830
+ if(!overlay.querySelector('.tagCheckbox[value="'+testTag+'"]')){
831
+ failures.push({route,section:ctx.section,kind:'unsaved-contact-tag-not-added'});
832
+ }
833
+ }
834
+
835
// Exercise a real cancel/close button when present.
836
const cancel=nested.find(x=>/FINORA\.Modal\.close|Modal\.closeAll/.test(handler(x)) ||
837
/^(انصراف|بستن|بازگشت|✕|×)$/.test(name(x)));