فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(A07): validate multipage Persian invoice PDF in installed Windows WebView2

Add true WebView2 CDP PDF engine regression using 110 synthetic rows from production RTL invoice renderer; require multi-page PDF and upload the result. All existing Windows NSIS upgrade, finance, backup/restore, native offline and real 60k IndexedDB benchmark checks still pass. Windows Native #38955075618 and PR Quality #38955075675 green. Physical printer/user dialog/manual visual QA remain open.

davoodmehraban89 committed Oct 16, 2026 at 23:05 UTC 3108ddd0a6e3f023222815024ef23796e13b0599
3 files changed +63
.github/workflows/windows-vm-native-lab.yml
+2
@@ -14,6 +14,7 @@ on:
14 - 'tests/windows-vm-native-origin.test.mjs'
15 - 'tests/windows-vm-native-functional-matrix.cjs'
16 - 'tests/windows-vm-encrypted-company-backup-browser.js'
17 + - 'tests/windows-vm-native-print-pdf-browser.js'
18 - 'tests/windows-vm-native-performance-browser.js'
19 - 'scripts/windows-vm-native-lab.ps1'
20 - 'scripts/windows-vm-set-candidate.cjs'
@@ -73,6 +74,7 @@ jobs:
74 path: |
75 ${{ runner.temp }}/factor-easypro-native-vm-lab/reports/*.json
76 ${{ runner.temp }}/factor-easypro-native-vm-lab/reports/*.png
77 + ${{ runner.temp }}/factor-easypro-native-vm-lab/reports/*.pdf
78 retention-days: 30
79 if-no-files-found: warn
80 - name: State acceptance boundary
tests/windows-vm-installed-tauri-cdp.cjs
+22
@@ -399,6 +399,28 @@ async function connect(url) {
399 measured.timingsMs.snapshotExport >= 0);
400 report.nativePerformance = measured;
401 }
402 + if (mode === 'fresh') {
403 + // LAST operation: real installed WebView2 PDF engine, using production
404 + // RTL formal-invoice renderer with 110 synthetic items only.
405 + const code = fs.readFileSync(
406 + path.join(__dirname, 'windows-vm-native-print-pdf-browser.js'), 'utf8');
407 + const template = await cdp.evaluate(code, 60000);
408 + assert.equal(template.itemRows, 110);
409 + const printed = await cdp.command('Page.printToPDF', {
410 + printBackground: true, preferCSSPageSize: true,
411 + displayHeaderFooter: false
412 + }, 90000);
413 + assert.ok(printed?.data, 'Installed WebView2 returned no PDF');
414 + const pdf = Buffer.from(printed.data, 'base64');
415 + assert.ok(pdf.length > 10000 && pdf.subarray(0, 5).toString('ascii') === '%PDF-',
416 + 'Invalid WebView2 PDF result');
417 + const pages = [...pdf.toString('latin1').matchAll(/\/Type\s*\/Page\b/g)].length;
418 + assert.ok(pages >= 2, 'Invoice PDF is not multipage: ' + pages);
419 + const filename = 'a07-native-rtl-multipage-invoice.pdf';
420 + fs.writeFileSync(path.join(path.dirname(reportPath), filename), pdf);
421 + report.nativePrint = { ...template, pages, pdfBytes: pdf.length,
422 + filename, physicalPrinter: 'not-tested' };
423 + }
424 report.status = 'PASSED';
425 console.log(JSON.stringify(report, null, 2));
426 } catch (err) {
tests/windows-vm-native-print-pdf-browser.js new
+39
@@ -0,0 +1,39 @@
1 +(async () => {
2 + const ok=(value,msg)=>{if(!value)throw Error(msg);};
3 + ok(!!globalThis.__TAURI_INTERNALS__?.invoke,'Not installed Windows Tauri WebView2');
4 + ok(window.InvoicePrint?._formalTemplate,'Production print template is unavailable');
5 + const original=(await FINORA.Storage.getAll('invoices')).find(x=>x.kind==='sale'&&x.financePosted&&x.items?.length);
6 + ok(original,'Posted native sales invoice fixture is missing');
7 + const count=110;
8 + const lines=Array.from({length:count},(_,i)=>({
9 + productName:'کالای آزمایشی '+(i+1),qty:1,price:1000,discount:0,unit:'عدد'
10 + }));
11 + const invoice={...original,items:lines,kind:'sale',isPreInvoice:false,
12 + subtotal:110000,totalDiscount:0,vatEnabled:false,vatAmount:0,
13 + grandTotal:110000,paidAmount:0,remaining:110000,paymentMethod:'credit'};
14 + InvoicePrint.settings.template='formal';
15 + InvoicePrint.settings.paperSize='A4';
16 + InvoicePrint.settings.orientation='portrait';
17 + InvoicePrint.settings.showBalance='none';
18 + const rendered=InvoicePrint._formalTemplate(invoice,
19 + {name:'شرکت ساختگی'}, {name:'مشتری ساختگی'},0);
20 + ok(rendered.includes('dir="rtl"')&&rendered.includes('<thead>')&&
21 + rendered.includes('کالای آزمایشی 110'),'RTL template rows/header missing');
22 + const style=document.createElement('style');
23 + style.textContent='@page{size:A4 portrait;margin:0 !important;}'
24 + +'*{box-sizing:border-box;}'
25 + +'html,body,table,td,th{direction:rtl;text-align:right;}'
26 + +'html,body{font-family:"Vazirmatn FD",Tahoma,sans-serif;background:white;color:black;}'
27 + +'body{margin:0;padding:0;}'
28 + +'thead{display:table-header-group;}'
29 + +'tfoot{display:table-footer-group;}'
30 + +'tr,td,th{break-inside:avoid;page-break-inside:avoid;}'
31 + +'.print-doc{direction:rtl !important;page-break-inside:auto;}'
32 + +' *{-webkit-print-color-adjust:exact !important;print-color-adjust:exact !important;}';
33 + document.head.appendChild(style);
34 + document.body.innerHTML=rendered;
35 + ok(document.querySelectorAll('.print-doc tbody tr').length>=110,
36 + 'Rendered native printable invoice lost rows');
37 + await document.fonts.ready;
38 + return {engine:'native-WebView2-printToPDF',rtl:true,paper:'A4',itemRows:110};
39 +})()
\ No newline at end of file