85 lines
2.9 KiB
JavaScript
85 lines
2.9 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { inheritCompatibleFields } from '../../resources/js/lib/context-inheritance.ts';
|
|
import {
|
|
buildProjectDossierRows,
|
|
exportProjectDossierCsv,
|
|
} from '../../resources/js/lib/project-dossier.ts';
|
|
import {
|
|
createProjectDossierReport,
|
|
createProjectDossierPrintHtml,
|
|
} from '../../resources/js/lib/project-dossier-report.ts';
|
|
|
|
void test('selected associations stay attached to each opportunity in reports and do not replace deliberate simulator answers', async () => {
|
|
const choices = [
|
|
{
|
|
opportunity: { key: 'opportunity:1', title: 'Oportunidade QA A' },
|
|
territory: { title: 'Sofala / Dondo' },
|
|
portfolio_origins: [
|
|
{ title: 'Âncora QA', id: 'p', sha256: 'internal-hash' },
|
|
],
|
|
},
|
|
{
|
|
opportunity: { key: 'opportunity:2', title: 'Oportunidade QA B' },
|
|
territory: { title: 'Manica' },
|
|
portfolio_origins: [{ title: 'Cluster QA', id: 'c' }],
|
|
},
|
|
];
|
|
const snapshot = JSON.stringify({
|
|
version: 1,
|
|
context_revision: 3,
|
|
opportunity_choices: choices,
|
|
land_preparation: { need: 'unknown' },
|
|
});
|
|
const values = {
|
|
project_title: 'Título deliberado',
|
|
province_id: 'local-edit',
|
|
context_applicability_snapshot: 'old',
|
|
};
|
|
const result = inheritCompatibleFields(
|
|
'dossier:A:simulator',
|
|
values,
|
|
{
|
|
project_title: 'Origem',
|
|
province_id: 'source',
|
|
context_applicability_snapshot: snapshot,
|
|
},
|
|
null,
|
|
);
|
|
assert.equal(result.patch.project_title, undefined);
|
|
assert.equal(result.patch.province_id, undefined);
|
|
assert.equal(result.patch.context_applicability_snapshot, snapshot);
|
|
const draft = { ...values, ...result.patch };
|
|
const before = JSON.stringify(draft);
|
|
const rows = buildProjectDossierRows(draft);
|
|
assert.ok(
|
|
rows.some(
|
|
(row) =>
|
|
row[1] === 'Associação escolhida na carteira' &&
|
|
row[2] === 'Âncora QA' &&
|
|
row[3].startsWith('Oportunidade QA A;'),
|
|
),
|
|
);
|
|
assert.ok(
|
|
rows.some(
|
|
(row) =>
|
|
row[1] === 'Associação escolhida na carteira' &&
|
|
row[2] === 'Cluster QA' &&
|
|
row[3].startsWith('Oportunidade QA B;'),
|
|
),
|
|
);
|
|
assert.match(exportProjectDossierCsv(draft), /Sofala \/ Dondo/);
|
|
const html = await createProjectDossierPrintHtml(
|
|
createProjectDossierReport(draft, {
|
|
selectedSections: new Set(['location']),
|
|
}),
|
|
[],
|
|
false,
|
|
);
|
|
assert.match(html, /Âncora QA/);
|
|
assert.match(html, /Cluster QA/);
|
|
assert.match(html, /Manica/);
|
|
assert.doesNotMatch(html, /internal-hash/);
|
|
assert.equal(JSON.stringify(draft), before);
|
|
});
|