92 lines
3.2 KiB
TypeScript
92 lines
3.2 KiB
TypeScript
import { App } from '@inertiajs/react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { expect, test } from 'vitest';
|
|
import ImportPartySelection, {
|
|
type ImportPartyWorkspace,
|
|
} from '@/components/import-party-selection';
|
|
|
|
function renderParties(canSelect: boolean) {
|
|
const selected = {
|
|
id: 1,
|
|
version: 2,
|
|
data: { role: 'broker', supplier_id: 3, instruction_document_id: 4 },
|
|
snapshot: {
|
|
supplier: {
|
|
name: '<script>Broker QA</script>',
|
|
nuit: '123456789',
|
|
version: 1,
|
|
},
|
|
instructions: { data: { reference: 'INSTRUCTIONS-QA' } },
|
|
},
|
|
reason: 'Explicit synthetic selection.',
|
|
issues: [
|
|
'As instruções escritas têm uma versão diferente; confira a selecção.',
|
|
],
|
|
};
|
|
const workspace: ImportPartyWorkspace = {
|
|
roles: { broker: 'Despachante aduaneiro', forwarder: 'Transitário' },
|
|
canSelect,
|
|
search: '',
|
|
current: [selected],
|
|
history: { data: [selected], prev_page_url: null, next_page_url: null },
|
|
suppliers: {
|
|
data: [{ id: 3, name: 'Broker QA', nuit: '123456789', version: 1 }],
|
|
prev_page_url: null,
|
|
next_page_url: null,
|
|
},
|
|
instructions: {
|
|
data: [
|
|
{
|
|
id: 4,
|
|
version: 1,
|
|
data: {
|
|
reference: 'INSTRUCTIONS-QA',
|
|
issuer_reference: 'QA buyer',
|
|
},
|
|
},
|
|
],
|
|
prev_page_url: null,
|
|
next_page_url: null,
|
|
},
|
|
};
|
|
return renderToStaticMarkup(
|
|
<App
|
|
initialComponent={ImportPartySelection}
|
|
initialPage={{
|
|
component: 'supply/import-dossier',
|
|
url: '/compras/importacoes/5/documentos',
|
|
version: null,
|
|
clearHistory: false,
|
|
encryptHistory: true,
|
|
props: {
|
|
errors: {},
|
|
workspace,
|
|
importId: 5,
|
|
importKey: 'synthetic-import',
|
|
actorId: 6,
|
|
tenantId: 7,
|
|
},
|
|
}}
|
|
/>,
|
|
);
|
|
}
|
|
|
|
test('party reader sees preserved selection instructions and pending issues without selection commands', () => {
|
|
const html = renderParties(false);
|
|
expect(html).toContain('INSTRUCTIONS-QA');
|
|
expect(html).toContain('uma versão diferente');
|
|
expect(html).toContain('/compras/importacoes/5/documentos/4');
|
|
expect(html).not.toContain('Confirmar entidade e instruções');
|
|
expect(html).toContain('<script>Broker QA</script>');
|
|
expect(html).not.toContain('<script>Broker QA');
|
|
});
|
|
|
|
test('buyer selects existing sources and must personally confirm the conflict declaration', () => {
|
|
const html = renderParties(true);
|
|
expect(html).toContain('Escolher entidade');
|
|
expect(html).toContain('Escolher instruções');
|
|
expect(html).toContain('Confirmo a ausência de conflito');
|
|
expect(html).not.toMatch(/<input[^>]+type="checkbox"[^>]*checked/);
|
|
expect(html).toContain('Rever a selecção actual');
|
|
});
|