Files
Investidor-V2/tools/portal-simulator-loading-visual-qa.cjs
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

113 lines
3.7 KiB
JavaScript

const {
start,
DIR,
path,
assert,
sanitized,
} = require('./portal-visual-qa-lib.cjs');
void (async () => {
const q = await start('simulator-loading-chromium-20261010');
let page, ctx, release;
try {
({ page, ctx } = await q.context('investor18', 390));
await q.login(page, 'investor18');
const e = require(path.join(DIR, 'investor-ab-chromium-20261010.json'))
.scenarios.B;
const gate = new Promise((resolve) => {
release = resolve;
});
let reached;
const incoming = new Promise((resolve) => {
reached = resolve;
});
await q.open(page, '/investimentos/' + e.id);
await page.route(
(url) => url.pathname === '/api/v1/simulation-drafts/current',
async (route) => {
q.proof.requested_context = new URL(
route.request().url(),
).searchParams.get('context');
reached();
await gate;
await route.continue();
},
);
await page
.getByRole('link', { name: 'Plano e simulador', exact: true })
.click();
await Promise.race([
incoming,
new Promise((_, reject) =>
setTimeout(
() =>
reject(
Error('Draft recovery request was not intercepted'),
),
20000,
),
),
]);
assert.equal(q.proof.requested_context, e.id);
await page
.getByText('A recuperar o rascunho. Aguarde para editar.', {
exact: true,
})
.waitFor();
const nav = page.getByRole('navigation', {
name: 'Etapas do formulário',
});
assert(
await nav
.getByRole('button', { name: /Estrutura financeira/ })
.isDisabled(),
);
assert(await page.getByRole('combobox').first().isDisabled());
q.proof.checks.controls_disabled_until_recovery = true;
release();
await page
.getByText('Dossier privado recuperado da sua conta.', {
exact: true,
})
.waitFor();
assert(
!(await nav
.getByRole('button', { name: /Estrutura financeira/ })
.isDisabled()),
);
await nav.getByRole('button', { name: /Projecto ou negócio/ }).click();
assert.equal(
await page
.getByLabel('Título do projecto', { exact: true })
.inputValue(),
'Plano financeiro B QA',
);
await nav.getByRole('button', { name: /Estrutura financeira/ }).click();
await page
.getByRole('region', {
name: 'Ferramentas de planeamento financeiro',
})
.waitFor();
q.proof.checks.restored_values_usable_after_delay = true;
await q.shot(page, 'loaded-mobile-tool');
await q.logout(page);
await ctx.close();
q.proof.result = 'passed';
} catch (e) {
if (release) release();
q.proof.result = 'failed';
q.proof.error = sanitized(e);
} finally {
q.proof.finished_at = new Date().toISOString();
q.save();
await q.browser.close();
console.log(
JSON.stringify({
result: q.proof.result,
checks: q.proof.checks,
receipt: q.receipt,
}),
);
if (q.proof.result !== 'passed') process.exitCode = 1;
}
})();