@@ -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('');
|
||||
});
|
||||
@@ -1,7 +1,8 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { App, router } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import { afterEach, expect, test, vi } from 'vitest';
|
||||
import Legal from '../../resources/js/pages/supply/import-legal';
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
function renderLegal(
|
||||
canManage: boolean,
|
||||
@@ -108,12 +109,49 @@ test('official reference preparation is explicit and only available to the custo
|
||||
expect(allowed).toContain('3506.91.20');
|
||||
expect(allowed).toContain('taxa geral 20%');
|
||||
expect(allowed).toContain('não é uma pauta consolidada');
|
||||
expect(allowed).toContain('não substituir');
|
||||
expect(allowed).toContain('Ainda não existem regras neste âmbito.');
|
||||
expect(allowed).not.toContain('Ainda não existem fontes neste âmbito.');
|
||||
const reader = renderLegal(false, false, false, true);
|
||||
expect(reader).not.toContain('Preparar a partir do exemplar oficial');
|
||||
expect(reader).not.toContain('Silicone para selagem');
|
||||
});
|
||||
|
||||
test('remembered legal preparation is preserved and disables replacement by official reference drafts', () => {
|
||||
vi.spyOn(router, 'restore').mockImplementation((key) =>
|
||||
key === 'legal-rule:1:1:1:data'
|
||||
? {
|
||||
operation_key: 'c1111111-1111-4111-8111-111111111111',
|
||||
record_key: null,
|
||||
version: 0,
|
||||
action: 'save',
|
||||
title: 'PRESERVED-DELIBERATE-TITLE',
|
||||
official_reference: '',
|
||||
official_url: '',
|
||||
citation: '',
|
||||
valid_from: '',
|
||||
valid_until: '',
|
||||
match_code: '',
|
||||
suggested_code: '',
|
||||
origin_country: '',
|
||||
sector: '',
|
||||
obligations: '',
|
||||
document_types: [],
|
||||
reason: '',
|
||||
file: null,
|
||||
source_id: '',
|
||||
charges: [],
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
const post = vi.spyOn(router, 'post');
|
||||
const html = renderLegal(true, false, false, true);
|
||||
expect(html).toContain('PRESERVED-DELIBERATE-TITLE');
|
||||
expect(html).toContain('O preenchimento existente será conservado');
|
||||
expect(html).toContain('Limpar preparação');
|
||||
expect(html).toMatch(/<select[^>]*disabled[^>]*>/);
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('legal consultation escapes titles preserves periods and offers verified-source downloads without management controls', () => {
|
||||
const html = renderLegal(false);
|
||||
expect(html).toContain('<script>synthetic rule</script>');
|
||||
|
||||
Reference in New Issue
Block a user