144 lines
5.4 KiB
TypeScript
144 lines
5.4 KiB
TypeScript
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');
|
|
});
|