94 lines
3.4 KiB
JavaScript
94 lines
3.4 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
investmentPreparationHref,
|
|
complementPreparationHref,
|
|
} from '../../resources/js/lib/search-territory.ts';
|
|
import { buildProjectDossierRows } from '../../resources/js/lib/project-dossier.ts';
|
|
|
|
void test('consulting a complementary opportunity preserves the origin selection and the chosen dossier', () => {
|
|
const dossier = '11111111-1111-4111-8111-111111111111';
|
|
const query = new URLSearchParams({
|
|
complement_origin: 'opportunity:10',
|
|
complement_code: 'cold',
|
|
complement_target: 'opportunity:20',
|
|
investment_dossier: dossier,
|
|
complement_territory: dossier,
|
|
});
|
|
const href = investmentPreparationHref(20, '/oportunidades/frio?' + query);
|
|
assert.ok(href.startsWith(`/investimentos/${dossier}/contexto/editar?`));
|
|
const params = new URL(href, 'https://local.invalid').searchParams;
|
|
assert.equal(params.get('complement_origin'), 'opportunity:10');
|
|
assert.equal(params.get('complement_target'), 'opportunity:20');
|
|
assert.equal(params.get('complement_territory'), dossier);
|
|
assert.equal(
|
|
complementPreparationHref(
|
|
'/parcerias/7?complement_origin=portfolio:a&complement_code=finance&complement_target=partnership:7',
|
|
'partnership:7',
|
|
),
|
|
'/investimentos/iniciar?complement_origin=portfolio%3Aa&complement_code=finance&complement_target=partnership%3A7',
|
|
);
|
|
assert.equal(
|
|
complementPreparationHref(
|
|
'/oportunidades/frio?' + query,
|
|
'opportunity:21',
|
|
),
|
|
null,
|
|
);
|
|
query.set('investment_dossier', 'https://external.invalid');
|
|
assert.ok(
|
|
investmentPreparationHref(
|
|
20,
|
|
'/oportunidades/frio?' + query,
|
|
).startsWith('/investimentos/iniciar?'),
|
|
);
|
|
});
|
|
|
|
void test('complement report rows retain principal, concrete target and the distinction from a need', () => {
|
|
const complements = [
|
|
{
|
|
title: 'Silos',
|
|
kind: 'opportunity',
|
|
origin: { title: 'Cereais' },
|
|
target: {
|
|
title: 'Armazenagem existente',
|
|
href: '/oportunidades/silos',
|
|
},
|
|
},
|
|
{
|
|
title: 'Fiação',
|
|
kind: 'need',
|
|
origin: { title: 'Corredor de origem' },
|
|
target: null,
|
|
},
|
|
{
|
|
title: 'Formação',
|
|
kind: 'service',
|
|
origin: { title: 'Cereais' },
|
|
target: { title: 'Serviço existente', href: '/parcerias/7' },
|
|
},
|
|
];
|
|
const draft = {
|
|
project_title: 'Título deliberado',
|
|
context_applicability_snapshot: JSON.stringify({
|
|
version: 1,
|
|
complements,
|
|
}),
|
|
};
|
|
const before = JSON.stringify(draft);
|
|
const rows = buildProjectDossierRows(draft);
|
|
const chosen = rows.filter((row) => row[1] === 'Complemento escolhido');
|
|
assert.equal(chosen.length, 3);
|
|
assert.ok(chosen[0][3].includes('Cereais'));
|
|
assert.ok(chosen[1][3].includes('necessidade complementar em preparação'));
|
|
assert.ok(chosen[2][3].includes('serviço/instrumento'));
|
|
assert.ok(
|
|
rows.some(
|
|
(row) =>
|
|
row[1] === 'Ficha complementar' &&
|
|
row[3] === '/oportunidades/silos',
|
|
),
|
|
);
|
|
assert.equal(JSON.stringify(draft), before);
|
|
});
|