143 lines
5.3 KiB
JavaScript
143 lines
5.3 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');
|
|
const base = 'http://127.0.0.1:18092';
|
|
void (async () => {
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath:
|
|
'C:/Users/macbook/AppData/Local/ms-playwright/chromium-1243/chrome-win64/chrome.exe',
|
|
});
|
|
const context = await browser.newContext();
|
|
await context.route('**/*', (r) =>
|
|
r.request().url().startsWith(base) ? r.continue() : r.abort(),
|
|
);
|
|
const page = await context.newPage();
|
|
const errors = [];
|
|
page.on('pageerror', (e) => errors.push(e.message));
|
|
try {
|
|
const response = await page.goto(base + '/login');
|
|
assert.equal(
|
|
response.headers()['x-investmoz-qa-target'],
|
|
'investmoz_v2_20261008_test:55441',
|
|
);
|
|
await page
|
|
.locator('input[type=email]')
|
|
.fill('guidance-qa-investor@example.invalid');
|
|
await page.locator('input[type=password]').fill('QA-Guidance-2026!');
|
|
await page.locator('button[type=submit]').click();
|
|
await page.waitForURL((url) => !url.pathname.startsWith('/login'));
|
|
await page.goto(base + '/balcao-virtual/painel');
|
|
await page
|
|
.getByText('Preparar acompanhamento de um projecto', {
|
|
exact: true,
|
|
})
|
|
.click();
|
|
const title = 'Painel — dossier sintético QA ' + Date.now();
|
|
await page.getByLabel('Título do projecto').fill(title);
|
|
await page
|
|
.getByRole('button', { name: 'Preparar dossier', exact: true })
|
|
.click();
|
|
await page
|
|
.getByRole('alert')
|
|
.filter({ hasText: 'O dossier não foi guardado' })
|
|
.waitFor();
|
|
assert.equal(
|
|
await page.getByLabel('Título do projecto').inputValue(),
|
|
title,
|
|
);
|
|
await page
|
|
.getByLabel('Autorizo reutilizar os dados seleccionados', {
|
|
exact: false,
|
|
})
|
|
.check();
|
|
let mode = 'conflict';
|
|
let writes = 0;
|
|
await page.route(base + '/balcao-virtual/dossiers', async (route) => {
|
|
if (route.request().method() !== 'POST') return route.continue();
|
|
if (mode === 'conflict')
|
|
return route.fulfill({
|
|
status: 409,
|
|
contentType: 'text/plain',
|
|
body: 'QA conflict',
|
|
});
|
|
if (mode === 'network') return route.abort('connectionfailed');
|
|
writes++;
|
|
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
return route.continue();
|
|
});
|
|
await page
|
|
.getByRole('button', { name: 'Preparar dossier', exact: true })
|
|
.click();
|
|
await page
|
|
.getByRole('alert')
|
|
.filter({ hasText: 'Esta operação já foi utilizada' })
|
|
.waitFor();
|
|
assert.equal(
|
|
await page.getByLabel('Título do projecto').inputValue(),
|
|
title,
|
|
);
|
|
mode = 'network';
|
|
await page
|
|
.getByRole('button', { name: 'Preparar dossier', exact: true })
|
|
.click();
|
|
await page
|
|
.getByRole('alert')
|
|
.filter({ hasText: 'A ligação falhou' })
|
|
.waitFor();
|
|
assert.equal(
|
|
await page.getByLabel('Título do projecto').inputValue(),
|
|
title,
|
|
);
|
|
mode = 'success';
|
|
await page
|
|
.getByRole('button', { name: 'Preparar dossier', exact: true })
|
|
.dblclick();
|
|
await page.waitForURL('**/balcao-virtual/dossiers/*');
|
|
await page
|
|
.getByRole('status')
|
|
.filter({ hasText: 'Dossier guardado e disponível' })
|
|
.waitFor();
|
|
assert.equal(writes, 1);
|
|
const caseUrl = page.url();
|
|
await page.goto(base + '/balcao-virtual/painel');
|
|
await page.getByRole('link', { name: title, exact: true }).click();
|
|
await page.waitForURL(caseUrl);
|
|
assert.equal(page.url(), caseUrl);
|
|
const result = await page.evaluate(async () => {
|
|
const r = await fetch(location.pathname, {
|
|
headers: { Accept: 'application/json' },
|
|
});
|
|
return r.json();
|
|
});
|
|
assert.equal(result.case.title, title);
|
|
assert.equal(result.requests.length, 0);
|
|
assert.deepEqual(errors, []);
|
|
const proof = {
|
|
passed: true,
|
|
database: 'investmoz_v2_20261008_test',
|
|
port: 55441,
|
|
actualPostCount: writes,
|
|
caseRecovered: true,
|
|
requestCount: result.requests.length,
|
|
validationFailurePreserved: true,
|
|
conflictPreserved: true,
|
|
networkFailurePreserved: true,
|
|
successAndNextActionVisible: true,
|
|
errors,
|
|
};
|
|
fs.writeFileSync(
|
|
'storage/app/private/investmoz-v2/panel-browser-evidence.json',
|
|
JSON.stringify(proof, null, 2),
|
|
);
|
|
console.log(JSON.stringify(proof));
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
})().catch((error) => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|