فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
test(native): exercise contact and product forms end to end
davoodmehraban89 committed
Oct 31, 2026 at 22:09 UTC
07fec776be3e75261ebbd830a55e2b63234a3f39
1 file changed
+170
tests/windows-vm-native-functional-matrix.cjs
+170
@@ -51,6 +51,174 @@ async function activateAccounting() {
51
integration: 'enabled', warehouse: 'created' };
52
}
53
54
+async function nativeContactCrudFormAndTags() {
55
+ const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
56
+ const check = (value, message) => { if (!value) throw Error(message); };
57
+ await FINORA.Router.go('contacts');
58
+ await wait(180);
59
+ const view = window.ContactsView;
60
+ check(view, 'Native contacts view is unavailable');
61
+ await view.openContactModal();
62
+ await wait(80);
63
+ check(document.getElementById('cName') && document.getElementById('newTagInput'),
64
+ 'Native contact creation form is incomplete');
65
+ const originalName = 'Q01 شخص فرم ساختگی';
66
+ const updatedName = 'Q01 شخص ویرایششده';
67
+ const tag = 'Q01-NATIVE-CONTACT-TAG';
68
+ document.getElementById('cName').value = originalName;
69
+ document.getElementById('cRole').value = 'both';
70
+ document.getElementById('newTagInput').value = tag;
71
+ const addTag = [...document.querySelectorAll('.modal-card button')]
72
+ .find(button => /ContactsView\.addNewTag/.test(button.getAttribute('onclick') || ''));
73
+ check(addTag, 'Native contact tag action is missing');
74
+ addTag.click();
75
+ check(document.querySelector('.tagCheckbox[value="' + tag + '"]')?.checked,
76
+ 'New contact tag was not added and selected');
77
+ const saveContact = () => [...document.querySelectorAll('.modal-card .modal-footer button')]
78
+ .find(button => !button.disabled && /ذخیره/.test(button.textContent));
79
+ const createButton = saveContact();
80
+ check(createButton, 'Native contact create button is missing');
81
+ createButton.click();
82
+ let created = null;
83
+ for (let i = 0; i < 60; i++) {
84
+ created = (await FINORA.Storage.getAll('contacts'))
85
+ .find(contact => contact.name === originalName);
86
+ if (created && FINORA.Modal.stack.length === 0) break;
87
+ await wait(100);
88
+ }
89
+ check(created && created.tags.includes(tag),
90
+ 'Contact form did not persist the new contact and selected tag');
91
+ await view.editContact(created.id);
92
+ await wait(80);
93
+ check(document.getElementById('cName')?.value === originalName,
94
+ 'Contact edit form did not load the persisted record');
95
+ document.getElementById('cName').value = updatedName;
96
+ check(document.querySelector('.tagCheckbox[value="' + tag + '"]')?.checked,
97
+ 'Contact edit form did not restore the saved tag selection');
98
+ const updateButton = saveContact();
99
+ check(updateButton, 'Native contact update button is missing');
100
+ updateButton.click();
101
+ let updated = null;
102
+ for (let i = 0; i < 60; i++) {
103
+ updated = await FINORA.Storage.get('contacts', created.id);
104
+ if (updated?.name === updatedName && FINORA.Modal.stack.length === 0) break;
105
+ await wait(100);
106
+ }
107
+ check(updated?.name === updatedName && updated.tags.includes(tag),
108
+ 'Contact form update did not preserve identity and tags');
109
+ check(!document.querySelector('.toast-error'),
110
+ 'Native contact CRUD form displayed an unexpected error');
111
+ return { createdThroughForm: true, tagPersisted: true,
112
+ editedThroughForm: true, stableRecordId: true };
113
+}
114
+
115
+async function nativeProductCrudFormAndNestedClassifiers() {
116
+ const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
117
+ const check = (value, message) => { if (!value) throw Error(message); };
118
+ await FINORA.Router.go('products');
119
+ await wait(180);
120
+ const view = window.ProductsView;
121
+ check(view, 'Native products view is unavailable');
122
+ view._switchTab('products');
123
+ await view.openProductModal();
124
+ await wait(80);
125
+ const parentDepth = FINORA.Modal.stack.length;
126
+ check(parentDepth === 1 && document.getElementById('pName'),
127
+ 'Native product parent form is missing');
128
+ const unitName = 'Q01-UNIT-UI';
129
+ const unitButton = document.querySelector('.modal-card button[onclick*="openUnitModal(true)"]');
130
+ check(unitButton, 'Nested unit creation button is missing');
131
+ unitButton.click();
132
+ await wait(60);
133
+ check(FINORA.Modal.stack.length === parentDepth + 1 &&
134
+ document.getElementById('uName') && document.getElementById('uSymbol'),
135
+ 'Nested unit form did not open');
136
+ document.getElementById('uName').value = unitName;
137
+ document.getElementById('uSymbol').value = 'q1';
138
+ const saveTopModal = () => [...FINORA.Modal.stack.at(-1).card.querySelectorAll('.modal-footer button')]
139
+ .find(button => !button.disabled && /ذخیره/.test(button.textContent));
140
+ const saveUnit = saveTopModal();
141
+ check(saveUnit, 'Nested unit save action is missing');
142
+ saveUnit.click();
143
+ let unitId = '';
144
+ for (let i = 0; i < 60; i++) {
145
+ unitId = document.getElementById('pUnit')?.value || '';
146
+ if (FINORA.Modal.stack.length === parentDepth && unitId &&
147
+ (await FINORA.Storage.getAll('units')).some(unit => unit.id === unitId && unit.name === unitName)) break;
148
+ await wait(100);
149
+ }
150
+ check(FINORA.Modal.stack.length === parentDepth && unitId &&
151
+ (await FINORA.Storage.getAll('units')).some(unit => unit.id === unitId && unit.name === unitName),
152
+ 'Saving a nested unit did not restore parent and select persisted unit');
153
+
154
+ const categoryName = 'Q01-CATEGORY-UI';
155
+ const categoryButton = document.querySelector('.modal-card button[onclick*="openCategoryModal(true)"]');
156
+ check(categoryButton, 'Nested category creation button is missing');
157
+ categoryButton.click();
158
+ await wait(60);
159
+ check(FINORA.Modal.stack.length === parentDepth + 1 &&
160
+ document.getElementById('cName') && document.getElementById('cParent'),
161
+ 'Nested category form did not open');
162
+ document.getElementById('cName').value = categoryName;
163
+ const saveCategory = saveTopModal();
164
+ check(saveCategory, 'Nested category save action is missing');
165
+ saveCategory.click();
166
+ let categoryId = '';
167
+ for (let i = 0; i < 60; i++) {
168
+ categoryId = document.getElementById('pCategory')?.value || '';
169
+ if (FINORA.Modal.stack.length === parentDepth && categoryId &&
170
+ (await FINORA.Storage.getAll('categories')).some(category => category.id === categoryId && category.name === categoryName)) break;
171
+ await wait(100);
172
+ }
173
+ check(FINORA.Modal.stack.length === parentDepth && categoryId &&
174
+ (await FINORA.Storage.getAll('categories')).some(category => category.id === categoryId && category.name === categoryName),
175
+ 'Saving a nested category did not restore parent and select persisted category');
176
+
177
+ const productName = 'Q01 کالای فرم ساختگی';
178
+ document.getElementById('pCode').value = 'Q01-UI-PRODUCT';
179
+ document.getElementById('pName').value = productName;
180
+ document.getElementById('pBuyPrice').value = '1200';
181
+ document.getElementById('pSellPrice').value = '2400';
182
+ document.getElementById('pMinStock').value = '2.125';
183
+ const saveProduct = saveTopModal();
184
+ check(saveProduct, 'Native product create button is missing');
185
+ saveProduct.click();
186
+ let created = null;
187
+ for (let i = 0; i < 60; i++) {
188
+ created = (await FINORA.Storage.getAll('products'))
189
+ .find(product => product.code === 'Q01-UI-PRODUCT');
190
+ if (created && FINORA.Modal.stack.length === 0) break;
191
+ await wait(100);
192
+ }
193
+ check(created && created.name === productName && created.unitId === unitId &&
194
+ created.categoryId === categoryId && created.buyPrice === 1200 &&
195
+ created.sellPrice === 2400 && created.minStock === 2.125,
196
+ 'Product form failed to persist prices, reorder point, unit or category');
197
+ await view.editProduct(created.id);
198
+ await wait(80);
199
+ check(document.getElementById('pName')?.value === productName,
200
+ 'Product edit form did not load the persisted record');
201
+ const updatedName = 'Q01 کالای ویرایششده';
202
+ document.getElementById('pName').value = updatedName;
203
+ const updateProduct = saveTopModal();
204
+ check(updateProduct, 'Native product update button is missing');
205
+ updateProduct.click();
206
+ let updated = null;
207
+ for (let i = 0; i < 60; i++) {
208
+ updated = await FINORA.Storage.get('products', created.id);
209
+ if (updated?.name === updatedName && FINORA.Modal.stack.length === 0) break;
210
+ await wait(100);
211
+ }
212
+ check(updated?.name === updatedName && updated.unitId === unitId &&
213
+ updated.categoryId === categoryId && updated.sellPrice === 2400,
214
+ 'Product form update did not preserve selected classifiers and financial fields');
215
+ check(!document.querySelector('.toast-error'),
216
+ 'Native product CRUD form displayed an unexpected error');
217
+ return { createdThroughForm: true, nestedUnitSavedAndSelected: true,
218
+ nestedCategorySavedAndSelected: true, fractionalReorderPointPreserved: true,
219
+ editedThroughForm: true, stableRecordId: true };
220
+}
221
+
222
async function nativePositiveOpeningLedger() {
223
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
224
const check = (value, message) => { if (!value) throw Error(message); };
@@ -1154,6 +1322,8 @@ async function openingDryRunWithExistingActivity() {
1322
module.exports = async function nativeFunctionalMatrix(cdp) {
1323
const phases = [
1324
['activate-accounting-and-inventory', activateAccounting],
1325
+ ['contacts-crud-form-and-tags', nativeContactCrudFormAndTags],
1326
+ ['products-crud-form-and-nested-classifiers', nativeProductCrudFormAndNestedClassifiers],
1327
['positive-opening-ledger-and-idempotency', nativePositiveOpeningLedger],
1328
['purchase-and-post-ledger', purchaseInvoice],
1329
['partial-sale-and-inventory', saleInvoice],