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

test(native): verify fractional quantity events and reject over-precision without silent truncation

davoodmehraban89 committed Oct 31, 2026 at 18:24 UTC a252bc5692d4a22275ed8f11f07e1a1ed26074db
3 files changed +27 -1
src/utils/NumberInput.js
+2 -1
@@ -47,7 +47,8 @@ export const NumberInput = {
47 const numeric = positive.replace(/[^\d.]/g, '');
48 const point = numeric.indexOf('.');
49 let integer = (point >= 0 ? numeric.slice(0, point) : numeric).replace(/^0+(?=\d)/, '');
50 - const fraction = point >= 0 ? numeric.slice(point + 1).replace(/\./g, '').slice(0, digits || 3) : '';
50 + // Never silently truncate over-precision: finance validation must reject it.
51 + const fraction = point >= 0 ? numeric.slice(point + 1).replace(/\./g, '') : '';
52 if (!integer && (point >= 0 || negative)) integer = '0';
53 const grouped = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
54 const decimal = point >= 0 ? '.' + fraction : '';
tests/number-input-fractions.test.mjs
+11
@@ -2,6 +2,7 @@ import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { readFileSync } from 'node:fs';
4 import { NumberInput } from '../src/utils/NumberInput.js';
5 +import { qtyUnits } from '../src/core/RetailFinanceCore.mjs';
6
7 function field(value, { decimals, type = 'text', inputmode = 'numeric', step } = {}) {
8 const attrs = new Map([['inputmode', inputmode]]);
@@ -99,3 +100,13 @@ test('an explicit zero VAT rate remains zero when reopening an invoice', () => {
100 const form = readFileSync(new URL('../src/views/InvoiceFormView.js', import.meta.url), 'utf8');
101 assert.ok(form.includes('d.vatRate ?? 10, 2'), 'zero tax must not be replaced with ten percent');
102 });
103 +
104 +
105 +test('over-precision is never silently truncated before the ledger validation', () => {
106 + const input = field('1.23456', { decimals: 3 });
107 + NumberInput._formatLive(input);
108 + assert.equal(input.value, '1.23456');
109 + assert.equal(NumberInput.parse(input), 1.23456);
110 + assert.throws(() => qtyUnits(NumberInput.parse(input)), /مقدار کالا نامعتبر/);
111 + assert.equal(qtyUnits(1.234), 1234);
112 +});
tests/windows-vm-native-functional-matrix.cjs
+14
@@ -163,6 +163,20 @@ async function purchaseInvoice() {
163 const chosen = document.querySelector('.product-option[data-id="' + p.id + '"]');
164 check(chosen, 'product autocomplete selection failed');
165 chosen.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
166 + // Actual installed WebView2 input event, not merely a pure formatting unit test:
167 + // a quantity of 2.5 must not be converted to 25, and grouping must keep dot.
168 + const quantityField = document.querySelector('.row-qty');
169 + check(quantityField?.dataset.decimals === '3',
170 + 'Native invoice quantity field lacks the three-decimal precision contract');
171 + quantityField.value = '1234.5';
172 + quantityField.dispatchEvent(new Event('input', { bubbles: true }));
173 + check(quantityField.value === '1,234.5',
174 + 'Native formatter removed fractional dot or failed live grouping');
175 + quantityField.value = '2.5';
176 + quantityField.dispatchEvent(new Event('input', { bubbles: true }));
177 + check(quantityField.value === '2.5',
178 + 'Native input silently changed 2.5 to an incorrect financial quantity');
179 + // Restore the original synthetic invoice fixture before financial posting.
180 document.querySelector('.row-qty').value = '10';
181 window.InvoiceFormView._onFieldChange(0, 'qty', '10');
182 document.querySelector('.row-price').value = '100';