Files
WebApp/e2e/cacu.spec.ts
T
2026-12-01 14:22:23 -06:00

231 lines
9.6 KiB
TypeScript

import { expect, type Page, test } from '@playwright/test';
import { layoutProblems } from './layout';
import { type Simulation, simulateRounds } from './simulated-rounds';
test.beforeEach(async ({ page }) => {
const form = { username: 'admin@isssteleon.mx', password: 'solo-para-pruebas' };
expect((await page.request.post('/api/auth/login', { form })).status()).toBe(204);
});
test('indicadores cacu: its sections in order, each card read one mode at a time', async ({
page,
}) => {
await page.goto('/indicadores/cacu');
const tab = page.locator('app-tab-indicadores');
await expect(tab.getByRole('heading', { name: 'Indicadores clínicos' })).toBeVisible();
await expect(tab.locator('app-loading')).toHaveCount(0, { timeout: 5 * 60_000 });
const headings = await tab
.locator('h2, app-readings h3')
.evaluateAll((els) => els.map((e) => (e as HTMLElement).innerText.trim()));
expect(headings.slice(headings.indexOf('Indicadores de oportunidad'))).toEqual([
'Indicadores de oportunidad',
'Tiempos de la ruta del tamizaje',
'Indicadores clínicos',
'Resultados de citología, VPH y biopsia',
'Distribución de resultados citológicos',
'Resultados de VPH por genotipo',
'Resultados de biopsia cervical',
'Pacientes evaluadas por resultado de VPH',
'Tasa de confirmación histopatológica',
'Valor predictivo positivo de la colposcopía',
]);
const route = tab.locator('app-readings').first();
for (const mode of ['Por pasos', 'Por CIE-10', 'Acumulado desde la toma']) {
await route.getByRole('radio', { name: mode }).click();
await expect(
route.getByRole('table', { name: mode }).or(route.getByText('Sin datos en el periodo.')),
).toBeVisible();
}
// the screening round replaces the clinical scenario: the same tab, label and order on four cards
const round = { name: 'Por detección inicial y subsecuente' };
await expect(tab.getByRole('radio', { name: 'Por escenario clínico' })).toHaveCount(0);
for (const card of [
'Distribución de resultados citológicos',
'Pacientes evaluadas por resultado de VPH',
'Valor predictivo positivo de la colposcopía',
]) {
const readings = tab.locator('app-readings', {
has: page.getByRole('heading', { name: card }),
});
await readings.getByRole('radio', round).click();
// rows in the order of the contract, "no disponible", or no patients in the period
await expect(
readings
.getByRole('table', round)
.or(readings.locator('app-plot'))
.or(readings.getByText(/No disponible|Sin datos en el periodo/)),
).toBeVisible();
if (await readings.getByRole('table', round).count()) {
const labels = await readings.getByRole('rowheader').allInnerTexts();
expect(labels.map((l) => l.trim().split(/\s{2,}|\n/)[0])).toEqual([
'Detección inicial',
'Detección subsecuente',
'Sin dato',
]);
}
}
await tab.getByRole('radio', { name: 'Biopsia', exact: true }).click();
await tab
.locator('app-readings', {
has: page.getByRole('heading', { name: 'Valor predictivo positivo de la biopsia' }),
})
.getByRole('radio', round)
.click();
await expect(
tab.getByRole('heading', { name: 'Valor predictivo positivo de la biopsia' }),
).toBeVisible();
await tab.getByRole('radio', { name: 'Solicitudes' }).click();
});
test('riesgos cacu: ages filter the whole list and a row opens its stages', async ({ page }) => {
await page.goto('/indicadores/cacu');
await page.getByRole('tab', { name: 'Análisis de riesgos' }).click();
const list = page.locator('table.worklist tbody tr');
await expect(list.first().locator('app-stages li')).toHaveCount(5);
await list.first().getByRole('button', { name: 'Detalle' }).click();
await expect(page.locator('tr.stage-detail')).toContainText('Toma de muestra');
const answer = page.waitForResponse((r) => r.url().includes('birthdate=le'));
await page.getByLabel('Edad mínima').fill('45');
expect((await answer).ok()).toBe(true);
for (const age of await list.locator('td:nth-child(2)').allInnerTexts())
expect(parseInt(age)).toBeGreaterThanOrEqual(45);
for (const [button, file] of [
['Exportar Excel', 'seguimiento-cacu.xlsx'],
['Exportar PDF', 'seguimiento-cacu.pdf'],
]) {
const saved = page.waitForEvent('download');
await page.getByRole('button', { name: button }).click();
expect((await saved).suggestedFilename()).toBe(file);
}
await list.first().locator('a').first().click();
await expect(page.locator('[data-section=etapas]')).toContainText('Reporte de biopsia');
const record = page.waitForEvent('download');
await page.getByRole('button', { name: 'Exportar PDF' }).click();
expect((await record).suggestedFilename()).toBe('expediente-cacu.pdf');
});
// ---- Screening rounds on SIMULATED answers (see simulated-rounds.ts): the groups the contract of
// `rebuild` allows, tried without loading data. They show how the page draws them, not the backend.
const ROUND = { name: 'Por detección inicial y subsecuente' };
const TITLES = {
cytology: 'Distribución de resultados citológicos',
vph: 'Pacientes evaluadas por resultado de VPH',
colposcopy: 'Valor predictivo positivo de la colposcopía',
biopsy: 'Valor predictivo positivo de la biopsia',
};
const BAR = {
initial: 'rgb(95, 127, 154)',
subsequent: 'rgb(143, 167, 187)',
no_data: 'rgb(201, 205, 210)',
};
async function withRounds(page: Page, how: Simulation) {
await simulateRounds(page, how);
await page.goto('/indicadores/cacu');
const tab = page.locator('app-tab-indicadores');
await expect(tab.getByRole('heading', { name: 'Indicadores clínicos' })).toBeVisible({
timeout: 3 * 60_000,
});
await expect(tab.locator('app-loading')).toHaveCount(0, { timeout: 5 * 60_000 });
const card = (title: string) =>
tab.locator('app-readings', { has: page.getByRole('heading', { name: title }) }).first();
const open = async (key: keyof typeof TITLES) => {
if (key === 'biopsy') await tab.getByRole('radio', { name: 'Biopsia', exact: true }).click();
if (key === 'colposcopy')
await tab.getByRole('radio', { name: 'Colposcopía', exact: true }).click();
const readings = card(TITLES[key]);
await readings.getByRole('radio', ROUND).click();
return readings;
};
return { tab, open };
}
for (const key of ['vph', 'colposcopy', 'biopsy'] as const) {
test(`rondas (simulado) ${key}: three groups in order, each with its own colour`, async ({
page,
}) => {
const { open } = await withRounds(page, 'as-is');
const readings = await open(key);
const rows = readings.getByRole('row').filter({ has: page.getByRole('rowheader') });
await expect(rows).toHaveCount(3);
const names = await readings.getByRole('rowheader').allInnerTexts();
expect(names.map((n) => n.trim().split(/\s*\n\s*/)[0])).toEqual([
'Detección inicial',
'Detección subsecuente',
'Sin dato',
]);
const colours = await readings
.locator('tbody .bar')
.evaluateAll((els) => els.map((e) => getComputedStyle(e).backgroundColor));
expect(colours).toEqual([BAR.initial, BAR.subsequent, BAR.no_data]);
});
test(`rondas (simulado) ${key}: an empty initial group is zero patients, not hidden`, async ({
page,
}) => {
const { open } = await withRounds(page, 'no-initial');
const readings = await open(key);
const initial = readings.getByRole('row').filter({ hasText: 'Detección inicial' });
await expect(initial).toContainText('Sin pacientes en el periodo');
await expect(initial).toContainText('0/0');
});
test(`rondas (simulado) ${key}: without the stratum the card says it is not available`, async ({
page,
}) => {
const { open } = await withRounds(page, 'unpublished');
const readings = await open(key);
await expect(readings).toContainText('No disponible');
await expect(readings.getByRole('table', ROUND)).toHaveCount(0);
});
}
test('rondas (simulado) cytology: the bars follow the round and the cytology colours', async ({
page,
}) => {
const { open } = await withRounds(page, 'as-is');
const readings = await open('cytology');
const plot = readings.locator('.js-plotly-plot');
await expect(plot).toBeVisible();
const { y, colours } = await plot.evaluate((e: any) => ({
y: e.data[0].y as string[],
colours: Object.fromEntries(e.data.map((t: any) => [t.name, t.marker.color])),
}));
expect(y.map((s) => s.split('<br>')[0])).toEqual([
'Detección inicial',
'Detección subsecuente',
'Sin dato',
]);
expect(colours).toMatchObject({
Normal: '#408651',
'ASC-US': '#2778B8',
LIEBG: '#B19525',
'ASC-H': '#7955B1',
LIEAG: '#CE4778',
'Carcinoma in situ': '#AA394D',
});
});
test('rondas (simulado): an initial group folded into "Sin dato" keeps its counts there', async ({
page,
}) => {
const { open } = await withRounds(page, 'unclassified');
const readings = await open('vph');
const rows = readings.getByRole('row').filter({ has: page.getByRole('rowheader') });
await expect(rows.filter({ hasText: 'Detección inicial' })).toContainText('0/0');
await expect(rows.filter({ hasText: 'Sin dato' })).not.toContainText('0/0');
await expect(readings).toContainText('una categoría en cero significa');
});
for (const width of [1440, 480]) {
test(`rondas (simulado) at ${width} px: the four cards open on their rounds lay out cleanly`, async ({
page,
}) => {
await page.setViewportSize({ width, height: 1000 });
const { open } = await withRounds(page, 'as-is');
for (const key of ['cytology', 'vph', 'colposcopy', 'biopsy'] as const) await open(key);
await page.waitForTimeout(1500);
expect(await layoutProblems(page)).toEqual([]);
});
}