269 lines
10 KiB
JavaScript
269 lines
10 KiB
JavaScript
const {
|
|
chromium,
|
|
} = require('C:/Users/macbook/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
(async () => {
|
|
const b = await chromium.launch({
|
|
headless: true,
|
|
executablePath:
|
|
'C:/Users/macbook/AppData/Local/ms-playwright/chromium-1243/chrome-win64/chrome.exe',
|
|
});
|
|
const evidence = [];
|
|
try {
|
|
for (const width of [1440, 390]) {
|
|
const context = await b.newContext({
|
|
viewport: { width, height: 850 },
|
|
});
|
|
const p = await context.newPage();
|
|
const consoleErrors = [];
|
|
p.on('pageerror', (error) => consoleErrors.push(error.message));
|
|
const base = 'http://127.0.0.1:18092';
|
|
const http = [];
|
|
let submissions = 0;
|
|
let calculations = 0;
|
|
await p.route('**/*', (r) => {
|
|
const u = r.request().url();
|
|
if (!u.startsWith(base)) return r.abort();
|
|
if (
|
|
r.request().method() === 'POST' &&
|
|
u.includes('/balcao-virtual')
|
|
)
|
|
submissions++;
|
|
if (
|
|
r.request().method() === 'POST' &&
|
|
new URL(u).pathname === '/api/v1/simulations'
|
|
)
|
|
calculations++;
|
|
return r.continue();
|
|
});
|
|
p.on('response', (r) => {
|
|
if (
|
|
r.status() === 422 &&
|
|
r.url().includes('/simulation-drafts')
|
|
)
|
|
void r.json().then((body) =>
|
|
fs.writeFileSync(
|
|
'storage/app/private/investmoz-v2/draft-422-response.json',
|
|
JSON.stringify(
|
|
{
|
|
body,
|
|
payload: r.request().postDataJSON(),
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
),
|
|
);
|
|
if (r.url().includes('/api/'))
|
|
http.push({
|
|
path: new URL(r.url()).pathname,
|
|
status: r.status(),
|
|
method: r.request().method(),
|
|
});
|
|
});
|
|
await p.addInitScript(() => {
|
|
if (sessionStorage.getItem('investmoz-simulation-draft-v1'))
|
|
return;
|
|
sessionStorage.setItem(
|
|
'investmoz-simulation-draft-v1',
|
|
JSON.stringify({
|
|
journey_type: 'personal',
|
|
detail_level: 'simple',
|
|
purpose: 'simulate_only',
|
|
preferred_language: 'pt-MZ',
|
|
fiscal_period: '2026',
|
|
fiscal_periodicity: 'annual',
|
|
fiscal_component: 'customs_ice',
|
|
fiscal_customs_code: 'QA-NAO-CLASSIFICADO',
|
|
fiscal_operation: 'import',
|
|
fiscal_scenario_mode: 'custom_planning',
|
|
rate: '5',
|
|
reduction: '0',
|
|
}),
|
|
);
|
|
});
|
|
const response = await p.goto(base + '/simulador-fiscal');
|
|
assert.equal(
|
|
response.headers()['x-investmoz-qa-target'],
|
|
'investmoz_v2_20261008_test:55441',
|
|
);
|
|
await p
|
|
.getByRole('button', { name: '3. Revisão', exact: true })
|
|
.click();
|
|
await p
|
|
.getByRole('button', {
|
|
name: 'Validar este rascunho',
|
|
exact: true,
|
|
})
|
|
.click();
|
|
const summary = p.locator('#draft-validation-summary');
|
|
await summary.waitFor();
|
|
await p.waitForFunction(
|
|
() => document.activeElement?.id === 'draft-validation-summary',
|
|
);
|
|
assert.match(await summary.innerText(), /campos pendentes/);
|
|
assert.match(await summary.innerText(), /Não calcula valores/);
|
|
assert.equal(calculations, 0);
|
|
assert.equal(submissions, 0);
|
|
await p.waitForFunction(() => {
|
|
const rect = document
|
|
.getElementById('draft-validation-summary')
|
|
?.getBoundingClientRect();
|
|
return rect && rect.top >= -1 && rect.top < innerHeight;
|
|
});
|
|
assert.equal(
|
|
await summary.evaluate((e) => {
|
|
const r = e.getBoundingClientRect();
|
|
return r.top >= -1 && r.top < innerHeight;
|
|
}),
|
|
true,
|
|
);
|
|
await summary.getByRole('button').first().click();
|
|
await p
|
|
.getByLabel('Base hipotética para planeamento', {
|
|
exact: false,
|
|
})
|
|
.fill('1000');
|
|
await p
|
|
.getByRole('button', { name: '3. Revisão', exact: true })
|
|
.click();
|
|
await p
|
|
.getByRole('button', {
|
|
name: 'Validar este rascunho',
|
|
exact: true,
|
|
})
|
|
.dblclick();
|
|
await p.waitForFunction(
|
|
() => document.activeElement?.id === 'draft-validation-summary',
|
|
);
|
|
assert.match(
|
|
await summary.innerText(),
|
|
/Campos pendentes e inconsistências: 0/,
|
|
);
|
|
assert.equal(calculations, 0);
|
|
assert.equal(submissions, 0);
|
|
await p
|
|
.getByRole('button', {
|
|
name: '2. Operação fiscal',
|
|
exact: true,
|
|
})
|
|
.click();
|
|
assert.equal(
|
|
await p
|
|
.getByLabel('Base hipotética para planeamento', {
|
|
exact: false,
|
|
})
|
|
.inputValue(),
|
|
'1000',
|
|
);
|
|
await p.waitForFunction(
|
|
() =>
|
|
JSON.parse(
|
|
sessionStorage.getItem(
|
|
'investmoz-simulation-draft-v1',
|
|
) ?? '{}',
|
|
).base === '1000',
|
|
);
|
|
await p
|
|
.getByRole('button', {
|
|
name: 'Guardar e continuar mais tarde',
|
|
exact: true,
|
|
})
|
|
.click();
|
|
await p.reload();
|
|
await p
|
|
.getByRole('button', {
|
|
name: '2. Operação fiscal',
|
|
exact: true,
|
|
})
|
|
.click();
|
|
assert.equal(
|
|
await p
|
|
.getByLabel('Base hipotética para planeamento', {
|
|
exact: false,
|
|
})
|
|
.inputValue(),
|
|
'1000',
|
|
);
|
|
await p
|
|
.getByRole('button', { name: '3. Revisão', exact: true })
|
|
.click();
|
|
await p
|
|
.getByRole('button', {
|
|
name: 'Validar este rascunho',
|
|
exact: true,
|
|
})
|
|
.click();
|
|
await p.screenshot({
|
|
path: `storage/app/private/investmoz-v2/review-summary-${width}.png`,
|
|
fullPage: true,
|
|
});
|
|
const names = await summary.locator('dt').allTextContents();
|
|
const values = await summary.locator('dd').allTextContents();
|
|
assert.ok(names.length > 0 && names.length === values.length);
|
|
assert.ok(
|
|
names.every((text) => text.trim()) &&
|
|
values.every((text) => text.trim()),
|
|
);
|
|
const calculationResponse = p.waitForResponse(
|
|
(r) =>
|
|
new URL(r.url()).pathname === '/api/v1/simulations' &&
|
|
r.request().method() === 'POST',
|
|
);
|
|
await p
|
|
.getByRole('button', {
|
|
name: 'Abrir cálculo',
|
|
exact: true,
|
|
})
|
|
.click();
|
|
await p.waitForFunction(
|
|
() => document.activeElement?.id === 'draft-tool-calculation',
|
|
);
|
|
await p
|
|
.getByRole('button', {
|
|
name: 'Validar e calcular no servidor',
|
|
exact: true,
|
|
})
|
|
.dblclick();
|
|
const calculated = await calculationResponse;
|
|
assert.ok([200, 201, 202].includes(calculated.status()));
|
|
await p
|
|
.getByText('Cálculo concluído no servidor.', { exact: false })
|
|
.waitFor();
|
|
assert.equal(calculations, 1);
|
|
assert.equal(submissions, 0);
|
|
evidence.push({
|
|
width,
|
|
passed: true,
|
|
summaryFocused: true,
|
|
summaryInViewport: true,
|
|
pendingCorrection: true,
|
|
dataRecovered: true,
|
|
calculationPosts: calculations,
|
|
deskSubmissions: submissions,
|
|
consoleErrors,
|
|
http,
|
|
});
|
|
assert.deepEqual(consoleErrors, []);
|
|
await context.close();
|
|
}
|
|
fs.writeFileSync(
|
|
'storage/app/private/investmoz-v2/review-summary-browser.json',
|
|
JSON.stringify(
|
|
{ qa: 'investmoz_v2_20261008_test:55441', evidence },
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
console.log(
|
|
'QA summary: desktop/mobile, pending correction, focus, recovery and HTTP separation passed',
|
|
);
|
|
} finally {
|
|
await b.close();
|
|
}
|
|
})().catch((e) => {
|
|
console.error(e);
|
|
process.exitCode = 1;
|
|
});
|