Gobernanza preview saved as PDF; Playwright TEA page tests

- The EEG preview dialog gets "Guardar como PDF": previewPdfContent is a
  pure function (verdict, checks, metrics with scores per electrode and
  zone, ADOS-2 classification/CSS and items by their Core titles,
  warnings), downloadPreviewPdf a thin wrapper over export/pdf; the file
  is tea-gobernanza-<day>.pdf. Unit-tested without mocks.
- e2e/pages.spec.ts now holds only the TEA page tests (the CaCu/CaMa
  cases needed fixtures P7 removed): every indicator tab, the follow-up
  xlsx export, the patient record and risk page with their PDFs, and
  every Gobernanza section in sync mode including the preview PDF. Each
  download is checked for a file and a name without a record number.
- Fixes the page tests found: the TEA xlsx name ('seguimiento-tea') failed
  validateName, so the export always threw; it is now tea-<page>-<day>.
  ng serve crashed on every Plotly page (has-hover reads 'global'): the
  build defines global as globalThis. Record numbers repeated once per
  source identifier; they are deduplicated. A refused bundle export showed
  '{}': the blob error body is now read for the API's detail.
This commit is contained in:
2026-11-30 19:17:46 -06:00
parent b847e04697
commit b291885b97
14 changed files with 419 additions and 113 deletions
+102 -89
View File
@@ -1,6 +1,6 @@
import { expect, Page, test } from '@playwright/test';
import { statSync } from 'node:fs';
import { expect, Locator, 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()}`));
@@ -9,110 +9,123 @@ function watch(page: Page): string[] {
return problems;
}
test("indicators: the KPIs are the API's MeasureReports, every tab and the patient view load", async ({
async function downloaded(page: Page, button: Locator, kind: 'pdf' | 'xlsx'): Promise<string> {
const [file] = await Promise.all([page.waitForEvent('download'), button.click()]);
const name = file.suggestedFilename();
expect(name).toMatch(new RegExp(`^tea-[a-z]+-\\d{4}-\\d{2}-\\d{2}\\.${kind}$`));
expect(name).not.toMatch(/N-?\d{4}/);
expect(statSync(await file.path()).size).toBeGreaterThan(0);
return name;
}
test('tea indicators: every tab loads, and the follow-up list exports to Excel', 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'),
const listed = page.waitForResponse(
(r) => r.url().includes('/tea/fhir/Measure') && !r.url().includes('MeasureReport'),
);
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;
await expect(page.locator('[data-measure="CACU_EU7"] .kpi-value')).toHaveText(String(count));
await expect(page.locator('app-tab-indicadores app-plot').first()).toBeVisible();
await page.goto('/indicadores/tea');
const measures = (await (await listed).json()).entry.length;
await expect(page.getByRole('tab', { name: 'Resumen' })).toBeVisible();
await expect(page.locator('app-tab-indicadores mat-card[data-measure]').first()).toBeVisible();
await page.getByRole('tab', { name: 'Trazabilidad' }).click();
await expect(page.locator('app-tab-trazabilidad mat-card')).toHaveCount(14);
await expect(page.getByText('Progresión del proceso diagnóstico')).toBeVisible();
await expect(page.locator('app-tab-trazabilidad app-plot').first()).toBeVisible();
await page.getByRole('tab', { name: 'Seguimiento' }).click();
const rows = page.locator('app-tab-seguimiento table tbody tr');
await expect(rows.first().locator('td').first()).toHaveText(/^N-?\d{4}$/);
const name = await downloaded(
page,
page.getByRole('button', { name: 'Exportar a Excel' }),
'xlsx',
);
expect(name).toMatch(/^tea-seguimiento-/);
await page.getByRole('tab', { name: 'Análisis de riesgo' }).click();
await expect(page.locator('app-tab-riesgos app-tea-list')).toBeVisible();
await expect(page.getByText('Cargando pacientes…')).toHaveCount(0);
await page.getByRole('tab', { name: 'Datos y definiciones' }).click();
await expect(page.locator('app-tab-definiciones tbody tr')).toHaveCount(14);
await expect(page.locator('app-tab-definiciones tbody tr')).toHaveCount(measures);
expect(problems).toEqual([]);
});
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: 'Seguimiento' }).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');
test('tea patient: the record and the risk page load and export to PDF', async ({ page }) => {
const problems = watch(page);
await page.goto('/indicadores/tea');
await expect(page.getByRole('tab', { name: 'Indicadores' })).toBeVisible();
await page.getByRole('tab', { name: 'Seguimiento' }).click();
const first = page.locator('app-tab-seguimiento table tbody tr').first();
await expect(first.locator('td').first()).toHaveText(/^N-?\d{4}$/);
await first.getByRole('link', { name: 'Expediente' }).click();
await expect(page).toHaveURL(/\/indicadores\/tea\/pacientes\/[^/]+$/);
await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
await expect(page.locator('app-tea-section').first()).toBeVisible();
const record = await downloaded(page, page.getByRole('button', { name: 'Exportar PDF' }), 'pdf');
expect(record).toMatch(/^tea-seguimiento-/);
await page.getByRole('link', { name: 'Riesgo' }).click();
await expect(page.getByRole('heading', { name: 'Análisis de riesgo TEA' })).toBeVisible();
await expect(page.locator('app-tea-section').first()).toBeVisible();
expect(await downloaded(page, page.getByRole('button', { name: 'Exportar PDF' }), 'pdf')).toMatch(
/^tea-riesgos-/,
);
expect(problems).toEqual([]);
});
test('conectar: open the hospital pipeline, preview a source, run it to success', async ({
test('tea gobernanza: every section in sync mode, and the preview saved as PDF', 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 · Patients').click();
await expect(page.locator('formly-form')).toBeVisible();
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('Mapear · cytology', { exact: true }).click();
await expect(page.getByText('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([]);
});
await page.goto('/gobernanza/tea');
await page.getByLabel('Modo').selectOption('sync');
await expect(page.getByRole('status').filter({ hasText: 'Disponible' })).toBeVisible();
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([]);
});
await page.getByRole('button', { name: 'Entrenar modelos' }).click();
await expect(page.getByRole('heading', { name: 'Entrenar modelos', level: 3 })).toBeVisible();
await expect(page.locator('app-governance-training formly-form')).toBeVisible();
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');
const monitor = page.locator('app-gobernanza > section > section app-run-monitor');
await page.getByRole('button', { name: 'Analizar EEG' }).click();
await expect(page.getByRole('heading', { name: 'Análisis de EEG' })).toBeVisible();
await expect(monitor.getByRole('status')).toHaveText('SUCCESS', { timeout: 10 * 60_000 });
await page.getByRole('button', { name: 'Calcular riesgos' }).click();
await expect(page.getByRole('heading', { name: 'Cálculo de riesgos' })).toBeVisible();
await expect(monitor.getByRole('status')).toHaveText('SUCCESS', { timeout: 10 * 60_000 });
await page.getByRole('button', { name: 'Promover candidatas' }).click();
await expect(page.getByText('No hay candidatas que se puedan promover.')).toBeVisible();
const studies = page.locator('app-eeg-studies');
await expect(studies.locator('table.eegs tbody tr').first()).toContainText(/Válido|No válido/);
await studies.locator('table.eegs tbody button:enabled').first().click();
await expect(studies.getByRole('heading', { name: /^EEG .* meses$/ })).toBeVisible();
await studies.getByRole('button', { name: 'Analizar', exact: true }).click();
await expect(studies.locator('app-run-monitor').first().getByRole('status')).toHaveText(
'SUCCESS',
{ timeout: 10 * 60_000 },
);
const preview = page.locator('app-eeg-preview');
await preview.getByLabel('EDF').setInputFiles(process.env['TEA_EDF']!);
await preview.getByLabel('ADOS-2 (PDF)').setInputFiles(process.env['TEA_ADOS2']!);
await preview.getByLabel('Fecha de nacimiento').fill(process.env['TEA_BIRTH']!);
await preview.getByRole('button', { name: 'Vista previa' }).click();
const dialog = page.getByRole('dialog', { name: 'Vista previa del estudio' });
await expect(dialog.getByText('Resultado de la vista previa')).toBeVisible({
timeout: 10 * 60_000,
});
await expect(dialog.locator('dt').first()).toHaveText(/^[AB]-\d+ \S/);
expect(
await downloaded(page, dialog.getByRole('button', { name: 'Guardar como PDF' }), 'pdf'),
).toMatch(/^tea-gobernanza-/);
await dialog.getByRole('button', { name: 'Cerrar' }).click();
const bundles = page.locator('app-governance-bundles');
await bundles.getByLabel('Versiones').selectOption('all');
await bundles.getByRole('button', { name: 'Exportar bundle' }).click();
await expect(bundles.getByRole('alert')).toContainText('nothing to export');
expect(problems.filter((p) => !p.includes('409'))).toEqual([]);
});