Files
RutasDBUS/tests/verify-zones.cjs
Pedro 235297fd3a - Separado el control de poligonos excluyentes
- Añadido interpreacion de tipologia de suelo en segmentos andando
- Persistencia modo andando
- Transbordo penalizado a 6
- Añadidos varias zonas de prohibicion de poligonos
2026-09-08 13:33:15 +02:00

81 lines
5.5 KiB
JavaScript

const { chromium } = require(process.argv[2] || "playwright");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
(async () => {
const browser = await chromium.launch({ channel: "msedge", headless: true });
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
const errors = [];
page.on("pageerror", error => errors.push(error.stack || error.message));
const artifacts = path.join(__dirname, "../artifacts/zones-check");
fs.mkdirSync(artifacts, { recursive: true });
try {
await page.goto("http://127.0.0.1:5199", { waitUntil: "domcontentloaded" });
await page.waitForFunction(() => !!window.rt?._dotNetHelper && !!window.__rtLeafletMap);
const initialErrors = errors.slice();
await page.getByRole("button", { name: "Abrir zonas a evitar", exact: true }).click();
await page.getByRole("button", { name: "Añadir zona", exact: true }).click();
for (const [x, y] of [[600, 420], [850, 430], [760, 640]]) {
await page.mouse.click(x, y);
await page.waitForTimeout(250);
}
await page.getByRole("button", { name: "Cerrar zona", exact: true }).click();
await page.getByRole("button", { name: "Añadir zona", exact: true }).waitFor();
assert.equal(await page.locator(".zones-panel__item").count(), 1);
assert.equal(await page.locator(".rt-exclusion-vertex").count(), 3);
const polygon = page.locator('path[stroke="#e879f9"]');
const previousShape = await polygon.getAttribute("d");
const marker = await page.locator(".rt-exclusion-vertex").first().boundingBox();
await page.mouse.move(marker.x + marker.width / 2, marker.y + marker.height / 2);
await page.mouse.down();
await page.mouse.move(marker.x - 55, marker.y + 65, { steps: 10 });
assert.notEqual(await polygon.getAttribute("d"), previousShape, "Poligono se mueve durante el arrastre");
await page.mouse.up();
await page.waitForTimeout(250);
await page.getByRole("button", { name: "Añadir zona", exact: true }).click();
for (const [x, y] of [[920, 460], [1090, 460], [1020, 640]]) {
await page.mouse.click(x, y);
await page.waitForTimeout(250);
}
await page.getByRole("button", { name: "Cerrar zona", exact: true }).click();
await page.getByRole("button", { name: "Añadir zona", exact: true }).waitFor();
assert.equal(await page.locator(".zones-panel__item").count(), 2);
await page.screenshot({ path: path.join(artifacts, "desktop.png") });
const heights = await page.locator(".zones-panel__actions .btn-ghost").evaluateAll(
buttons => buttons.map(button => button.getBoundingClientRect().height));
assert.equal(new Set(heights).size, 1, "Botones de igual altura");
await page.getByRole("button", { name: "Cerrar herramienta", exact: true }).click();
await page.locator(".zones-panel").waitFor({ state: "detached" });
assert.equal(await page.locator(".rt-exclusion-vertex").count(), 0);
assert.equal(await page.locator('path[stroke="#e879f9"], path[stroke="#f97316"]').count(), 0);
await page.getByRole("button", { name: "Abrir zonas a evitar", exact: true }).click();
await page.locator(".zones-panel").waitFor();
assert.equal(await page.locator(".zones-panel__item").count(), 2, "Reabrir conserva zonas editables");
await page.getByRole("button", { name: "Eliminar zona", exact: true }).first().click();
await page.waitForFunction(() => document.querySelectorAll(".zones-panel__item").length === 1);
assert.equal(await page.locator(".zones-panel__item").count(), 1);
await page.getByRole("button", { name: "Borrar todas", exact: true }).click();
await page.waitForFunction(() => document.querySelectorAll(".zones-panel__item").length === 0);
assert.equal(await page.locator(".zones-panel__item").count(), 0);
await page.setViewportSize({ width: 390, height: 844 });
await page.screenshot({ path: path.join(artifacts, "mobile.png") });
const box = await page.locator(".zones-panel").boundingBox();
assert.ok(box.x >= 0 && box.x + box.width <= 390 && box.y + box.height <= 844, "Panel dentro del movil");
await page.getByRole("button", { name: "Añadir zona", exact: true }).click();
await page.getByRole("button", { name: "Cerrar herramienta", exact: true }).click();
await page.setViewportSize({ width: 1440, height: 1000 });
await page.getByTitle("Configuración", { exact: true }).click();
assert.equal(await page.locator(".config-more-menu").count(), 0, "No hay opcion para guardar valores de fabrica");
const externalErrors = errors.filter(error =>
error.includes("esri-leaflet-geocoder@3.1.4/dist/esri-leaflet-geocoder.js") &&
error.includes("reading 'extend'"));
const newErrors = errors.filter(error => !initialErrors.includes(error) && !externalErrors.includes(error));
assert.equal(newErrors.length, 0, newErrors.join("\n"));
if (externalErrors.length) console.log("Aviso del complemento externo de geocodificacion: " + externalErrors[0]);
console.log("OK multiples zonas, arrastre en vivo, cierre, reapertura, borrado, alturas de botones y movil");
} finally {
await browser.close();
}
})().catch(error => { console.error(error); process.exitCode = 1; });