240 lines
9.0 KiB
JavaScript
240 lines
9.0 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 path = require('node:path');
|
|
const privateDir = path.resolve(
|
|
__dirname,
|
|
'../storage/app/private/investmoz-v2',
|
|
);
|
|
const fixture = JSON.parse(
|
|
fs.readFileSync(
|
|
path.join(privateDir, 'territory-qa-fixtures.json'),
|
|
'utf8',
|
|
),
|
|
);
|
|
assert.equal(fixture.database, 'investmoz_v2_20261008_test');
|
|
assert.equal(fixture.port, 55441);
|
|
(async () => {
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath:
|
|
'C:/Users/macbook/AppData/Local/ms-playwright/chromium-1243/chrome-win64/chrome.exe',
|
|
});
|
|
const checks = [];
|
|
try {
|
|
for (const width of [1440, 390]) {
|
|
const context = await browser.newContext({
|
|
viewport: { width, height: 850 },
|
|
});
|
|
await context.route('**/*', (route) =>
|
|
route.request().url().startsWith('http://127.0.0.1:18092')
|
|
? route.continue()
|
|
: route.abort(),
|
|
);
|
|
const page = await context.newPage();
|
|
const errors = [];
|
|
const writes = [];
|
|
page.on('pageerror', (e) => errors.push(e.message));
|
|
page.on('request', (r) => {
|
|
if (!['GET', 'HEAD'].includes(r.method()))
|
|
writes.push(r.method() + ' ' + r.url());
|
|
});
|
|
for (const [kind, record] of Object.entries(fixture.cases)) {
|
|
const response = await page.goto(
|
|
'http://127.0.0.1:18092/oportunidades/' + record.slug,
|
|
);
|
|
assert.equal(response.status(), 200);
|
|
assert.match(
|
|
response.headers()['x-investmoz-qa-target'] || '',
|
|
/investmoz_v2_20261008_test/,
|
|
);
|
|
try {
|
|
await page
|
|
.getByRole('heading', {
|
|
name: 'Implantação declarada da oportunidade',
|
|
})
|
|
.waitFor({ timeout: 10000 });
|
|
} catch (error) {
|
|
fs.writeFileSync(
|
|
path.join(
|
|
privateDir,
|
|
'territory-browser-diagnostic.json',
|
|
),
|
|
JSON.stringify(
|
|
{
|
|
url: page.url(),
|
|
errors,
|
|
body: await page.locator('body').innerText(),
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
throw error;
|
|
}
|
|
const map = await page.request.get(
|
|
'http://127.0.0.1:18092/api/v1/investment/map?opportunity_id=' +
|
|
record.id,
|
|
);
|
|
const data = await map.json();
|
|
const expected =
|
|
kind === 'multiple'
|
|
? 2
|
|
: ['direct', 'context'].includes(kind)
|
|
? 1
|
|
: 0;
|
|
assert.equal(data.features.length, expected);
|
|
const section = page
|
|
.locator('section')
|
|
.filter({
|
|
has: page.getByRole('heading', {
|
|
name: 'Implantação declarada da oportunidade',
|
|
exact: true,
|
|
}),
|
|
})
|
|
.first();
|
|
if (['context', 'insufficient'].includes(kind))
|
|
assert.match(await section.innerText(), /não documentada/);
|
|
if (kind === 'context') {
|
|
assert.equal(
|
|
data.features[0].properties.location_basis,
|
|
'linked_project_site',
|
|
);
|
|
await page
|
|
.getByRole('link', {
|
|
name: 'Consultar dossier: Territory QA dossier',
|
|
})
|
|
.click();
|
|
await page.waitForURL('**/carteira/' + fixture.dossier);
|
|
await page
|
|
.getByRole('link', {
|
|
name: record.title || 'Territory QA context',
|
|
exact: true,
|
|
})
|
|
.first()
|
|
.click();
|
|
await page.waitForURL(
|
|
'**/oportunidades/' + record.slug + '**',
|
|
);
|
|
}
|
|
if (kind === 'multiple') {
|
|
const buttons = page.getByRole('button', {
|
|
name: 'Territory QA multiple',
|
|
exact: true,
|
|
});
|
|
await buttons.first().waitFor();
|
|
assert.equal(await buttons.count(), 2);
|
|
await buttons.nth(0).click();
|
|
await buttons.nth(1).click();
|
|
assert.equal(
|
|
await buttons.nth(1).getAttribute('aria-pressed'),
|
|
'true',
|
|
);
|
|
assert.equal(
|
|
await buttons.nth(0).getAttribute('aria-pressed'),
|
|
'false',
|
|
);
|
|
}
|
|
if (kind === 'direct') {
|
|
assert.equal(data.areas.length, 1);
|
|
await page
|
|
.getByText(
|
|
/Polígono cadastrado, limites oficiais por verificar/,
|
|
)
|
|
.first()
|
|
.waitFor();
|
|
}
|
|
if (kind === 'without-point') {
|
|
await section
|
|
.getByText('Coordenadas não documentadas.')
|
|
.waitFor();
|
|
await section
|
|
.getByRole('link', {
|
|
name: 'Pesquisar oportunidades neste território',
|
|
})
|
|
.click();
|
|
await page.waitForURL(
|
|
'**/oportunidades?geo_location_id=' + fixture.district,
|
|
);
|
|
await page
|
|
.getByRole('link', {
|
|
name: 'Territory QA without-point',
|
|
exact: true,
|
|
})
|
|
.first()
|
|
.waitFor();
|
|
}
|
|
checks.push({
|
|
width,
|
|
kind,
|
|
markers: data.features.length,
|
|
areas: data.areas.length,
|
|
passed: true,
|
|
});
|
|
}
|
|
await page.goto('http://127.0.0.1:18092/oportunidades');
|
|
await page
|
|
.getByLabel('Base da relação territorial')
|
|
.selectOption('context');
|
|
await page
|
|
.getByRole('button', { name: 'Aplicar filtros', exact: true })
|
|
.click();
|
|
await page.waitForURL('**territory_basis=context**');
|
|
await page
|
|
.getByRole('link', {
|
|
name: 'Territory QA context',
|
|
exact: true,
|
|
})
|
|
.first()
|
|
.waitFor();
|
|
assert.equal(
|
|
await page
|
|
.getByRole('link', {
|
|
name: 'Territory QA direct',
|
|
exact: true,
|
|
})
|
|
.count(),
|
|
0,
|
|
);
|
|
await page
|
|
.getByRole('status')
|
|
.filter({ hasText: 'locais com coordenadas disponíveis.' })
|
|
.first()
|
|
.waitFor();
|
|
assert.deepEqual(errors, []);
|
|
assert.deepEqual(writes, []);
|
|
await page.screenshot({
|
|
path: path.join(
|
|
privateDir,
|
|
'territory-browser-' + width + '.png',
|
|
),
|
|
fullPage: true,
|
|
});
|
|
await context.close();
|
|
}
|
|
fs.writeFileSync(
|
|
path.join(privateDir, 'territory-browser.json'),
|
|
JSON.stringify(
|
|
{
|
|
database: fixture.database,
|
|
port: fixture.port,
|
|
external_requests_blocked: true,
|
|
checks,
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
console.log(
|
|
JSON.stringify({ passed: true, checks: checks.length, writes: 0 }),
|
|
);
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
})().catch((error) => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|