Files
Investidor-V2/tests/frontend/investment-step-help.test.mjs
T
2026-11-17 08:55:48 +02:00

89 lines
2.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import {
investmentStageHelp,
preparationHelp,
helpPreferenceKey,
readHelpPreference,
} from '../../resources/js/lib/investment-step-help.ts';
test('each of the 19 existing stages has specific orientation, an example and a purpose', () => {
const instructions = new Set();
for (let i = 1; i <= 19; i++) {
const code = `S${String(i).padStart(2, '0')}`;
const help = investmentStageHelp(code, `Título ${i}`);
assert.equal(help.code, code);
assert.equal(help.title, `Título ${i}`);
assert.ok(help.instruction.length > 30);
assert.ok(help.example.length > 25);
assert.ok(help.purpose.length > 25);
instructions.add(help.instruction);
}
assert.equal(instructions.size, 19);
assert.equal(
investmentStageHelp('future-stage', 'Nova etapa').title,
'Nova etapa',
);
});
test('preparation guidance preserves the review before confirmation sequence', () => {
assert.deepEqual(
preparationHelp.map((step) => step.code),
['help-choices', 'help-declarations', 'help-review'],
);
assert.match(preparationHelp[2].instruction, /Compare.*confirme/);
});
test('preferences default safely, survive malformed storage and remain separate per user and flow', () => {
assert.deepEqual(readHelpPreference(null), {
automatic: true,
seen: false,
});
assert.deepEqual(readHelpPreference('{bad'), {
automatic: true,
seen: false,
});
assert.deepEqual(readHelpPreference('{"automatic":false,"seen":true}'), {
automatic: false,
seen: true,
});
assert.deepEqual(readHelpPreference('{"automatic":true,"seen":true}'), {
automatic: true,
seen: true,
});
assert.notEqual(helpPreferenceKey(1, 'path'), helpPreferenceKey(2, 'path'));
assert.notEqual(
helpPreferenceKey(1, 'path'),
helpPreferenceKey(1, 'preparation'),
);
assert.notEqual(
helpPreferenceKey('a:b', 'c'),
helpPreferenceKey('a', 'b:c'),
);
});
test('dossier help follows only the steps already permitted by the adaptive path', () => {
const page = readFileSync(
new URL(
'../../resources/js/pages/investor-path/show.tsx',
import.meta.url,
),
'utf8',
);
assert.match(
page,
/steps=\{path\.steps\s*\.filter\(\(step\) => step\.preparation_allowed\)/,
);
assert.match(page, /<HelpAtStep code=\{step.code\}/);
const component = readFileSync(
new URL(
'../../resources/js/components/investment-step-help.tsx',
import.meta.url,
),
'utf8',
);
assert.doesNotMatch(component, /router\.|fetch\(|\.submit\(|\.post\(/);
assert.doesNotMatch(component, /location\.(assign|reload)|window\.history/);
});