@@ -0,0 +1,89 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import CapitalRegister from '../../resources/js/pages/equipment/capital-register';
|
||||
import CapitalAssignments from '../../resources/js/pages/requisitions/capital-assignments';
|
||||
import CapitalAssignmentSummary from '../../resources/js/components/capital-assignment-summary';
|
||||
|
||||
const source = {
|
||||
id: 2,
|
||||
version: 3,
|
||||
record_key: 'source',
|
||||
state: 'archived',
|
||||
reason: 'Synthetic archive reason',
|
||||
data: {
|
||||
type: 'project',
|
||||
code: 'PRJ-QA',
|
||||
name: '<script>QA</script>',
|
||||
reference: 'Frozen documentary reference',
|
||||
department_id: 1,
|
||||
equipment_id: null,
|
||||
},
|
||||
};
|
||||
const page = <T,>(data: T[]) => ({
|
||||
data,
|
||||
prev_page_url: null,
|
||||
next_page_url: null,
|
||||
});
|
||||
const assignment = {
|
||||
id: 5,
|
||||
version: 1,
|
||||
state: 'linked',
|
||||
reason: 'Synthetic deliberate assignment',
|
||||
data: { requisition_item_id: 1 },
|
||||
snapshot: { item: { description: 'Synthetic item' }, source },
|
||||
};
|
||||
function render(
|
||||
component: typeof CapitalRegister | typeof CapitalAssignments,
|
||||
props: object,
|
||||
) {
|
||||
return renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={component}
|
||||
initialPage={{
|
||||
component: 'qa',
|
||||
url: '/qa',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: { errors: {}, ...props },
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
test('read-only capital register preserves archived identity and history without management forms', () => {
|
||||
const html = render(CapitalRegister, {
|
||||
records: page([source]),
|
||||
history: page([source]),
|
||||
departments: [],
|
||||
equipment: [],
|
||||
canManage: false,
|
||||
actorId: 1,
|
||||
tenantId: 1,
|
||||
});
|
||||
expect(html).toContain('Arquivado');
|
||||
expect(html).toContain('Histórico do registo');
|
||||
expect(html).toContain('<script>QA</script>');
|
||||
expect(html).not.toContain('<form');
|
||||
});
|
||||
test('approved requisitions display the preserved source independently of available new choices', () => {
|
||||
const html = render(CapitalAssignments, {
|
||||
requisition: { id: 1, number: 'REQ-QA', status: 'approved' },
|
||||
items: [],
|
||||
current: [assignment],
|
||||
choices: page([]),
|
||||
history: page([assignment]),
|
||||
canWrite: false,
|
||||
actorId: 1,
|
||||
tenantId: 1,
|
||||
});
|
||||
expect(html).toContain('PRJ-QA');
|
||||
expect(html).toContain('versão 3');
|
||||
expect(html).not.toContain('<form');
|
||||
const frozen = renderToStaticMarkup(
|
||||
<CapitalAssignmentSummary records={{ 1: assignment }} />,
|
||||
);
|
||||
expect(frozen).toContain('Frozen documentary reference');
|
||||
expect(frozen).toContain('<script>QA</script>');
|
||||
expect(renderToStaticMarkup(<CapitalAssignmentSummary />)).toBe('');
|
||||
});
|
||||
@@ -0,0 +1,143 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import BankSupport from '@/pages/supply/import-bank-support';
|
||||
|
||||
function renderBankSupport(canWrite: boolean, dated = false) {
|
||||
const record = {
|
||||
id: 2,
|
||||
record_key: 'synthetic-bank-key',
|
||||
version: 1,
|
||||
state: dated ? 'documented' : 'ready',
|
||||
reason: 'Synthetic bank evidence',
|
||||
data: {
|
||||
commitment_document_id: 1,
|
||||
declaration_document_id: 3,
|
||||
support_document_ids: [4, 5],
|
||||
submission_document_id: dated ? 6 : null,
|
||||
submission_basis: dated
|
||||
? 'Explicit synthetic delivery evidence'
|
||||
: null,
|
||||
submitted_on: dated ? '2026-11-26' : null,
|
||||
requirements_known: true,
|
||||
required_support_types: ['commercial_invoice'],
|
||||
required_support_counts: { commercial_invoice: 2 },
|
||||
requirements_basis: 'Explicit synthetic bank request',
|
||||
due_on: dated ? '2026-11-27' : null,
|
||||
deadline_basis: dated
|
||||
? 'Explicit synthetic bank request deadline'
|
||||
: null,
|
||||
},
|
||||
snapshot: {
|
||||
documents: [
|
||||
{
|
||||
id: 1,
|
||||
version: 1,
|
||||
type: 'bank_commitment',
|
||||
reference: '<script>private term</script>',
|
||||
issuer_reference: 'Synthetic bank',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
version: 1,
|
||||
type: 'customs_declaration',
|
||||
reference: 'DU-QA',
|
||||
issuer_reference: 'Synthetic issuer',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
version: 1,
|
||||
type: 'commercial_invoice',
|
||||
reference: 'INVOICE-QA-1',
|
||||
issuer_reference: 'Synthetic supplier',
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
version: 1,
|
||||
type: 'commercial_invoice',
|
||||
reference: 'INVOICE-QA-2',
|
||||
issuer_reference: 'Synthetic supplier',
|
||||
},
|
||||
...(dated
|
||||
? [
|
||||
{
|
||||
id: 6,
|
||||
version: 1,
|
||||
type: 'bank_support',
|
||||
reference: 'DELIVERY-QA',
|
||||
issuer_reference: 'Synthetic bank',
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
issues: dated
|
||||
? []
|
||||
: [
|
||||
'Falta o comprovativo de entrega ao banco.',
|
||||
'Prazo documental ainda por indicar.',
|
||||
],
|
||||
};
|
||||
const page = { data: [record], prev_page_url: null, next_page_url: null };
|
||||
return renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={BankSupport}
|
||||
initialPage={{
|
||||
component: 'supply/import-bank-support',
|
||||
url: '/qa',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
importRecord: {
|
||||
id: 1,
|
||||
record_key: 'synthetic-import-key',
|
||||
version: 1,
|
||||
},
|
||||
order: { id: 1, number: 'QA' },
|
||||
current: page,
|
||||
history: page,
|
||||
documents: {
|
||||
data: [],
|
||||
prev_page_url: null,
|
||||
next_page_url: '/qa?bank_documents_page=2',
|
||||
},
|
||||
types: {
|
||||
bank_commitment: 'Termo de compromisso',
|
||||
commercial_invoice: 'Factura comercial',
|
||||
bank_support: 'Suporte bancário',
|
||||
},
|
||||
canWrite,
|
||||
actorId: 3,
|
||||
tenantId: 2,
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
test('bank consultation and report links preserve unknown deadlines requested counts and the delivery distinction', () => {
|
||||
const html = renderBankSupport(false);
|
||||
expect(html).toContain('Documentos reunidos; entrega por documentar');
|
||||
expect(html).toContain('Factura comercial: 2');
|
||||
expect(html).toContain('Prazo: Por indicar');
|
||||
expect(html).toContain('suporte-bancario.csv');
|
||||
expect(html).toContain('<script>private term</script>');
|
||||
expect(html).not.toContain('<form');
|
||||
});
|
||||
|
||||
test('bank date presentation follows the shared local format and preserves the actual documentary delivery date', () => {
|
||||
const html = renderBankSupport(false, true);
|
||||
expect(html).toContain('Prazo: 27/11/2026');
|
||||
expect(html).toContain('Entrega documentada: 26/11/2026');
|
||||
expect(html).toContain('Comprovativo de entrega associado');
|
||||
expect(html).not.toContain('entrega por documentar');
|
||||
});
|
||||
|
||||
test('bank preparation reuses existing originals and does not apply a generic legal deadline', () => {
|
||||
const html = renderBankSupport(true);
|
||||
expect(html).toContain('Seleccione os originais já registados');
|
||||
expect(html).toContain('Fonte dos requisitos ou informação ainda em falta');
|
||||
expect(html).not.toContain('30 dias');
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import ImportEstimate from '@/pages/supply/import-estimate';
|
||||
|
||||
function renderPlan(linked = false) {
|
||||
const page = { data: [], prev_page_url: null, next_page_url: null };
|
||||
const source = {
|
||||
id: 4,
|
||||
version: 2,
|
||||
snapshot: {
|
||||
item: { description: 'Synthetic valued item' },
|
||||
legal_rule: {
|
||||
data: { official_reference: 'Preserved official source' },
|
||||
},
|
||||
result: {
|
||||
lines: [
|
||||
{
|
||||
key: 'duty-line',
|
||||
kind: 'duty',
|
||||
label: 'Synthetic documented duty',
|
||||
method: 'ad_valorem',
|
||||
amount_minor: 750,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
return renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={ImportEstimate}
|
||||
initialPage={{
|
||||
component: 'supply/import-estimate',
|
||||
url: '/qa',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
requisition: {
|
||||
id: 1,
|
||||
number: 'QA',
|
||||
status: 'draft',
|
||||
total_minor: 10000,
|
||||
},
|
||||
actorId: 2,
|
||||
tenantId: 3,
|
||||
canPrepare: true,
|
||||
nativeChanged: false,
|
||||
budgets: page,
|
||||
history: page,
|
||||
legalAmounts: [source],
|
||||
latest: linked
|
||||
? {
|
||||
id: 5,
|
||||
version: 1,
|
||||
state: 'prepared',
|
||||
reason: 'Synthetic scenario',
|
||||
data: {
|
||||
budget_id: 1,
|
||||
components: [
|
||||
{
|
||||
key: 'duty',
|
||||
kind: 'duty',
|
||||
status: 'known',
|
||||
basis: 'Preserved selected calculation',
|
||||
subtotal_minor: 750,
|
||||
tax_minor: 0,
|
||||
total_minor: 750,
|
||||
},
|
||||
],
|
||||
},
|
||||
snapshot: {
|
||||
plan: {
|
||||
complete: true,
|
||||
budget_amount_minor: 10750,
|
||||
known_total_minor: 10750,
|
||||
unknown: [],
|
||||
},
|
||||
legal_sources: {
|
||||
duty: {
|
||||
estimate_id: 4,
|
||||
estimate_version: 2,
|
||||
charge_key: 'duty-line',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
: null,
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
test('native import preparation offers legal source reuse and additional parcels without silently selecting a value', () => {
|
||||
const html = renderPlan();
|
||||
expect(html).toContain('Reutilizar uma imposição calculada');
|
||||
expect(html).toContain('Synthetic valued item');
|
||||
expect(html).toContain('7.50 MZN');
|
||||
expect(html).toContain('Acrescentar parcela desta família');
|
||||
expect(html).not.toContain('O total conserva a fonte seleccionada');
|
||||
});
|
||||
|
||||
test('a preserved legal amount retains explicit budget tax treatment and a deliberate manual-detach action', () => {
|
||||
const html = renderPlan(true);
|
||||
expect(html).toContain('O total conserva a fonte seleccionada');
|
||||
expect(html).toContain('divisão entre base e imposto');
|
||||
expect(html).toContain('retirar ligação e conservar os valores');
|
||||
expect(html.match(/<option[^>]*value="4:duty-line"[^>]*>/)?.[0]).toContain(
|
||||
'selected=""',
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,116 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import Legal from '../../resources/js/pages/supply/import-legal';
|
||||
|
||||
function renderLegal(canManage: boolean, withRule = true, withCharges = 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: {},
|
||||
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('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');
|
||||
});
|
||||
@@ -0,0 +1,88 @@
|
||||
import { App } from '@inertiajs/react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { expect, test } from 'vitest';
|
||||
import Readiness from '../../resources/js/pages/supply/import-readiness';
|
||||
import ImportTariffSummary from '../../resources/js/components/import-tariff-summary';
|
||||
|
||||
test('import follow-up preserves incomplete checks actionable links and unknown dates without rendering financial operations', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<App
|
||||
initialComponent={Readiness}
|
||||
initialPage={{
|
||||
component: 'supply/import-readiness',
|
||||
url: '/qa',
|
||||
version: null,
|
||||
clearHistory: false,
|
||||
encryptHistory: true,
|
||||
props: {
|
||||
errors: {},
|
||||
importRecord: { id: 1, version: 2, state: 'arrived' },
|
||||
order: { id: 1, number: 'QA' },
|
||||
expectedUsableOn: null,
|
||||
checkedAt: '2026-11-27',
|
||||
complete: false,
|
||||
alerts: [
|
||||
{
|
||||
key: 'missing',
|
||||
category: 'Documentos',
|
||||
text: '<script>Missing synthetic licence</script>',
|
||||
href: '/compras/importacoes/1/documentos',
|
||||
},
|
||||
],
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('Verificação incompleta');
|
||||
expect(html).toContain('Por indicar');
|
||||
expect(html).toContain(
|
||||
'<script>Missing synthetic licence</script>',
|
||||
);
|
||||
expect(html).toContain('/compras/importacoes/1/documentos');
|
||||
expect(html).not.toContain('<form');
|
||||
});
|
||||
|
||||
test('issued classification displays the frozen legal citation and obligations rather than the current catalogue', () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<ImportTariffSummary
|
||||
records={{
|
||||
1: {
|
||||
record_id: 1,
|
||||
version: 2,
|
||||
item: {
|
||||
description: 'Synthetic item',
|
||||
quantity: '1',
|
||||
unit: 'KG',
|
||||
},
|
||||
data: {
|
||||
proposed_code: '1234',
|
||||
confirmed_code: '1234',
|
||||
source_reference: 'Source',
|
||||
confirmation_source: 'Confirmed source',
|
||||
deviation: false,
|
||||
},
|
||||
confirmed_by: { name: 'Synthetic buyer' },
|
||||
reason: 'Synthetic decision',
|
||||
legal_rule: {
|
||||
version: 5,
|
||||
data: {
|
||||
official_reference: 'Preserved official edition',
|
||||
citation: 'Article QA',
|
||||
obligations: 'Preserved documentary conditions',
|
||||
document_types: ['licence'],
|
||||
},
|
||||
context: {
|
||||
date: '2026-11-27',
|
||||
origin_country: 'Synthetic A',
|
||||
sector: 'Synthetic sector',
|
||||
},
|
||||
},
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain('Preserved official edition');
|
||||
expect(html).toContain('Article QA');
|
||||
expect(html).toContain('versão 5');
|
||||
expect(html).toContain('Preserved documentary conditions');
|
||||
});
|
||||
Reference in New Issue
Block a user