سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 18:00 UTC
test: cover production Pages invoice product/buyer filtering and metadata with zero-write synthetic fixture
davoodmehraban89 committed
Oct 15, 2026 at 21:37 UTC
c71ed9ac937491247f3c4e6e0d3ff48dbac2e049
1 file changed
+86
scripts/pages-artifact.spec.js
+86
@@ -180,3 +180,89 @@ test('Published Pages CSP event bindings open Commerce and the top-bar sales inv
180
await expect(quick).toHaveAttribute('aria-expanded','false');
181
expect(pageErrors).toEqual([]);
182
});
183
+
184
+
185
+test('Published Pages F0-02 invoice product and buyer search only use synthetic data without writes',async({page})=>{
186
+ // No real Supabase session. The built Pages event binder + ERP bundles execute in Chromium.
187
+ const errors=[];
188
+ page.on('pageerror',e=>errors.push(e.message));
189
+ await page.goto(base,{waitUntil:'domcontentloaded'});
190
+ await page.waitForFunction(()=>window.FinoraStartupStatus?.extensionsReady===true&&
191
+ typeof window.finoraRefreshSearchableSelect==='function'&&
192
+ typeof window.addInvoiceItemRow==='function'&&
193
+ typeof window.renderContacts==='function');
194
+ await page.evaluate(()=>{
195
+ currentUser={
196
+ id:'F0-02-SYNTHETIC-ONLY',role:'accountant',modules:['full_suite'],
197
+ subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}
198
+ };
199
+ datastore.companies=[
200
+ {id:'QA_CO',ownerUserId:currentUser.id,name:'شرکت آزمون غیرواقعی'}
201
+ ];
202
+ datastore.settings=[{
203
+ ownerUserId:currentUser.id,default_company_id:'QA_CO',
204
+ currency_mode:'rial',vat_mode:'none',vat_rate:10
205
+ }];
206
+ datastore.products=[
207
+ {id:'QA_B10',ownerUserId:currentUser.id,name:'بلوک سیمانی سبک',
208
+ code:'B-10',spec:'ده سانت',unit:'عدد',sale_price:1700,buy_price:1200},
209
+ {id:'QA_B15',ownerUserId:currentUser.id,name:'بلوک دیواری',
210
+ code:'B-15',spec:'پانزده سانت',unit:'عدد',sale_price:2400,buy_price:2000},
211
+ {id:'QA_H1',ownerUserId:currentUser.id,name:'هارد تستی',
212
+ code:'H-1',spec:'ذخیره ساز',unit:'دستگاه',sale_price:4000,buy_price:2800},
213
+ {id:'OTHER_SECRET',ownerUserId:'ANOTHER_TENANT',name:'بلوک غیرمجاز',
214
+ code:'NOPE',spec:'نباید دیده شود',unit:'عدد',sale_price:1}
215
+ ];
216
+ datastore.contacts=[
217
+ {id:'QA_BUY1',ownerUserId:currentUser.id,name:'شرکت خریدار آزمایشی',role:'customer'},
218
+ {id:'QA_BUY2',ownerUserId:currentUser.id,name:'مشتری حقیقی آزمایشی',role:'customer'},
219
+ {id:'QA_SUP',ownerUserId:currentUser.id,name:'شرکت تامین کننده آزمایشی',role:'supplier'},
220
+ {id:'OTHER_PERSON',ownerUserId:'ANOTHER_TENANT',name:'شرکت بیگانه',role:'customer'}
221
+ ];
222
+ datastore.invoices=[];
223
+ window.__qaBackupSaveDatastore=saveDatastore;
224
+ window.__qaSaveCalls=0;
225
+ saveDatastore=()=>{window.__qaSaveCalls++;throw Error('UNEXPECTED_FINANCIAL_WRITE')};
226
+ document.getElementById('invoice-items-table-body').replaceChildren();
227
+ renderContacts();
228
+ addInvoiceItemRow();
229
+ const buyer=document.getElementById('invoice-contact-id');
230
+ finoraRefreshSearchableSelect(buyer);
231
+ document.getElementById('auth-screen').style.display='none';
232
+ applyLicensedModuleUI();
233
+ });
234
+ await page.locator('#module-rail [data-module="commerce"]').click();
235
+ await expect(page.locator('#view-invoices')).toHaveClass(/active/);
236
+ const row=page.locator('#invoice-items-table-body tr').first();
237
+ const product=row.locator('.row-product-select');
238
+ const productSearch=product.locator('xpath=..').locator('.finora-combobox-input');
239
+ await productSearch.click();
240
+ await productSearch.fill('بلوك');
241
+ const productOptions=page.locator('body > .finora-combobox-list [role="option"]');
242
+ await expect(productOptions).toHaveCount(2);
243
+ await expect(page.locator('body > .finora-combobox-list')).not.toContainText('غیرمجاز');
244
+ // Metadata must be available on *options* without clicking and changing a draft row.
245
+ const metadata=await product.evaluate(select=>{
246
+ const option=[...select.options].find(o=>o.value==='QA_B10');
247
+ return {unit:option?.dataset.unit,price:option?.dataset.price,selected:select.value};
248
+ });
249
+ expect(metadata).toEqual({unit:'عدد',price:'1700',selected:''});
250
+ await productSearch.press('Escape');
251
+ const buyer=page.locator('#invoice-contact-id');
252
+ const buyerSearch=buyer.locator('xpath=..').locator('.finora-combobox-input');
253
+ await buyerSearch.click();
254
+ await buyerSearch.fill('شرکت');
255
+ const buyerOptions=buyer.locator('xpath=..').locator('.finora-combobox-list [role="option"]');
256
+ await expect(buyerOptions).toHaveCount(1);
257
+ await expect(buyerOptions).toContainText('خریدار آزمایشی');
258
+ await expect(buyerOptions).not.toContainText('تامین کننده');
259
+ await expect(buyer).toHaveValue('QA_BUY1'.slice(0,0)); // no buyer selected by searching
260
+ await buyerSearch.press('Escape');
261
+ const unchanged=await page.evaluate(()=>({
262
+ saveCalls:window.__qaSaveCalls,invoiceCount:datastore.invoices.length,
263
+ productSelection:document.querySelector('#invoice-items-table-body .row-product-select')?.value||'',
264
+ buyerSelection:document.getElementById('invoice-contact-id')?.value||''
265
+ }));
266
+ expect(unchanged).toEqual({saveCalls:0,invoiceCount:0,productSelection:'',buyerSelection:''});
267
+ expect(errors).toEqual([]);
268
+});