feat: prioritise missing preparation documents and retain associations

This commit is contained in:
2026-10-29 22:56:02 +02:00
parent d662e63469
commit 181a9883b3
5 changed files with 296 additions and 49 deletions
@@ -358,3 +358,147 @@ void test('investment stages expose readable next actions while internal codes a
assert.doesNotMatch(html, /<summary[^>]*>S01/);
assert.match(html, /Fonte e referência desta etapa/);
});
function preparationFixture() {
const requirement = (key, state, required = true) => ({
key,
label: key,
state,
required,
document_id: state === 'associated' ? 'saved-document' : null,
document: null,
reason: 'Synthetic QA',
source: { url: '/source', reference: 'Synthetic QA' },
});
return {
version: 'private-investment-preparation-2026-v1',
enabled: true,
mode: 'registration',
period_covered: true,
scope_covered: true,
missing_fields: [],
questions: [
{
key: 'investment_preparation',
label: 'Preparar?',
source: 'Synthetic QA',
},
],
next: 'Preparar documentos',
reason: [],
authority_source: { url: '/source' },
source: { url: '/source' },
requirements: [
requirement('MISSING', 'missing'),
requirement('ASSOCIATED', 'associated'),
requirement('UNDETERMINED', 'indeterminate', false),
requirement('HISTORICAL', 'not_applicable', false),
],
};
}
const preparationMocks = {
'@inertiajs/react': {
Link: ({ href, children }) =>
React.createElement('a', { href }, children),
},
'@/pages/investment/shared': { card: 'card', input: 'input' },
};
void test('preparation directs complete context to missing documents without treating association or uncertainty as approval', () => {
const Summary = load(
'../../resources/js/components/private-investment-preparation.tsx',
preparationMocks,
'PreparationSummary',
);
const data = preparationFixture();
const before = JSON.stringify(data);
const render = (overrides = {}) =>
renderToStaticMarkup(
React.createElement(Summary, {
data: { ...data, ...overrides },
caseId: 'synthetic',
}),
);
const visible = render().split('<details>')[0];
assert.match(visible, /Documentos por associar: 1/);
assert.match(visible, /Documentos associados: 1 — conteúdo por conferir/);
assert.match(visible, /Exigências documentais por determinar: 1/);
assert.match(visible, /#preparation-documents/);
assert.match(visible, /Associar documentos do dossier/);
for (const overrides of [
{ missing_fields: ['currency'] },
{ scope_covered: false },
{ period_covered: false },
{ enabled: false },
{
requirements: data.requirements.filter(
(r) => r.state !== 'missing',
),
},
]) {
assert.match(
render(overrides).split('<details>')[0],
/#preparation-questions/,
);
}
assert.equal(JSON.stringify(data), before);
});
void test('associated document controls remain editable in details and deliberate detachment survives rerender', () => {
const Editor = load(
'../../resources/js/components/private-investment-preparation.tsx',
preparationMocks,
'PreparationEditor',
);
const data = preparationFixture();
const links = {};
const props = {
data,
fields: { investment_preparation: 'yes' },
changes: {},
documents: [
{
document_id: 'saved-document',
file_name: 'ORIGINAL.pdf',
status: 'active',
},
],
links,
onChange() {},
onLink(key, value) {
links[key] = value;
},
disabled: false,
};
const tree = Editor(props);
const details = flat(tree).find(
(node) =>
node.type === 'details' &&
flat(node).some(
(child) =>
child.type === 'summary' &&
child.props.children ===
'Documentos já associados — consultar ou alterar',
),
);
assert.ok(details);
assert.ok(!details.props.open);
const existingSelect = flat(details).find((node) => node.type === 'select');
assert.equal(existingSelect.props.value, 'saved-document');
assert.equal(flat(tree).filter((node) => node.type === 'select').length, 2);
existingSelect.props.onChange({ target: { value: '' } });
assert.deepEqual(links, { ASSOCIATED: null });
const rerender = Editor(props);
assert.equal(
flat(rerender)
.filter((node) => node.type === 'select')
.every((node) => node.props.value === ''),
true,
);
assert.equal(data.requirements[1].document_id, 'saved-document');
const disabled = Editor({ ...props, disabled: true });
assert.equal(
flat(disabled)
.filter((node) => node.type === 'select')
.every((node) => node.props.disabled),
true,
);
});