@@ -0,0 +1,54 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import {
|
||||
chargeDrafts,
|
||||
LegalChargeSummary,
|
||||
} from '@/components/import-legal-charges';
|
||||
import {
|
||||
specificRateLabel,
|
||||
specificRateMinor,
|
||||
specificRateMoney,
|
||||
} from '@/lib/import-legal-specific-rate';
|
||||
|
||||
test.each([
|
||||
['1.25', 125],
|
||||
['1,25', 125],
|
||||
['0.0099', '0.99'],
|
||||
['0.0133', '1.33'],
|
||||
['0.00000001', '0.000001'],
|
||||
['000.00990000', '0.99'],
|
||||
['0', 0],
|
||||
] as const)(
|
||||
'preserves exact documentary coefficient %s in minor units',
|
||||
(input, minor) => {
|
||||
expect(specificRateMinor(input)).toBe(minor);
|
||||
expect(specificRateMinor(specificRateMoney(minor))).toBe(minor);
|
||||
},
|
||||
);
|
||||
|
||||
test.each(['', '-1', '1e2', '0.000000001', '10000000000000', '1.2.3', 'NaN'])(
|
||||
'invalid MZN coefficient cannot be reinterpreted as a valid cent coefficient: %s',
|
||||
(input) => expect(specificRateMinor(input)).toBeNull(),
|
||||
);
|
||||
|
||||
test('fractional cent coefficients survive revision and remain visible without monetary rounding', () => {
|
||||
const charge = {
|
||||
key: 'synthetic-specific',
|
||||
kind: 'ice',
|
||||
label: 'Coeficiente documental sintético',
|
||||
method: 'specific',
|
||||
rate_percent: null,
|
||||
specific_minor: '0.99',
|
||||
quantity_unit: 'g',
|
||||
basis_reference: 'Fonte sintética, sem activação fiscal',
|
||||
};
|
||||
expect(chargeDrafts([charge])[0].specific_amount).toBe('0.0099');
|
||||
expect(specificRateLabel('0.99')).toBe('0,0099 MZN');
|
||||
const html = renderToStaticMarkup(
|
||||
<LegalChargeSummary charges={[charge]} />,
|
||||
);
|
||||
expect(html).toContain('0,0099 MZN');
|
||||
expect(html).not.toContain('0,00 MZN');
|
||||
expect(specificRateMoney(125)).toBe('1.25');
|
||||
expect(specificRateMoney(null)).toBe('');
|
||||
});
|
||||
Reference in New Issue
Block a user