سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 17:00 UTC
test: enforce Persian-only visible invoice digits in three print templates and preserve source IDs
davoodmehraban89 committed
Oct 11, 2026 at 16:34 UTC
f1150fccb14cdf80a336f9eb9dec68c31f2aa10d
1 file changed
+54
scripts/taxpayer-print.spec.js
+54
@@ -59,3 +59,57 @@ test('isolated print waits for the supplied image before opening print',async({p
59
release();
60
await expect.poll(()=>page.evaluate(()=>window.printCalls)).toBe(1);
61
});
62
+
63
+
64
+test('all visible invoice print digits are Persian across formal, informal and taxpayer templates without mutating data',async({page})=>{
65
+ await page.goto('http://127.0.0.1:4173/');
66
+ await page.waitForFunction(()=>typeof buildFormalPage==='function'&&typeof buildNonFormalPage==='function'&&typeof buildElectronicDocPage==='function'&&typeof stageInvoicePrint==='function');
67
+ const results=await page.evaluate(()=>{
68
+ window.__FINORA_PRINT_TEST_MODE=true;
69
+ const seller={name:'شرکت نمونه 12',phone:'09123456789',national_id:'0012345678',postal_code:'1234567890'};
70
+ const buyer={name:'خریدار نمونه 2',mobile:'٠٩١٢٣٤٥٦٧٨٩',economic_code:'123456789'};
71
+ const original={number:'PINV-31',date:'۱۴۰5/٠۷/19',id:'TAX12A340'};
72
+ const inv={...original,kind:'formal',items:[{prodName:'کالا 2',unit:'عدد',qty:2,price:12500,lineTotal:25000}],subtotal:25000,discount:0,vat:2500,vatRate:10,grandTotal:27500};
73
+ const row={rowNo:1,prodName:'کالا 2',unit:'عدد',qty:2,price:12500,lineSubtotal:25000,lineDiscount:0,lineVat:2500,lineNet:27500};
74
+ const option={pageNum:1,totalPages:1,isFirstPage:true,isLastPage:true,cumulativeSubtotal:25000,cumulativeDiscount:0,cumulativeVat:2500,cumulativeNet:27500};
75
+ const spec={paper:'A4',orientation:'landscape',widthMm:297,heightMm:210,marginMm:7};
76
+ const cases={
77
+ formal:buildFormalPage([row],seller,buyer,inv,option),
78
+ informal:buildNonFormalPage([row],seller,buyer,{...inv,kind:'non_formal'},option),
79
+ taxpayer:buildElectronicDocPage(inv,{uniqueNumber:original.id,issueDateTime:original.date+' 08:30:59',internalInvoiceNumber:original.number,items:[{internalId:'2030123',officialId:'2099901'}]},seller,buyer)
80
+ };
81
+ const visibleText=root=>{
82
+ const walker=(root.ownerDocument||document).createTreeWalker(root,NodeFilter.SHOW_TEXT);
83
+ let node,output='';
84
+ while((node=walker.nextNode()))if(node.parentElement&&!/^(SCRIPT|STYLE|NOSCRIPT)$/i.test(node.parentElement.tagName))output+=node.nodeValue;
85
+ return output;
86
+ };
87
+ const checks={};
88
+ for(const [kind,html] of Object.entries(cases)){
89
+ const frame=stageInvoicePrint(html,spec);
90
+ const root=frame.contentDocument.getElementById('finora-print-document');
91
+ const preview=document.getElementById('printable-invoice');
92
+ const text=visibleText(root),previewText=preview?visibleText(preview):text;
93
+ checks[kind]={asciiDigits:/[0-9٠-٩]/.test(text),previewAsciiDigits:/[0-9٠-٩]/.test(previewText),
94
+ persianNumber:text.includes('PINV-۳۱'),persianDate:text.includes('۱۴۰۵/۰۷/۱۹'),
95
+ persianTotal:text.includes('۲۷٬۵۰۰')||text.includes('۲۷,۵۰۰'),
96
+ restoredSource:inv.number==='PINV-31'&&inv.date==='۱۴۰5/٠۷/19'&&inv.grandTotal===27500};
97
+ }
98
+ const sample='<div data-code="TAX12A340" title="1405"><span>شماره TAX12A340، تاریخ ۱۴۰5/٠۷/19</span></div>';
99
+ const localized=localizePrintHtmlDigits(sample);
100
+ const sampleTemplate=document.createElement('template');sampleTemplate.innerHTML=localized;
101
+ const el=sampleTemplate.content.querySelector('div');
102
+ checks.attributes={title:el.getAttribute('title'),id:el.getAttribute('data-code'),text:el.textContent};
103
+ return checks;
104
+ });
105
+ for(const [key,v] of Object.entries(results)){
106
+ if(key==='attributes')continue;
107
+ expect(v.asciiDigits,key+' ascii digits').toBe(false);
108
+ expect(v.previewAsciiDigits,key+' preview ascii digits').toBe(false);
109
+ expect(v.persianNumber,key+' invoice number').toBe(true);
110
+ expect(v.persianDate,key+' invoice date').toBe(true);
111
+ expect(v.persianTotal,key+' total').toBe(true);
112
+ expect(v.restoredSource,key+' source unchanged').toBe(true);
113
+ }
114
+ expect(results.attributes).toEqual({title:'1405',id:'TAX12A340',text:'شماره TAX۱۲A۳۴۰، تاریخ ۱۴۰۵/۰۷/۱۹'});
115
+});