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

test(ui): verify all inline view-method handlers and 10 sidebar routes with explicit incomplete coverage reporting

davoodmehraban89 committed Oct 30, 2026 at 23:16 UTC ae80caa653a82fee87619121bf2cb44bcc483840
1 file changed +64
tests/ui-control-structure.test.mjs new
+64
@@ -0,0 +1,64 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import fs from 'node:fs';
4 +import path from 'node:path';
5 +import { fileURLToPath } from 'node:url';
6 +
7 +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
8 +const folder = path.join(root, 'src', 'views');
9 +const viewFiles = fs.readdirSync(folder).filter(n => n.endsWith('.js'));
10 +const views = new Map(viewFiles.map(filename => [
11 + path.basename(filename, '.js'),
12 + fs.readFileSync(path.join(folder, filename), 'utf8')
13 +]));
14 +
15 +test('Q01: every named inline view handler has an actual declared view method', () => {
16 + const missing = [];
17 + const refs = [];
18 + for (const [sourceName, source] of views) {
19 + // Find only declarations in the HTML/template markup, not arbitrary test
20 + // or controller calls that do not become user-facing controls.
21 + const actions = [...source.matchAll(/on(?:click|change|input|submit|mousedown|blur|focus|keyup|keydown)\\?=["']([^"']+)["']/g)];
22 + for (const action of actions) {
23 + const handler = action[1].replace(/\\(["'])/g, '$1');
24 + for (const call of handler.matchAll(/(?:window\\.)?([A-Za-z_$][\\w$]*(?:View|Modal))\\.([A-Za-z_$][\\w$]*)\\s*\\(/g)) {
25 + const viewName = call[1], method = call[2];
26 + refs.push({sourceName, viewName, method});
27 + const src = views.get(viewName);
28 + if (!src) {
29 + missing.push({sourceName, viewName, method, reason:'source-not-found'});
30 + continue;
31 + }
32 + const declaration = new RegExp('^\\s*(?:async\\s+)?' + method + '\\s*\\(', 'm');
33 + if (!declaration.test(src)) missing.push({sourceName, viewName, method, reason:'method-not-declared'});
34 + }
35 + }
36 + }
37 + assert.ok(viewFiles.length >= 10, 'unexpectedly few view files in UI inventory');
38 + assert.ok(refs.length >= 80, 'inline view events not sufficiently inventoried');
39 + assert.deepEqual(missing, [], 'declared on* handlers must resolve to real view methods');
40 +});
41 +
42 +test('Q01: the actual sidebar has one entry for each registered route', () => {
43 + const shell = fs.readFileSync(path.join(root, 'index.html'), 'utf8');
44 + const main = fs.readFileSync(path.join(root, 'src', 'main.js'), 'utf8');
45 + const sidebar = [...shell.matchAll(/data-page="([a-z]+)"/g)].map(x=>x[1]);
46 + const registered = [...main.matchAll(/\{ name: '([a-z]+)',\s*title:/g)].map(x=>x[1]);
47 + assert.equal(new Set(sidebar).size, sidebar.length, 'sidebar has duplicated navigation controls');
48 + assert.equal(new Set(registered).size, registered.length, 'router has duplicate route definitions');
49 + assert.equal(sidebar.length, 10, 'navigation coverage baseline changed; update native click audit');
50 + assert.deepEqual(sidebar.sort(), registered.sort(), 'sidebar has missing, orphan or dead routes');
51 +});
52 +
53 +test('Q01: the native UI coverage runner must report unclicked controls explicitly', () => {
54 + const source = fs.readFileSync(path.join(root, 'tests', 'windows-vm-ui-interaction-audit-browser.js'), 'utf8');
55 + for (const required of [
56 + 'routesVisited','safeClickCount','not-clicked',
57 + 'financialActionsNotBulkClicked:true','everyActionVerified:false',
58 + 'accessibilityNameGaps','missing-function'
59 + ]) {
60 + assert.ok(source.includes(required), 'coverage reporter missing mandatory field: '+required);
61 + }
62 + assert.ok(!source.includes('localStorage.clear()') && !source.includes('wipeAll('),
63 + 'interaction audit must never clear the database in the installed VM');
64 +});