286 lines
14 KiB
TypeScript
286 lines
14 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
||
import { expect, Page, test } from '@playwright/test';
|
||
|
||
/** Every page loads from the API with no failed request and no console error. */
|
||
function watch(page: Page): string[] {
|
||
const problems: string[] = [];
|
||
page.on('console', (m) => m.type() === 'error' && problems.push(`console: ${m.text()}`));
|
||
page.on('response', (r) => r.status() >= 400 && problems.push(`${r.status()} ${r.url()}`));
|
||
page.on('pageerror', (e) => problems.push(`page: ${e.message}`));
|
||
return problems;
|
||
}
|
||
|
||
// The pages show only to someone signed in (the API itself answers everyone).
|
||
test.beforeEach(async ({ page }) => {
|
||
const signed = await page.request.post('/api/auth/login', {
|
||
form: { username: 'admin@isssteleon.mx', password: 'solo-para-pruebas' },
|
||
});
|
||
expect(signed.status()).toBe(204);
|
||
});
|
||
|
||
test('login: the pages wait for a sign-in, and a wrong password says so', async ({ browser }) => {
|
||
const page = await browser.newPage({ baseURL: 'http://127.0.0.1:4310' });
|
||
await page.goto('/conectar');
|
||
await expect(page).toHaveURL(/\/login\?next=%2Fconectar/);
|
||
await expect(page.getByRole('heading', { name: 'Inicio de sesión' })).toBeVisible();
|
||
await page.getByRole('textbox', { name: 'Usuario' }).fill('admin@isssteleon.mx');
|
||
await page.getByRole('textbox', { name: 'Contraseña' }).fill('otra');
|
||
await page.getByRole('button', { name: 'Ingresar' }).click();
|
||
await expect(page.getByText('Usuario o contraseña incorrectos.')).toBeVisible();
|
||
await page.getByRole('textbox', { name: 'Contraseña' }).fill('solo-para-pruebas');
|
||
await page.getByRole('button', { name: 'Ingresar' }).click();
|
||
await expect(page).toHaveURL(/\/conectar$/);
|
||
await page.getByRole('button', { name: 'Cuenta' }).click();
|
||
await page.getByRole('menuitem', { name: 'Salir' }).click();
|
||
await expect(page).toHaveURL(/\/login/);
|
||
await page.close();
|
||
});
|
||
|
||
test("indicators: the KPIs are the API's MeasureReports, every tab and the patient view load", async ({
|
||
page,
|
||
}) => {
|
||
const problems = watch(page);
|
||
const report = page.waitForResponse(
|
||
(r) =>
|
||
r.url().includes('MeasureReport') &&
|
||
r.url().includes('measure=cacu-eu7') &&
|
||
!r.url().includes('%2C'),
|
||
);
|
||
await page.goto('/indicadores/cacu');
|
||
const eu7 = await (await report).json();
|
||
const count = eu7.entry[0].resource.group[0].population.find(
|
||
(p: any) => p.code.coding[0].code === 'initial-population',
|
||
).count;
|
||
// the card says it as the old one did: "<n> pacientes"
|
||
await expect(page.locator('[data-measure="CACU_EU7"] .kpi-value')).toHaveText(
|
||
`${count.toLocaleString('es-MX')} pacientes`,
|
||
);
|
||
await expect(page.locator('app-tab-indicadores app-plot').first()).toBeVisible();
|
||
|
||
await page.getByRole('tab', { name: 'Trazabilidad' }).click();
|
||
await expect(page.locator('app-tab-trazabilidad mat-card')).toHaveCount(14);
|
||
|
||
await page.getByRole('tab', { name: 'Datos y definiciones' }).click();
|
||
await expect(page.locator('app-tab-definiciones tbody tr')).toHaveCount(14);
|
||
|
||
const list = page.waitForResponse((r) => r.url().includes('/fhir/Patient?'));
|
||
await page.getByRole('tab', { name: 'Análisis de riesgos' }).click();
|
||
const bundle = await (await list).json();
|
||
const patient = bundle.entry.find((e: any) => e.search.mode === 'match').resource;
|
||
const first = patient.name?.[0]?.text ?? patient.id.slice(0, 10);
|
||
const rows = page.locator('table.worklist tbody tr');
|
||
await expect(rows).toHaveCount(Math.min(20, bundle.total));
|
||
await expect(rows.first().locator('a').first()).toHaveText(first);
|
||
await page.getByRole('button', { name: 'Siguiente' }).click();
|
||
await expect(page.getByText(`21–`)).toBeVisible();
|
||
|
||
await page.getByRole('button', { name: 'Anterior' }).click();
|
||
await rows.first().locator('a').first().click();
|
||
await expect(page.getByText('Historial médico')).toBeVisible();
|
||
await expect(page.getByText('Pruebas y resultados')).toBeVisible();
|
||
await expect(
|
||
page.locator('app-paciente table').nth(1).locator('tbody tr').first(),
|
||
).not.toContainText('Sin estudios');
|
||
|
||
await page.goto('/indicadores/cama');
|
||
await expect(page.getByRole('tab', { name: 'Indicadores' })).toBeVisible();
|
||
await page.getByRole('tab', { name: 'Análisis de riesgos' }).click();
|
||
await page.locator('mat-form-field', { hasText: 'Ventana' }).click();
|
||
await page.getByRole('option', { name: '12 meses' }).click();
|
||
const camaRows = page.locator('table.worklist tbody tr');
|
||
await expect(camaRows.first()).toContainText('BI-RADS');
|
||
await page.goto('/indicadores/tea');
|
||
await expect(page.getByRole('tab', { name: 'Resumen' })).toBeVisible();
|
||
expect(problems).toEqual([]);
|
||
});
|
||
|
||
test('conectar: open the hospital pipeline, preview a source, run it to success', async ({
|
||
page,
|
||
}) => {
|
||
const problems = watch(page);
|
||
await page.goto('/conectar');
|
||
await page.getByText('cacu', { exact: true }).click();
|
||
await expect(page.locator('vflow')).toBeVisible();
|
||
await page.getByText('Fuente de datos · Patients').click();
|
||
await expect(page.locator('formly-form')).toBeVisible(); // drawn by hand: its raw form
|
||
await page.getByRole('button', { name: 'Vista previa' }).click();
|
||
await expect(page.locator('.preview tr[mat-row]').first()).toBeVisible();
|
||
// A map node shows the site's codes in platform terms (its ConceptMap), editable as rows.
|
||
await page.getByText('Traducir códigos · cytology', { exact: true }).click();
|
||
await expect(page.getByRole('heading', { name: /^Códigos del sitio/ })).toBeVisible();
|
||
await expect
|
||
.poll(() =>
|
||
page
|
||
.locator('app-concept-map-editor input')
|
||
.evaluateAll((els) => els.map((e) => (e as HTMLInputElement).value)),
|
||
)
|
||
.toContain('LIEAG');
|
||
await page.getByRole('button', { name: 'Ejecutar' }).click();
|
||
await expect(page.getByText('SUCCESS')).toBeVisible({ timeout: 10 * 60_000 });
|
||
expect(problems).toEqual([]);
|
||
});
|
||
|
||
test('revision: what the hospital source holds, and a decision through the page', async ({
|
||
page,
|
||
}) => {
|
||
const problems = watch(page);
|
||
await page.goto('/revision');
|
||
await page.getByRole('tab', { name: 'Personas' }).click();
|
||
await page.locator('mat-form-field', { hasText: 'Canalización' }).click();
|
||
await page.getByRole('option', { name: 'site', exact: true }).click();
|
||
await expect(page.getByText(/Posibles pacientes duplicadas \([1-9]/)).toBeVisible();
|
||
await page.getByRole('button', { name: 'Distintas' }).first().click();
|
||
await expect(page.getByText('Decisión registrada.')).toBeVisible();
|
||
expect(problems).toEqual([]);
|
||
});
|
||
|
||
test('gobernanza: a version with its reports, its curves, and promotion refused without validation', async ({
|
||
page,
|
||
}) => {
|
||
const problems = watch(page);
|
||
await page.goto('/gobernanza/cama');
|
||
await expect(page.getByRole('heading', { name: 'survival' })).toBeVisible();
|
||
const version = page.locator('tr', { hasText: 'v1' });
|
||
await expect(version.getByRole('link', { name: 'Validación técnica' })).toBeVisible();
|
||
await version.getByRole('button', { name: 'Ver gráficas' }).click();
|
||
await expect(page.locator('app-plot .plot svg').first()).toBeVisible();
|
||
await version.getByRole('button', { name: 'Promover' }).click();
|
||
await expect(page.getByText('No se promovió')).toContainText('clinical_validation');
|
||
expect(problems.filter((p) => !p.includes('409'))).toEqual([]);
|
||
});
|
||
|
||
test('conectar: someone who knows nothing of databases connects the SQL Server with the dialog', async ({
|
||
page,
|
||
}) => {
|
||
const site = new URL((process.env['SITE_URL'] ?? '').replace(/^mssql\+pymssql/, 'http'));
|
||
const problems = watch(page);
|
||
await page.goto('/conectar');
|
||
await page.getByLabel('Nueva canalización').fill('asistente');
|
||
await page.getByLabel('Nueva canalización').press('Enter');
|
||
await page.getByRole('button', { name: 'Fuente de datos' }).click();
|
||
await expect(page.getByText('¿Dónde están los datos?')).toBeVisible();
|
||
await page.locator('[data-type="sqlserver"]').click();
|
||
await page.locator('[data-field="host"]').fill(site.hostname);
|
||
await page.locator('[data-field="database"]').fill(site.pathname.slice(1));
|
||
await page.locator('[data-field="user"]').fill(decodeURIComponent(site.username));
|
||
await page.locator('[data-field="password"]').fill(decodeURIComponent(site.password));
|
||
await page.getByRole('button', { name: 'Probar conexión' }).click();
|
||
await expect(page.getByText('Conexión correcta: 1 tabla.')).toBeVisible();
|
||
await page.locator('mat-select[data-field="table"]').click();
|
||
await page.getByRole('option', { name: 'ResultadoSubrogado' }).click();
|
||
await expect(page.getByText(/(Las primeras \d+ filas|La primera fila):/)).toBeVisible();
|
||
await page.getByLabel('Nombre de esta fuente').fill('Resultados');
|
||
await page.getByRole('button', { name: 'Guardar', exact: true }).last().click();
|
||
await expect(page.getByText('Fuente de datos · Resultados')).toBeVisible();
|
||
// A wrong password says so in words, not a stack trace.
|
||
await page.getByRole('button', { name: 'Editar conexión' }).click();
|
||
await page.locator('[data-field="password"]').fill('not-it');
|
||
await page.getByRole('button', { name: 'Probar conexión' }).click();
|
||
await expect(page.getByText(/usuario o la contraseña no son correctos/)).toBeVisible();
|
||
await page.getByRole('button', { name: 'Cancelar' }).click();
|
||
await expect(page.getByRole('dialog')).toHaveCount(0);
|
||
await page.getByRole('button', { name: 'Guardar', exact: true }).click();
|
||
await expect(page.getByText('Versión 1 guardada.')).toBeVisible();
|
||
expect(problems).toEqual([]);
|
||
});
|
||
|
||
/** The old app's Indicadores tab as captured (tools/capture_pages.py): its headings from the
|
||
* opportunity section on, in order, and the kind of each plot (its traces' types). */
|
||
function captured(domain: string) {
|
||
const path = `../tests/fixtures/reference/${domain}/ui/pages.json`;
|
||
const tabs = JSON.parse(readFileSync(path, 'utf8')).tabs;
|
||
const items = (tabs['Indicadores'] ?? tabs['Resumen']) as any[]; // TEA's first tab is its summary
|
||
const from = items.findIndex((i) => i.text === 'Indicadores de oportunidad');
|
||
return items
|
||
.slice(from)
|
||
.filter((i) => ['h2', 'h3', 'plot'].includes(i.kind))
|
||
.filter((i) => !/^(cacu|cama|tea), /.test(i.text ?? '')); // a figure's machine caption
|
||
}
|
||
const period = (text: string) => text.replace(/, \d{4}-(S[12]|\d{2})$/, ', <periodo>');
|
||
const kindOf = (types: string[]) => [...new Set(types)].sort().join('+');
|
||
|
||
for (const domain of ['cacu', 'cama', 'tea']) {
|
||
test(`indicadores ${domain}: the old page's headings, in order, and the same kinds of plots`, async ({
|
||
page,
|
||
}) => {
|
||
const old = captured(domain);
|
||
await page.goto(`/indicadores/${domain}`);
|
||
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, h3')
|
||
.evaluateAll((els) => els.map((e) => (e as HTMLElement).innerText.trim()));
|
||
const from = headings.indexOf('Indicadores de oportunidad');
|
||
expect(headings.slice(from).map(period)).toEqual(
|
||
old.filter((i) => i.kind !== 'plot').map((i) => period(i.text)),
|
||
);
|
||
// Each figure drawn is one of the old kinds (a figure with no data in the period is named).
|
||
const drawn = await tab
|
||
.locator('.js-plotly-plot')
|
||
.evaluateAll((els) =>
|
||
els.map((e: any) => (e.data ?? []).map((t: any) => t.type ?? 'scatter')),
|
||
);
|
||
const kinds = new Set(
|
||
old.filter((i) => i.kind === 'plot').map((i) => kindOf(i.traces.map((t: any) => t.type))),
|
||
);
|
||
for (const types of drawn) expect(kinds).toContain(kindOf(types));
|
||
});
|
||
}
|
||
|
||
for (const domain of ['cacu', 'cama', 'tea']) {
|
||
test(`trazabilidad ${domain}: the old tab's panels, in order, and the same kinds of plots`, async ({
|
||
page,
|
||
}) => {
|
||
const tabs = JSON.parse(
|
||
readFileSync(`../tests/fixtures/reference/${domain}/ui/pages.json`, 'utf8'),
|
||
).tabs;
|
||
const old = (tabs['Trazabilidad'] as any[]).filter((i) =>
|
||
['h2', 'h3', 'plot'].includes(i.kind),
|
||
);
|
||
await page.goto(`/indicadores/${domain}`);
|
||
await page.getByRole('tab', { name: 'Trazabilidad' }).click();
|
||
const tab = page.locator('app-tab-trazabilidad');
|
||
await expect(tab.getByRole('heading', { name: 'Filtros' })).toBeVisible();
|
||
await expect(tab.locator('app-loading')).toHaveCount(0, { timeout: 5 * 60_000 });
|
||
const headings = await tab
|
||
.locator('h2, h3')
|
||
.evaluateAll((els) => els.map((e) => (e as HTMLElement).innerText.trim()));
|
||
expect(headings).toEqual(old.filter((i) => i.kind !== 'plot').map((i) => i.text));
|
||
const drawn = await tab
|
||
.locator('.js-plotly-plot')
|
||
.evaluateAll((els) =>
|
||
els.map((e: any) => (e.data ?? []).map((t: any) => t.type ?? 'scatter')),
|
||
);
|
||
const kinds = new Set(
|
||
old.filter((i) => i.kind === 'plot').map((i) => kindOf(i.traces.map((t: any) => t.type))),
|
||
);
|
||
for (const types of drawn) expect(kinds).toContain(kindOf(types));
|
||
});
|
||
}
|
||
|
||
for (const domain of ['cacu', 'cama', 'tea']) {
|
||
test(`datos y definiciones ${domain}: the old tab's headings and an indicator that opens`, async ({
|
||
page,
|
||
}) => {
|
||
const tabs = JSON.parse(
|
||
readFileSync(`../tests/fixtures/reference/${domain}/ui/pages.json`, 'utf8'),
|
||
).tabs;
|
||
const old = (tabs['Datos y definiciones'] as any[])
|
||
.filter((i) => ['h2', 'h3'].includes(i.kind))
|
||
.map((i) => i.text);
|
||
await page.goto(`/indicadores/${domain}`);
|
||
await page.getByRole('tab', { name: 'Datos y definiciones' }).click();
|
||
const tab = page.locator('app-tab-definiciones');
|
||
await expect(tab.getByRole('heading', { name: 'Catálogo de indicadores' })).toBeVisible();
|
||
const headings = await tab
|
||
.locator('h2, h3')
|
||
.evaluateAll((els) => els.map((e) => (e as HTMLElement).innerText.trim()));
|
||
expect(headings).toEqual(old);
|
||
await tab.locator('summary').first().click();
|
||
await expect(
|
||
tab.getByRole('heading', { name: 'Tipos de periodo admitidos' }).first(),
|
||
).toBeVisible();
|
||
});
|
||
}
|