fix: expose document association changes in preparation impact

This commit is contained in:
2026-10-29 22:58:30 +02:00
parent 181a9883b3
commit a10dd83d8d
5 changed files with 174 additions and 18 deletions
@@ -396,6 +396,79 @@ function preparationFixture() {
],
};
}
void test('impact exposes document replacement even when its state and filename stay unchanged', () => {
const Impact = load(
'../../resources/js/components/private-investment-preparation.tsx',
preparationMocks,
'PreparationImpact',
);
const before = preparationFixture();
before.requirements = [before.requirements[1]];
before.requirements[0].document = { file_name: 'ORIGINAL.pdf' };
const after = structuredClone(before);
after.requirements[0].document_id = 'replacement-document';
const original = JSON.stringify({ before, after });
const html = renderToStaticMarkup(
React.createElement(Impact, { before, after }),
);
const impactList = html.slice(html.indexOf('<ul'), html.indexOf('</ul>'));
assert.match(impactList, /ASSOCIATED/);
assert.match(
impactList,
/Substituição de documento: ORIGINAL.pdf → ORIGINAL.pdf/,
);
assert.doesNotMatch(impactList, /Vínculo documental preservado/);
assert.doesNotMatch(html, /Sem alterações às exigências/);
assert.equal(JSON.stringify({ before, after }), original);
});
void test('impact distinguishes detachment, unavailable names, preserved history and unchanged associations', () => {
const Impact = load(
'../../resources/js/components/private-investment-preparation.tsx',
preparationMocks,
'PreparationImpact',
);
const before = preparationFixture();
before.requirements = [before.requirements[1]];
before.requirements[0].document = { file_name: 'ORIGINAL.pdf' };
const render = (after) =>
renderToStaticMarkup(React.createElement(Impact, { before, after }));
const detached = structuredClone(before);
detached.requirements[0] = {
...detached.requirements[0],
document_id: null,
document: null,
state: 'missing',
};
assert.match(
render(detached),
/Documento: ORIGINAL.pdf → Sem documento associado/,
);
const replaced = structuredClone(before);
replaced.requirements[0] = {
...replaced.requirements[0],
document_id: 'new',
document: null,
};
assert.match(
render(replaced),
/Substituição de documento: ORIGINAL.pdf → Documento associado — nome indisponível/,
);
const historical = structuredClone(before);
historical.requirements[0].state = 'not_applicable';
const historicalList = render(historical).split('</ul>')[0];
assert.match(historicalList, /Vínculo documental preservado/);
assert.doesNotMatch(historicalList, /Substituição de documento/);
assert.match(
render(structuredClone(before)),
/Sem alterações às exigências ou associações documentais/,
);
const associated = structuredClone(detached);
const added = renderToStaticMarkup(
React.createElement(Impact, { before: associated, after: before }),
);
assert.match(added, /Documento: Sem documento associado → ORIGINAL.pdf/);
assert.equal(before.requirements[0].document_id, 'saved-document');
});
const preparationMocks = {
'@inertiajs/react': {
Link: ({ href, children }) =>