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

test(native): cover legacy and integrated stock adjustment UI

davoodmehraban89 committed Oct 31, 2026 at 22:19 UTC a66fe65fe78a81f81a46ce951d391e0fda2fc9aa
1 file changed +109
tests/windows-vm-native-functional-matrix.cjs
+109
@@ -3,6 +3,113 @@
3 // WebView2. Every write is synthetic and isolated to a disposable CI VM.
4 const assert = require('node:assert/strict');
5
6 +async function legacyStockAdjustmentFormAndValidation() {
7 + const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
8 + const check = (value, message) => { if (!value) throw Error(message); };
9 + await FINORA.Router.go('products');
10 + await wait(160);
11 + const product = await window.ProductController.createProduct({
12 + name: 'Q01 کالای اصلاح دستی ساختگی',
13 + code: 'Q01-LEGACY-ADJUST',
14 + trackInventory: true,
15 + buyPrice: 100,
16 + sellPrice: 150
17 + });
18 + await window.StockKardexModal.open(product.id);
19 + await wait(80);
20 + const parent = FINORA.Modal.stack.at(-1);
21 + check(parent?.card?.dataset.stockKardexProductId === product.id,
22 + 'Legacy Kardex parent dialog did not open');
23 + const openAdjust = parent.card.querySelector('button[onclick*="openAdjustModal"]');
24 + check(openAdjust, 'Legacy mode did not expose manual stock adjustment');
25 + openAdjust.click();
26 + await wait(80);
27 + const child = FINORA.Modal.stack.at(-1);
28 + check(FINORA.Modal.stack.length === 2 && document.getElementById('adjQty'),
29 + 'Manual adjustment child dialog did not open');
30 + const save = () => [...child.card.querySelectorAll('.modal-footer button')]
31 + .find(button => !button.disabled && /ثبت اصلاح/.test(button.textContent));
32 + const saveButton = save();
33 + check(saveButton, 'Manual stock adjustment save button is missing');
34 + const before = (await FINORA.Storage.getAll('stock_movements'))
35 + .filter(move => move.productId === product.id);
36 + document.getElementById('adjQty').value = '1.2345';
37 + saveButton.click();
38 + await wait(80);
39 + check(FINORA.Modal.stack.at(-1) === child &&
40 + (await FINORA.Storage.getAll('stock_movements')).filter(move =>
41 + move.productId === product.id).length === before.length,
42 + 'Over-precision stock adjustment was not rejected without writes');
43 + document.getElementById('adjQty').value = '-1';
44 + saveButton.click();
45 + await wait(80);
46 + check(FINORA.Modal.stack.at(-1) === child &&
47 + (await FINORA.Storage.getAll('stock_movements')).filter(move =>
48 + move.productId === product.id).length === before.length,
49 + 'Negative stock adjustment was not rejected without writes');
50 + document.getElementById('adjQty').value = '3.125';
51 + document.getElementById('adjNote').value = 'Q01 synthetic count';
52 + saveButton.click();
53 + let movement = null;
54 + for (let i = 0; i < 60; i++) {
55 + movement = (await FINORA.Storage.getAll('stock_movements'))
56 + .find(move => move.productId === product.id && move.type === 'adjust');
57 + if (movement && FINORA.Modal.stack.length === 1 &&
58 + FINORA.Modal.stack.at(-1) === parent) break;
59 + await wait(100);
60 + }
61 + check(movement?.qty === 3.125 && movement.note === 'Q01 synthetic count' &&
62 + await window.ProductController.getStock(product.id) === 3.125,
63 + 'Valid manual stock adjustment did not persist the final counted quantity');
64 + check(FINORA.Modal.stack.length === 1 && FINORA.Modal.stack.at(-1) === parent &&
65 + document.querySelectorAll('.modal-backdrop').length === 1,
66 + 'Saving stock adjustment opened a duplicate Kardex instead of refreshing its parent');
67 + await FINORA.Modal.close();
68 + check(!document.querySelector('.toast-error'),
69 + 'Legacy stock adjustment form displayed an unexpected error');
70 + return { overPrecisionRejectedWithoutWrites: true,
71 + negativeRejectedWithoutWrites: true, validAdjustmentPosted: true,
72 + fractionalQuantityPreserved: true, parentKardexRefreshedInPlace: true,
73 + duplicateKardexPrevented: true };
74 +}
75 +
76 +async function integratedStockAdjustmentGuard() {
77 + const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
78 + const check = (value, message) => { if (!value) throw Error(message); };
79 + await FINORA.Router.go('products');
80 + await wait(160);
81 + const product = await window.ProductController.createProduct({
82 + name: 'Q01 کالای یکپارچه ساختگی',
83 + code: 'Q01-INTEGRATED-ADJUST',
84 + trackInventory: true,
85 + buyPrice: 100,
86 + sellPrice: 150
87 + });
88 + await window.StockKardexModal.open(product.id);
89 + await wait(80);
90 + const parent = FINORA.Modal.stack.at(-1);
91 + check(parent?.card?.dataset.stockKardexProductId === product.id,
92 + 'Integrated Kardex parent dialog did not open');
93 + const body = parent.card.querySelector('.modal-body');
94 + check(body && !body.querySelector('button[onclick*="openAdjustModal"]') &&
95 + body.textContent.includes('انبارگردانی'),
96 + 'Integrated inventory still exposes an unusable manual adjustment button');
97 + const before = (await FINORA.Storage.getAll('stock_movements'))
98 + .filter(move => move.productId === product.id);
99 + await window.StockKardexModal.openAdjustModal(product.id);
100 + check(FINORA.Modal.stack.length === 1 && !document.getElementById('adjQty'),
101 + 'Direct manual-adjust modal invocation bypassed integrated-mode guard');
102 + await window.StockKardexModal.saveAdjust(product.id);
103 + const after = (await FINORA.Storage.getAll('stock_movements'))
104 + .filter(move => move.productId === product.id);
105 + check(JSON.stringify(before) === JSON.stringify(after) &&
106 + await window.ProductController.getStock(product.id) === 0,
107 + 'Integrated-mode manual adjustment guard wrote a stock movement');
108 + await FINORA.Modal.close();
109 + return { manualAdjustmentHidden: true, directOpenBlocked: true,
110 + directSaveBlocked: true, zeroStockWrites: true };
111 +}
112 +
113 async function activateAccounting() {
114 const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
115 const check = (value, message) => { if (!value) throw Error(message); };
@@ -1321,7 +1428,9 @@ async function openingDryRunWithExistingActivity() {
1428
1429 module.exports = async function nativeFunctionalMatrix(cdp) {
1430 const phases = [
1431 + ['legacy-stock-adjustment-form-and-validation', legacyStockAdjustmentFormAndValidation],
1432 ['activate-accounting-and-inventory', activateAccounting],
1433 + ['integrated-stock-adjustment-guard', integratedStockAdjustmentGuard],
1434 ['contacts-crud-form-and-tags', nativeContactCrudFormAndTags],
1435 ['products-crud-form-and-nested-classifiers', nativeProductCrudFormAndNestedClassifiers],
1436 ['positive-opening-ledger-and-idempotency', nativePositiveOpeningLedger],