فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(ui): inventory all visible controls and click safe nested tabs/openers in installed native WebView2
davoodmehraban89 committed
Oct 30, 2026 at 23:15 UTC
a8c24ae6f503756928d1f2a85df304ef4b401406
1 file changed
+226
tests/windows-vm-ui-interaction-audit-browser.js
new
+226
@@ -0,0 +1,226 @@
1
+'use strict';
2
+// Executed as a single async expression inside an INSTALLED Tauri WebView2,
3
+// on a disposable Windows VM after synthetic financial fixtures are created.
4
+// This does not click destructive actions; these need separate fixture-backed
5
+// accounting correctness tests. Never claim "all buttons work" from a sweep.
6
+(async () => {
7
+ const wait = ms => new Promise(r => setTimeout(r, ms));
8
+ const routes = [
9
+ 'dashboard','invoices','products','contacts','treasury',
10
+ 'cheques','expenses','reports','accounting','settings'
11
+ ];
12
+ const failures = [];
13
+ const inventories = [];
14
+ const clicks = [];
15
+ const skipped = [];
16
+ const all = new Map();
17
+ const target = () => document.getElementById('pageContent');
18
+ const isVisible = el => {
19
+ const style = window.getComputedStyle(el);
20
+ return style.display !== 'none' && style.visibility !== 'hidden' &&
21
+ el.getClientRects().length > 0;
22
+ };
23
+ const name = el => String(
24
+ el.getAttribute('aria-label') || el.getAttribute('title') ||
25
+ el.innerText || el.textContent || '').replace(/\s+/g, ' ').trim().slice(0, 90);
26
+ const handler = el => el.getAttribute('onclick') ||
27
+ el.getAttribute('onchange') || el.getAttribute('onsubmit') || '';
28
+ const sig = (el, route, section) => [
29
+ route, section, el.tagName.toLowerCase(), name(el),
30
+ handler(el).replace(/\s+/g,' ').slice(0,180)
31
+ ].join('|');
32
+ const dangerous = /\b(?:delete|wipe|remove|restore|save|post|submit|confirm|activate|seed|commit|final|approve|closePeriod|logout|export|import|download|print|settle|apply|reset|changeStatus|_save|_apply|_commit)\s*\(/i;
33
+ const safeTab = /\.(?:_switchTab|switchTab|_switchPeriod|_setPreset|_setStockFilter|_clearFilters)\s*\(/;
34
+ 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 clickables = (root) => [...root.querySelectorAll(
36
+ 'button, a, [role="button"], input[type="button"], input[type="submit"], [onclick]'
37
+ )].filter(isVisible);
38
+ function inventory(route, section) {
39
+ const controls = clickables(target());
40
+ const records = [];
41
+ for (const el of controls) {
42
+ const k=sig(el,route,section);
43
+ if (all.has(k)) continue;
44
+ const code=handler(el);
45
+ const accessible=!!name(el);
46
+ const row={
47
+ route,section,tag:el.tagName.toLowerCase(),
48
+ label:name(el),handler:code.slice(0,220),
49
+ disabled:!!el.disabled || el.getAttribute('aria-disabled')==='true',
50
+ hasAccessibleName:accessible,
51
+ className:String(el.className||'').slice(0,120),
52
+ type:el.getAttribute('type')||'',
53
+ status:'not-clicked',reason:''
54
+ };
55
+ all.set(k,row); records.push(row);
56
+ }
57
+ inventories.push({route,section,newControls:records.length,totalVisible:controls.length});
58
+ return controls;
59
+ }
60
+ async function go(route) {
61
+ const link=document.querySelector('#sidebarMenu [data-page="'+route+'"]');
62
+ if (!link) throw Error('main sidebar menu item missing: '+route);
63
+ link.click(); await wait(160);
64
+ if (FINORA.Router.current()!==route) throw Error('sidebar click did not navigate: '+route);
65
+ if (!target() || target().textContent.trim().length < 10 ||
66
+ target().textContent.includes('خطا در بارگذاری صفحه')) {
67
+ throw Error('screen blank/failed after clicking: '+route);
68
+ }
69
+ if (document.getElementById('finoraAuthOverlay')) throw Error('auth returned during navigation');
70
+ }
71
+ const noError = () => !document.querySelector('.toast-error') &&
72
+ !target()?.textContent.includes('خطا در بارگذاری صفحه');
73
+ function dismiss() {
74
+ FINORA.Modal.closeAll();
75
+ document.querySelectorAll('.toast-close').forEach(x=>x.click());
76
+ }
77
+ function resolveHandler(code) {
78
+ const m=code.match(/(?:window\.)?([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+)\s*\(/);
79
+ if (!m) return {detected:false,valid:null,callee:''};
80
+ const parts=m[1].split('.');
81
+ let obj=window;
82
+ for (const part of parts) {
83
+ if (obj == null) return {detected:true,valid:false,callee:m[1]};
84
+ obj=obj[part];
85
+ }
86
+ return {detected:true,valid:typeof obj==='function',callee:m[1]};
87
+ }
88
+ const seenClick = new Set();
89
+ async function press(el, route, section, category) {
90
+ const k=sig(el,route,section);
91
+ if (seenClick.has(k)) return;
92
+ seenClick.add(k);
93
+ const row=all.get(k);
94
+ const before=target().innerHTML;
95
+ const beforeModal=!!document.querySelector('.modal-backdrop');
96
+ try {
97
+ el.click(); await wait(180);
98
+ if (!noError()) throw Error('error toast or page render error');
99
+ const after=target()?.innerHTML||'';
100
+ const afterModal=!!document.querySelector('.modal-backdrop');
101
+ const changed = before !== after || beforeModal !== afterModal;
102
+ clicks.push({route,section,category,label:name(el),
103
+ handler:handler(el).slice(0,170),changed,afterModal});
104
+ if (row) {row.status='clicked';row.reason=changed?'visible-state-changed':'no-observable-DOM-change';}
105
+ if (!changed) {
106
+ failures.push({route,section,kind:'no-visible-change',label:name(el),handler:handler(el).slice(0,170)});
107
+ }
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();}
112
+ }
113
+ for (const route of routes) {
114
+ await go(route);
115
+ const tabs = inventory(route,'root').filter(el => !el.disabled && safeTab.test(handler(el)));
116
+ // Evaluate each known safe top-level tab. The router is reset between
117
+ // clicks to avoid mutating references after HTML rerendering.
118
+ const tabActions=[...new Set(tabs.map(el=>handler(el)))];
119
+ const contexts=[{section:'root',tabAction:null}];
120
+ for (const action of tabActions) contexts.push({section:'tab-'+contexts.length,tabAction:action});
121
+ for (const ctx of contexts) {
122
+ await go(route);
123
+ if (ctx.tabAction) {
124
+ const tab=clickables(target()).find(el=>handler(el)===ctx.tabAction);
125
+ if (tab) {
126
+ inventory(route,'root');
127
+ await press(tab,route,'root','tab');
128
+ } else {
129
+ failures.push({route,section:ctx.section,kind:'tab-missing',handler:ctx.tabAction});
130
+ continue;
131
+ }
132
+ }
133
+ const controls=inventory(route,ctx.section);
134
+ // For every visible clickable control, check function resolution. This
135
+ // inventory includes buttons we must not click indiscriminately.
136
+ for (const el of controls) {
137
+ const k=sig(el,route,ctx.section),row=all.get(k);
138
+ if (!row) continue;
139
+ const code=handler(el);
140
+ const parsed=resolveHandler(code);
141
+ if (parsed.detected && !parsed.valid) {
142
+ row.status='broken-handler';row.reason='target function missing';
143
+ failures.push({route,section:ctx.section,kind:'missing-function',callee:parsed.callee});
144
+ } else if (el.disabled) {row.status='disabled';row.reason='disabled state';}
145
+ else if (dangerous.test(code)) {
146
+ row.status='not-clicked';row.reason='financial or destructive action needs explicit fixture-backed test';
147
+ } else if (!code) {
148
+ row.status='not-clicked';row.reason='dynamic event listener or no inline action; requires focused audit';
149
+ } else if (!safeTab.test(code) && !safeOpen.test(code)) {
150
+ row.status='not-clicked';row.reason='not on audited safe-action allowlist';
151
+ }
152
+ }
153
+ // Open every safe modal/editor visible in this context without saving.
154
+ const openActions=[...new Set(controls
155
+ .filter(el=>!el.disabled && safeOpen.test(handler(el)))
156
+ .map(el=>handler(el)))].slice(0,30);
157
+ for (const action of openActions) {
158
+ await go(route);
159
+ if (ctx.tabAction) {
160
+ const tab=clickables(target()).find(el=>handler(el)===ctx.tabAction);
161
+ if(tab){tab.click();await wait(160);}
162
+ }
163
+ const el=clickables(target()).find(x=>handler(x)===action);
164
+ if (!el) {failures.push({route,section:ctx.section,kind:'open-action-vanished',handler:action});continue;}
165
+ inventory(route,ctx.section);
166
+ await press(el,route,ctx.section,'open');
167
+ const overlay=document.querySelector('.modal-backdrop');
168
+ if(overlay) {
169
+ const nested=clickables(overlay);
170
+ const modalControls=nested.map(x=>({
171
+ route,section:ctx.section+'/modal',tag:x.tagName.toLowerCase(),
172
+ label:name(x),handler:handler(x).slice(0,180),
173
+ disabled:!!x.disabled,hasAccessibleName:!!name(x),
174
+ status:'not-clicked',reason:'modal action; untested or requires fixture-backed input'
175
+ }));
176
+ modalControls.forEach(x=>{
177
+ const key=[x.route,x.section,x.tag,x.label,x.handler].join('|');
178
+ if(!all.has(key))all.set(key,x);
179
+ });
180
+ // Exercise a real cancel/close button when present.
181
+ const cancel=nested.find(x=>/FINORA\.Modal\.close|Modal\.closeAll/.test(handler(x)) ||
182
+ /^(انصراف|بستن|بازگشت|✕|×)$/.test(name(x)));
183
+ if(cancel){
184
+ cancel.click();await wait(70);
185
+ clicks.push({route,section:ctx.section+'/modal',category:'cancel',
186
+ label:name(cancel),handler:handler(cancel).slice(0,170),
187
+ changed:!document.querySelector('.modal-backdrop')});
188
+ const key=[route,ctx.section+'/modal',cancel.tagName.toLowerCase(),
189
+ name(cancel),handler(cancel).slice(0,180)].join('|');
190
+ const row=all.get(key);if(row)row.status='clicked';
191
+ }
192
+ }
193
+ dismiss();
194
+ }
195
+ }
196
+ }
197
+ await FINORA.Router.go('dashboard');
198
+ const rows=[...all.values()];
199
+ const byRoute={};
200
+ for(const route of routes) {
201
+ const slice=rows.filter(x=>x.route===route);
202
+ byRoute[route]={
203
+ discovered:slice.length,
204
+ clicked:slice.filter(x=>x.status==='clicked').length,
205
+ notClicked:slice.filter(x=>x.status==='not-clicked').length,
206
+ brokenHandlers:slice.filter(x=>x.status==='broken-handler').length,
207
+ missingAccessibleName:slice.filter(x=>!x.hasAccessibleName).length
208
+ };
209
+ }
210
+ return {
211
+ environment:'installed-Windows-Tauri-WebView2-synthetic-VM',
212
+ routesVisited:routes.length,routeNames:routes,
213
+ inventoryCount:rows.length,
214
+ safeClickCount:clicks.length,
215
+ skippedCount:rows.filter(x=>x.status==='not-clicked').length,
216
+ brokenHandlerCount:rows.filter(x=>x.status==='broken-handler').length,
217
+ accessibilityNameGaps:rows.filter(x=>!x.hasAccessibleName).length,
218
+ problems:failures,
219
+ byRoute,
220
+ controls:rows,
221
+ clickEvidence:clicks,
222
+ financialActionsNotBulkClicked:true,
223
+ customerDataUsed:false,
224
+ everyActionVerified:false
225
+ };
226
+})()
\ No newline at end of file