@davoodmehraban89 / Factor-easy / commits / 92c92d2
Fork 0

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

test: real Chromium keyboard navigation, wheel selection, search and guarded F2 saves

davoodmehraban89 committed Oct 12, 2026 at 00:04 UTC 92c92d22a7856ba4f9c27af78ff37242c1b4a301
1 file changed +128
scripts/ux-keyboard-f2.spec.js new
+128
@@ -0,0 +1,128 @@
1 +const {test,expect}=require('@playwright/test');
2 +const path=require('node:path');
3 +
4 +async function fixture(page){
5 + const productOptions=Array.from({length:48},(_,i)=>'<option value="P'+i+'">کالا عمومی '+String(i).padStart(2,'0')+'</option>').join('');
6 + const contactOptions=Array.from({length:15},(_,i)=>'<option value="C'+i+'">شرکت شماره '+String(i).padStart(2,'0')+'</option>').join('');
7 + await page.setContent('<style>.view-pane{display:none}.view-pane.active{display:block}.list-shell{max-width:480px}.finora-combobox-list{font-size:16px}</style>'
8 + +'<section id="view-settings" class="view-pane"></section>'
9 + +'<section id="view-products" class="view-pane"><input id="prod-name-input"><button id="product-save-btn">ثبت کالا</button></section>'
10 + +'<section id="view-invoices" class="view-pane active"><div class="list-shell"><table><tbody id="invoice-items-table-body"><tr><td>'
11 + +'<select id="test-product" class="row-product-select"><option value="">-- انتخاب کالا --</option>'+productOptions+'</select>'
12 + +'<input class="row-quantity" value="0"></td></tr></tbody></table>'
13 + +'<select id="invoice-contact-id"><option value="">-- انتخاب شخص --</option>'+contactOptions+'</select></div></section>');
14 + await page.addScriptTag({content:`var currentUser={id:'QA1'};
15 + var datastore={settings:[{ownerUserId:'QA1',ui_theme:'light',hotkey_ctrl_s:true,hotkey_ctrl_enter:true}],products:[],contacts:[],companies:[{id:'C1',ownerUserId:'QA1'}],invoices:[],purchases:[],cheques:[],accounts:[],projects:[],journalVouchers:[]};
16 + var FINORA_MODULES={settings:{groups:[]}};
17 + window.__saves=0;window.__posted=0;window.__alerts=[];
18 + function getMySettings(){return datastore.settings[0]}
19 + function getMyCompanies(){return datastore.companies}
20 + function getMyProducts(){return datastore.products.filter(p=>p.ownerUserId===currentUser.id)}
21 + function getMyContacts(){return datastore.contacts}
22 + function getMyAccounts(){return datastore.accounts}
23 + function getMyGlobalProjects(){return datastore.projects}
24 + function requireWrite(){return true}
25 + function saveDatastore(){}
26 + function toggleAccordion(){}
27 + function esc(s){return String(s)}
28 + function commitSaveInvoice(){window.__saves++}
29 + function commitSaveProduct(){window.__saves++}
30 + function jePostSourceRecord(){window.__posted++}
31 + window.alert=m=>window.__alerts.push(String(m));`});
32 + await page.evaluate(()=>{
33 + datastore.products=[
34 + ...Array.from({length:48},(_,i)=>({id:'P'+i,ownerUserId:'QA1',name:'کالا عمومی '+String(i).padStart(2,'0'),code:'40'+i,unit:'عدد',sale_price:100+i})),
35 + {id:'BL1',ownerUserId:'QA1',name:'بلوک سیمانی ۱۰ سانتی',code:'310001',unit:'عدد',sale_price:1500},
36 + {id:'BL2',ownerUserId:'QA1',name:'بلوک سبک ۱۵ سانتی',code:'310002',unit:'عدد',sale_price:2000},
37 + {id:'BLOCKED',ownerUserId:'OTHER_TENANT',name:'بلوک محرمانه',code:'777',unit:'عدد',sale_price:1}
38 + ];
39 + });
40 + await page.addScriptTag({path:path.resolve('js/ux-hardening-r2.js')});
41 + await page.evaluate(()=>document.dispatchEvent(new Event('DOMContentLoaded')));
42 + return {
43 + product:page.locator('#test-product').locator('xpath=..').locator('.finora-combobox-input'),
44 + person:page.locator('#invoice-contact-id').locator('xpath=..').locator('.finora-combobox-input')
45 + };
46 +}
47 +
48 +test('searchable products filter Persian variants; arrows select highlighted entry with Enter, not first',async({page})=>{
49 + const {product,person}=await fixture(page);
50 + await product.click();
51 + await product.fill('بلوك');
52 + const list=page.locator('body > .finora-combobox-list');
53 + await expect(list).toBeVisible();
54 + await expect(list.locator('[role="option"]')).toHaveCount(2);
55 + await expect(list).not.toContainText('محرمانه');
56 + await expect(product).toHaveAttribute('aria-expanded','true');
57 + await product.press('ArrowDown');
58 + await expect(list.locator('[aria-selected="true"]')).toContainText('بلوک سبک');
59 + await product.press('Enter');
60 + await expect(page.locator('#test-product')).toHaveValue('BL2');
61 + await expect(product).toHaveAttribute('aria-expanded','false');
62 + expect(await page.evaluate(()=>window.__saves)).toBe(0);
63 + await person.click();
64 + await person.fill('شرکت شماره 0');
65 + await expect(page.locator('#invoice-contact-id').locator('xpath=..').locator('[role="option"]')).toHaveCount(10);
66 + await person.press('ArrowDown');
67 + await person.press('Enter');
68 + await expect(page.locator('#invoice-contact-id')).toHaveValue('C1');
69 + expect(await page.evaluate(()=>window.__saves)).toBe(0);
70 +});
71 +
72 +test('large dropdown wheel scroll, PageDown, Home/End and Escape preserve selection',async({page})=>{
73 + const {product}=await fixture(page);
74 + await product.click();await product.fill('کالا عمومی');
75 + const list=page.locator('body > .finora-combobox-list');
76 + await expect(list.locator('[role="option"]')).toHaveCount(48);
77 + await product.press('PageDown');
78 + await expect(list.locator('[aria-selected="true"]')).not.toContainText('کالا عمومی 00');
79 + await product.press('End');
80 + await expect(list.locator('[aria-selected="true"]')).toContainText('کالا عمومی 47');
81 + await product.press('Home');
82 + await expect(list.locator('[aria-selected="true"]')).toContainText('کالا عمومی 00');
83 + await list.hover({position:{x:12,y:38}});
84 + await page.mouse.wheel(0,475);
85 + await expect.poll(()=>list.evaluate(e=>e.scrollTop)).toBeGreaterThan(0);
86 + const selected=await list.locator('[aria-selected="true"]').getAttribute('data-value');
87 + expect(selected).not.toBe('P0');
88 + await product.press('Enter');
89 + await expect(page.locator('#test-product')).toHaveValue(selected);
90 + await product.click();await product.fill('مورد بی‌ربط');
91 + await expect(list.locator('.finora-combobox-empty')).toContainText('موردی پیدا نشد');
92 + await product.press('Enter');
93 + await expect(page.locator('#test-product')).toHaveValue(selected);
94 + await product.press('Escape');
95 + await expect(product).toHaveAttribute('aria-expanded','false');
96 + await expect(page.locator('#test-product')).toHaveValue(selected);
97 +});
98 +
99 +test('F2 explicitly saves valid active form but rejects missing rows, unsupported modal and no active entry',async({page})=>{
100 + const {product}=await fixture(page);
101 + await page.keyboard.press('F2');
102 + expect(await page.evaluate(()=>window.__saves)).toBe(0);
103 + await expect.poll(()=>page.evaluate(()=>window.__alerts.at(-1))).toContain('حداقل یک کالا');
104 + await product.click();await product.fill('بلوک');await product.press('ArrowDown');await product.press('Enter');
105 + await page.locator('.row-quantity').fill('2');
106 + await page.keyboard.press('F2');
107 + expect(await page.evaluate(()=>window.__saves)).toBe(1);
108 + expect(await page.evaluate(()=>window.__posted)).toBe(0);
109 + await page.evaluate(()=>{
110 + const modal=document.createElement('div');modal.id='qa-modal';modal.className='modal-backdrop active';modal.textContent='تأیید اختصاصی';document.body.appendChild(modal);
111 + });
112 + await page.keyboard.press('F2');
113 + expect(await page.evaluate(()=>window.__saves)).toBe(1);
114 + await expect.poll(()=>page.evaluate(()=>window.__alerts.at(-1))).toContain('این پنجره');
115 + await page.evaluate(()=>{document.querySelector('#qa-modal').remove();document.querySelector('#view-invoices').classList.remove('active');document.querySelector('#view-products').classList.add('active')});
116 + await page.keyboard.press('F2');
117 + expect(await page.evaluate(()=>window.__saves)).toBe(1);
118 + await expect.poll(()=>page.evaluate(()=>window.__alerts.at(-1))).toContain('عنوان کالا');
119 + await page.locator('#prod-name-input').fill('قطعه جدید');
120 + await page.keyboard.press('F2');
121 + expect(await page.evaluate(()=>window.__saves)).toBe(2);
122 + await page.keyboard.press('Control+Enter');
123 + expect(await page.evaluate(()=>window.__saves)).toBe(3);
124 + await page.evaluate(()=>document.querySelector('#view-products').classList.remove('active'));
125 + await page.keyboard.press('F2');
126 + expect(await page.evaluate(()=>window.__saves)).toBe(3);
127 + await expect.poll(()=>page.evaluate(()=>window.__alerts.at(-1))).toContain('فرم فعالی');
128 +});