163 lines
5.8 KiB
JavaScript
163 lines
5.8 KiB
JavaScript
const {
|
|
chromium,
|
|
} = require('C:/Users/macbook/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright');
|
|
const fs = require('node:fs'),
|
|
assert = require('node:assert/strict');
|
|
const base = 'http://127.0.0.1:18095',
|
|
dir = 'storage/app/private/investmoz-v2/';
|
|
(async () => {
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath:
|
|
'C:/Users/macbook/AppData/Local/ms-playwright/chromium-1243/chrome-win64/chrome.exe',
|
|
});
|
|
const errors = [];
|
|
async function session(viewport) {
|
|
const context = await browser.newContext({ viewport });
|
|
await context.route('**/*', (r) =>
|
|
r.request().url().startsWith(base) ||
|
|
r.request().url().startsWith('data:')
|
|
? r.continue()
|
|
: r.abort(),
|
|
);
|
|
const page = await context.newPage();
|
|
page.on('pageerror', (e) => errors.push(e.message));
|
|
await page.goto(base + '/login');
|
|
await page
|
|
.getByLabel('Email address')
|
|
.fill('opportunity-manager@example.invalid');
|
|
await page
|
|
.getByLabel('Password', { exact: true })
|
|
.fill('Opportunity-QA-2026!');
|
|
await page.getByRole('button', { name: 'Log in', exact: true }).click();
|
|
await page.waitForURL('**/dashboard');
|
|
return { context, page };
|
|
}
|
|
const desktop = await session({ width: 1280, height: 900 }),
|
|
page = desktop.page;
|
|
await page
|
|
.getByRole('link', { name: 'Gestão de Oportunidades', exact: true })
|
|
.click();
|
|
await page
|
|
.getByRole('link', { name: 'Nova oportunidade', exact: true })
|
|
.click();
|
|
await page
|
|
.getByLabel('Motivo da alteração')
|
|
.fill('Criação incompleta autorizada somente em QA');
|
|
await page
|
|
.getByRole('button', { name: 'Guardar rascunho', exact: true })
|
|
.click();
|
|
await page.waitForURL(/\/management\/opportunities\/\d+\/edit$/);
|
|
const id = Number(page.url().match(/(\d+)\/edit$/)[1]);
|
|
assert(id > 6);
|
|
await page
|
|
.getByLabel('Título oficial')
|
|
.fill('QA browser opportunity recovered from server');
|
|
await page
|
|
.getByLabel('Categoria', { exact: true })
|
|
.selectOption('investment_project');
|
|
await page.getByLabel('Investimento estimado').fill('-1');
|
|
await page
|
|
.getByLabel('Motivo da alteração')
|
|
.fill('Edição financeira inválida para verificar erros QA');
|
|
await page
|
|
.getByRole('button', { name: 'Guardar rascunho', exact: true })
|
|
.click();
|
|
await page
|
|
.getByText('The estimated investment amount field format is invalid.')
|
|
.waitFor()
|
|
.catch(async () => {
|
|
await page.locator('[role="alert"]').first().waitFor();
|
|
});
|
|
assert.equal(
|
|
await page.getByLabel('Título oficial').inputValue(),
|
|
'QA browser opportunity recovered from server',
|
|
);
|
|
await page.getByLabel('Investimento estimado').fill('1000.25');
|
|
await page.getByLabel('Moeda', { exact: true }).selectOption('MZN');
|
|
await page
|
|
.getByRole('button', { name: 'Guardar rascunho', exact: true })
|
|
.click();
|
|
await page
|
|
.getByText(
|
|
'Rascunho guardado no servidor. Não foi submetido, aprovado ou publicado.',
|
|
{ exact: true },
|
|
)
|
|
.waitFor();
|
|
await page.screenshot({
|
|
path: dir + 'opportunity-management-desktop.png',
|
|
fullPage: true,
|
|
});
|
|
await desktop.context.close();
|
|
const mobile = await session({ width: 390, height: 844 });
|
|
await mobile.page.goto(base + `/management/opportunities/${id}/edit`);
|
|
await mobile.page.evaluate(() => localStorage.clear());
|
|
await mobile.page.reload();
|
|
assert.equal(
|
|
await mobile.page.getByLabel('Título oficial').inputValue(),
|
|
'QA browser opportunity recovered from server',
|
|
);
|
|
assert.equal(
|
|
await mobile.page.getByLabel('Investimento estimado').inputValue(),
|
|
'1000.25',
|
|
);
|
|
await mobile.page.screenshot({
|
|
path: dir + 'opportunity-management-mobile.png',
|
|
fullPage: true,
|
|
});
|
|
assert(
|
|
await mobile.page.evaluate(
|
|
() => document.documentElement.scrollWidth <= innerWidth + 1,
|
|
),
|
|
);
|
|
await mobile.page
|
|
.getByLabel('Motivo da alteração')
|
|
.fill('Exclusão lógica do rascunho de demonstração QA');
|
|
await mobile.page
|
|
.getByRole('checkbox', { name: /Confirmo a exclusão/ })
|
|
.check();
|
|
await mobile.page
|
|
.getByRole('button', { name: 'Excluir rascunho', exact: true })
|
|
.click();
|
|
await mobile.page
|
|
.getByRole('button', { name: 'Restaurar', exact: true })
|
|
.waitFor();
|
|
await mobile.page
|
|
.getByLabel('Motivo da alteração')
|
|
.fill('Restauração autorizada do rascunho somente QA');
|
|
await mobile.page
|
|
.getByRole('checkbox', { name: /Confirmo a restauração/ })
|
|
.check();
|
|
await mobile.page
|
|
.getByRole('button', { name: 'Restaurar', exact: true })
|
|
.click();
|
|
await mobile.page
|
|
.getByRole('button', { name: 'Excluir rascunho', exact: true })
|
|
.waitFor();
|
|
assert.equal(
|
|
await mobile.page.getByLabel('Título oficial').inputValue(),
|
|
'QA browser opportunity recovered from server',
|
|
);
|
|
assert.deepEqual(errors, []);
|
|
const proof = {
|
|
recorded_at: new Date().toISOString(),
|
|
id,
|
|
desktop: true,
|
|
mobile: true,
|
|
new_session_recovery: true,
|
|
field_errors: true,
|
|
soft_delete_restore: true,
|
|
errors,
|
|
active_writes: 0,
|
|
};
|
|
fs.writeFileSync(
|
|
dir + 'opportunity-management-browser.json',
|
|
JSON.stringify(proof, null, 2),
|
|
);
|
|
console.log(JSON.stringify(proof));
|
|
await browser.close();
|
|
})().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|