191 lines
7.6 KiB
TypeScript
191 lines
7.6 KiB
TypeScript
import { App, router } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { afterEach, expect, test, vi } from 'vitest';
|
|
import Legal from '../../resources/js/pages/supply/import-legal';
|
|
afterEach(() => vi.restoreAllMocks());
|
|
|
|
function renderLegal(
|
|
canManage: boolean,
|
|
withRule = true,
|
|
withCharges = false,
|
|
withReference = false,
|
|
) {
|
|
const data = {
|
|
title: '<script>synthetic rule</script>',
|
|
official_reference: 'Synthetic official edition',
|
|
official_url: 'https://example.test/source.pdf',
|
|
citation: 'Article QA',
|
|
valid_from: '2026-01-01',
|
|
valid_until: null,
|
|
match_code: '1234',
|
|
suggested_code: '1234.56',
|
|
origin_country: null,
|
|
sector: null,
|
|
obligations: 'Synthetic conditions only',
|
|
document_types: ['licence'],
|
|
charges: withCharges
|
|
? [
|
|
{
|
|
key: 'synthetic-duty',
|
|
kind: 'duty',
|
|
label: 'Synthetic duty',
|
|
method: 'maximum',
|
|
rate_percent: '7.500000',
|
|
specific_minor: 125,
|
|
quantity_unit: 'KG',
|
|
basis_reference:
|
|
'Synthetic explicit valuation and quantity basis',
|
|
},
|
|
]
|
|
: [],
|
|
};
|
|
const rule = {
|
|
id: 1,
|
|
record_key: 'qa',
|
|
version: 2,
|
|
state: 'published',
|
|
data,
|
|
reason: 'Synthetic publication',
|
|
source_url: '/requisicoes/1/base-legal/fontes/1',
|
|
};
|
|
const page = {
|
|
data: withRule ? [rule] : [],
|
|
prev_page_url: null,
|
|
next_page_url: null,
|
|
};
|
|
return renderToStaticMarkup(
|
|
<App
|
|
initialComponent={Legal}
|
|
initialPage={{
|
|
component: 'supply/import-legal',
|
|
url: '/qa',
|
|
version: null,
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: {
|
|
errors: {},
|
|
referenceDrafts: withReference
|
|
? [
|
|
{
|
|
source_id: 8,
|
|
code: '3506.91.20',
|
|
description:
|
|
'Silicone para selagem de painéis solares',
|
|
rate_percent: '20',
|
|
title: 'Taxa geral documental',
|
|
official_reference: 'Lei 8/2025',
|
|
official_url: null,
|
|
citation: 'Página 2180-(4)',
|
|
valid_from: '2026-01-01',
|
|
obligations:
|
|
'Conferir o exemplar e o regime aplicável',
|
|
charges: [],
|
|
},
|
|
]
|
|
: [],
|
|
requisition: { id: 1, number: 'QA' },
|
|
rules: page,
|
|
history: page,
|
|
suggestions: withRule
|
|
? [{ id: 1, version: 2, data, source_sha256: 'qa' }]
|
|
: [],
|
|
items: [{ id: 1, description: 'Synthetic item' }],
|
|
classifications: [],
|
|
canManage,
|
|
canPropose: canManage,
|
|
actorId: 1,
|
|
tenantId: 1,
|
|
types: { licence: 'Licença ou autorização' },
|
|
filters: { code: '1234', date: '2026-11-27' },
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
}
|
|
|
|
test('official reference preparation is explicit and only available to the customs preparer', () => {
|
|
const allowed = renderLegal(true, false, false, true);
|
|
expect(allowed).toContain('Preparar a partir do exemplar oficial');
|
|
expect(allowed).toContain('3506.91.20');
|
|
expect(allowed).toContain('taxa geral 20%');
|
|
expect(allowed).toContain('não é uma pauta consolidada');
|
|
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>');
|
|
expect(html).toContain('01/01/2026');
|
|
expect(html).toContain('sem termo final indicado');
|
|
expect(html).toContain('/base-legal/fontes/1');
|
|
expect(html).not.toContain('Guardar preparação para validação aduaneira');
|
|
expect(html).not.toContain('Preparar proposta com esta fonte');
|
|
});
|
|
|
|
test('legal preparation makes documentary scope and human publication explicit', () => {
|
|
const html = renderLegal(true);
|
|
expect(html).toContain('Preparar proposta com esta fonte');
|
|
expect(html).toContain('Preparar nova versão');
|
|
expect(html).toContain('Guardar preparação para validação aduaneira');
|
|
expect(html).toContain('Exemplar oficial');
|
|
expect(html).toContain('Licença ou autorização');
|
|
});
|
|
|
|
test('no matching rule never becomes an assumed zero tax or exemption', () => {
|
|
const html = renderLegal(false, false);
|
|
expect(html).toContain('Sem regra publicada correspondente');
|
|
expect(html).toContain('Não foram presumidos código, taxa ou isenção');
|
|
});
|
|
|
|
test('documented charges expose their methods rates units and input provenance before estimating', () => {
|
|
const html = renderLegal(true, true, true);
|
|
expect(html).toContain(
|
|
'Maior valor entre percentagem e montante por unidade',
|
|
);
|
|
expect(html).toContain('7.500000%');
|
|
expect(html).toContain('Taxa específica:');
|
|
expect(html).toContain('Quantidade em KG');
|
|
expect(html).toContain('Origem do valor ou da quantidade');
|
|
expect(html).toContain('Calcular e preservar estimativa');
|
|
});
|