@davoodmehraban89 / Factor-easy / commits / f7128b2
Fork 0

سامانه صدور فاکتور و حسابداری

test: assert Pages invoice product and buyer search filters with no selection or save

davoodmehraban89 committed Oct 15, 2026 at 21:49 UTC f7128b21c3b65e03d1a418e07a1818a8aa98abda
1 file changed +100
scripts/pages-artifact.spec.js
+100
@@ -180,3 +180,103 @@ 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 invoice product and buyer filters stay scoped and do not persist draft edits',async({page})=>{
186 + const pageErrors=[];
187 + page.on('pageerror',e=>pageErrors.push(e.message));
188 + await page.goto(base,{waitUntil:'domcontentloaded'});
189 + await page.waitForFunction(()=>window.FinoraLoginActionsBound===true&&
190 + typeof window.applyLicensedModuleUI==='function'&&
191 + typeof window.finoraRefreshSearchableSelect==='function'&&
192 + typeof window.renderContacts==='function'&&
193 + window.FinoraStartupStatus?.extensionsReady===true,{timeout:20000});
194 + const initial=await page.evaluate(()=>{
195 + // All records are synthetic and live ONLY in this local browser process.
196 + const uid='qa-pages-selectors';
197 + currentUser={id:uid,role:'accountant',modules:['full_suite'],
198 + subscription:{type:'lifetime',status:'active',endDate:'2099-01-01'}};
199 + const product=(id,name,unit,price,ownerUserId=uid)=>({
200 + id,ownerUserId,code:id,name,spec:'آزمایشی',unit,sale_price:price
201 + });
202 + datastore.settings=[{ownerUserId:uid,default_company_id:'QA_CO',ui_theme:'light'}];
203 + datastore.companies=[{id:'QA_CO',ownerUserId:uid,name:'شرکت آزمون مستقل'}];
204 + datastore.products=[
205 + product('QA_P10','بلوک سبک ۱۰','عدد',11000),
206 + product('QA_P15','بلوک سبک ۱۵','بسته',15000),
207 + product('QA_H1','هارد آزمایشی','عدد',20000),
208 + product('OTHER_P','بلوک محرمانه','عدد',1,'OTHER_USER')
209 + ];
210 + datastore.contacts=[
211 + {id:'QA_C1',ownerUserId:uid,name:'شرکت آزمایشی الف',role:'customer',balance:0},
212 + {id:'QA_C2',ownerUserId:uid,name:'شرکت آزمایشی ب',role:'both',balance:0},
213 + {id:'QA_C3',ownerUserId:uid,name:'آزمایش شخص حقیقی',role:'customer',balance:0},
214 + {id:'OTHER_C',ownerUserId:'OTHER_USER',name:'شرکت محرمانه',role:'customer',balance:0}
215 + ];
216 + datastore.invoices=[];datastore.purchases=[];
217 + document.querySelector('#auth-screen').style.display='none';
218 + applyLicensedModuleUI();
219 + renderContacts();
220 + finoraEnsureInitialInvoiceRow();
221 + const goods=document.querySelector('#invoice-items-table-body .row-product-select');
222 + const buyer=document.querySelector('#invoice-contact-id');
223 + if(!goods||!buyer)throw new Error('Missing invoice product/customer controls');
224 + finoraRefreshSearchableSelect(goods);
225 + finoraRefreshSearchableSelect(buyer);
226 + window.__qaPersistedWrites=0;
227 + window.saveDatastore=()=>{
228 + window.__qaPersistedWrites++;
229 + throw new Error('Unexpected saveDatastore during filter-only QA');
230 + };
231 + return {goods:goods.value,buyer:buyer.value,
232 + products:[...goods.options].filter(o=>o.value).map(o=>o.value),
233 + customers:[...buyer.options].filter(o=>o.value).map(o=>o.value)};
234 + });
235 + expect(initial.products).toEqual(['QA_P10','QA_P15','QA_H1']);
236 + expect(initial.customers).toEqual(['QA_C1','QA_C2','QA_C3']);
237 + await page.locator('#module-rail [data-module="commerce"]').click();
238 + await expect(page.locator('#view-invoices')).toHaveClass(/active/);
239 + await expect(page.locator('#module-panel-title')).toHaveText('بازرگانی');
240 +
241 + const productSelect=page.locator('#invoice-items-table-body .row-product-select').first();
242 + const productInput=productSelect.locator('xpath=..').locator('.finora-combobox-input');
243 + await productInput.click();
244 + await productInput.fill('بلوک');
245 + const productList=page.locator('body > .finora-combobox-list:visible');
246 + await expect(productList.locator('[role="option"]')).toHaveCount(2);
247 + await expect(productList).not.toContainText('محرمانه');
248 + expect(await page.evaluate(()=>{
249 + const sel=document.querySelector('#invoice-items-table-body .row-product-select');
250 + return [...sel.options].filter(o=>o.value).map(o=>({id:o.value,unit:o.dataset.unit,price:o.dataset.price}));
251 + })).toEqual([
252 + {id:'QA_P10',unit:'عدد',price:'11000'},
253 + {id:'QA_P15',unit:'بسته',price:'15000'},
254 + {id:'QA_H1',unit:'عدد',price:'20000'}
255 + ]);
256 + await productInput.press('Escape');
257 + await expect(productSelect).toHaveValue(initial.goods);
258 +
259 + const buyerSelect=page.locator('#invoice-contact-id');
260 + const buyerInput=buyerSelect.locator('xpath=..').locator('.finora-combobox-input');
261 + await buyerInput.click();
262 + await buyerInput.fill('شرکت');
263 + const buyerList=buyerSelect.locator('xpath=..').locator('.finora-combobox-list');
264 + await expect(buyerList.locator('[role="option"]')).toHaveCount(2);
265 + await expect(buyerList).not.toContainText('محرمانه');
266 + await expect(buyerSelect).toHaveValue(initial.buyer);
267 + await buyerInput.press('Escape');
268 +
269 + const final=await page.evaluate(()=>({
270 + saves:window.__qaPersistedWrites,
271 + productId:document.querySelector('#invoice-items-table-body .row-product-select').value,
272 + buyerId:document.querySelector('#invoice-contact-id').value,
273 + invoices:datastore.invoices.length,
274 + crossUserProduct:getMyProducts().some(p=>p.id==='OTHER_P'),
275 + crossUserBuyer:getMyContacts().some(c=>c.id==='OTHER_C')
276 + }));
277 + expect(final).toEqual({
278 + saves:0,productId:initial.goods,buyerId:initial.buyer,invoices:0,
279 + crossUserProduct:false,crossUserBuyer:false
280 + });
281 + expect(pageErrors).toEqual([]);
282 +});