فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(native): combine already passed real financial E2E with ten-route UI, backup replay and screenshot
davoodmehraban89 committed
Oct 16, 2026 at 18:56 UTC
164ea421a2edb1b212ba51074df946df17e08853
1 file changed
+24
-4
tests/windows-vm-installed-tauri-cdp.cjs
+24
-4
@@ -80,16 +80,16 @@ async function connect(url) {
80
if (reply.error) current.reject(Error(JSON.stringify(reply.error)));
81
else current.resolve(reply.result);
82
});
83
- const command = (method, params = {}) => new Promise((resolve, reject) => {
83
+ const command = (method, params = {}, timeoutMs = 12000) => new Promise((resolve, reject) => {
84
const next = ++id;
85
- const timer = setTimeout(() => { pending.delete(next); reject(Error('CDP ' + method + ' timed out')); }, 12000);
85
+ const timer = setTimeout(() => { pending.delete(next); reject(Error('CDP ' + method + ' timed out')); }, timeoutMs);
86
pending.set(next, { resolve, reject, timer });
87
ws.send(JSON.stringify({ id: next, method, params }));
88
});
89
- const evaluate = async expression => {
89
+ const evaluate = async (expression, timeoutMs = 12000) => {
90
const r = await command('Runtime.evaluate', {
91
expression, awaitPromise: true, returnByValue: true
92
- });
92
+ }, timeoutMs);
93
if (r.exceptionDetails) throw Error('Native UI exception: ' + r.exceptionDetails.text);
94
if (r.result?.subtype === 'error') throw Error('Native UI rejected JavaScript evaluation');
95
return r.result?.value;
@@ -294,6 +294,26 @@ async function connect(url) {
294
// verify accounting activation, financial journal, stock, backup and RTL.
295
report.nativeFunctional = await verifyNativeFunctionalMatrix(cdp);
296
}
297
+ if (mode === 'fresh') {
298
+ // Drive synthetic records, complete snapshot replay and every SPA route
299
+ // inside the actually installed Tauri WebView2, not Vite preview.
300
+ const ui = await cdp.evaluate("(async () => {\n const ensure = (pass, message) => { if (!pass) throw Error(message); };\n ensure(!document.getElementById('finoraAuthOverlay'), 'Cannot test UI before login');\n const person = await window.ContactController.create({\n name: 'شخص آزمایشی ماشین مجازی', role: 'both'\n });\n const product = await window.ProductController.createProduct({\n name: 'کالای آزمایشی ماشین مجازی', code: 'WINDOWS-VM-LAB',\n buyPrice: 150, sellPrice: 250, trackInventory: true\n });\n const db = window.FINORA.Storage;\n const before = {\n contacts: (await db.getAll('contacts')).length,\n products: (await db.getAll('products')).length\n };\n ensure((await db.get('contacts',person.id))?.name === 'شخص آزمایشی ماشین مجازی',\n 'Contact did not persist in the native app');\n ensure((await db.get('products',product.id))?.sellPrice === 250,\n 'Product did not persist in the native app');\n const snapshot = await db.exportAll();\n ensure(snapshot.version === 7 && snapshot.app === 'Factor-easyPro',\n 'Native snapshot identity/version mismatch');\n ensure(snapshot.data.users.every(u => !u.pwHash && !u.pwSalt && !u.pass),\n 'Credential hash leaked into plain export');\n ensure(snapshot.data.contacts.some(c => c.id === person.id) &&\n snapshot.data.products.some(p => p.id === product.id),\n 'Native snapshot missing committed master data');\n ensure(await db.importAll(snapshot) === true,\n 'Native full snapshot replay did not succeed');\n const after = {\n contacts: (await db.getAll('contacts')).length,\n products: (await db.getAll('products')).length\n };\n ensure(before.contacts === after.contacts && before.products === after.products,\n 'Snapshot replay duplicated a contact or product');\n const routes = [\n 'dashboard', 'invoices', 'products', 'contacts', 'treasury',\n 'cheques', 'expenses', 'reports', 'accounting', 'settings'\n ];\n const pages = [];\n for (const route of routes) {\n await FINORA.Router.go(route);\n const view = document.getElementById('pageContent');\n const text = (view?.textContent || '').trim();\n ensure(FINORA.Router.current() === route, 'Unexpected route: ' + route);\n ensure(text.length > 10, 'Empty page: ' + route);\n ensure(!text.includes('خطا در بارگذاری صفحه'),\n 'Router reported a page rendering error: ' + route);\n ensure(!document.querySelector('.toast-error'),\n 'Error toast while navigating to: ' + route);\n pages.push({route, renderedCharacters: text.length});\n }\n await FINORA.Router.go('dashboard');\n ensure(!document.getElementById('finoraAuthOverlay'),\n 'Navigation unexpectedly returned to authentication overlay');\n return {masterData:before, backup:'plain-no-credentials-replay-idempotent',\n routes:pages, visibleVersion:FINORA.version};\n})()", 45000);
301
+ assert.equal(ui.routes.length, 10);
302
+ assert.equal(ui.visibleVersion, expectedVersion);
303
+ report.nativeUI = ui;
304
+ try {
305
+ const screen = await cdp.command('Page.captureScreenshot', {
306
+ format: 'png', captureBeyondViewport: false, fromSurface: true
307
+ });
308
+ if (!screen?.data) throw Error('No PNG image data');
309
+ const filename = path.join(path.dirname(reportPath), 'fresh-native-dashboard.png');
310
+ fs.writeFileSync(filename, Buffer.from(screen.data, 'base64'));
311
+ report.screenshot = path.basename(filename);
312
+ } catch (screenshotError) {
313
+ // A screenshot is NOT claimed as verified if native CDP denies it.
314
+ report.screenshot = 'UNVERIFIED: ' + screenshotError.message;
315
+ }
316
+ }
317
report.status = 'PASSED';
318
console.log(JSON.stringify(report, null, 2));
319
} catch (err) {