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:
@@ -0,0 +1,119 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { PreviewResult } from '../../api/models/preview-result';
|
||||
import { previewPdfContent, previewPdfName } from './preview-pdf';
|
||||
|
||||
const score = { z: 2.1, p5: 1, median: 2, p95: 3, outside: 1 };
|
||||
|
||||
const result: PreviewResult = {
|
||||
eeg: {
|
||||
valid: true,
|
||||
level: 'complete',
|
||||
recorded_on: '2026-01-10',
|
||||
age_months: 24,
|
||||
clean_fraction: 0.9,
|
||||
bad_channels: 0,
|
||||
channels: 19,
|
||||
duration_min: 20,
|
||||
line_noise_db: 3,
|
||||
sleep: true,
|
||||
error: null,
|
||||
checks: [
|
||||
{ code: 'duration', value: 20, unit: 'min', low: 10, high: null, abnormal: false },
|
||||
{ code: 'flat', electrode: 'O1', text: 'plano', abnormal: true },
|
||||
],
|
||||
metrics: [
|
||||
{
|
||||
code: 'posterior_rhythm',
|
||||
value: 6.5,
|
||||
model: 'tea.eeg-posterior-rhythm/1',
|
||||
score,
|
||||
electrodes: { O1: { value: 6.4, score: null } },
|
||||
zones: { occipital: { value: 6.6, score } },
|
||||
},
|
||||
],
|
||||
},
|
||||
ados2: {
|
||||
module: 'module_1',
|
||||
evaluation_date: '2026-01-12',
|
||||
items: { pointing: 2, gestures: null, intonation: null, ignoring: 1 },
|
||||
titles: { pointing: 'A-7 Señalar', gestures: 'A-8 Gestos' },
|
||||
css: 7,
|
||||
classification: 'autism',
|
||||
read: ['module', 'pointing'],
|
||||
},
|
||||
warnings: ['sin curva en producción para spindles_n2'],
|
||||
};
|
||||
|
||||
describe('previewPdfContent', () => {
|
||||
it('prints the verdict, checks, scored metrics, ADOS-2 items by title and warnings', () => {
|
||||
expect(previewPdfContent(result)).toEqual([
|
||||
{ text: 'Vista previa del estudio EEG', fontSize: 18, bold: true },
|
||||
'complete · Válido',
|
||||
{ text: 'Comprobaciones', bold: true, fontSize: 14, margin: [0, 12, 0, 5] },
|
||||
{
|
||||
layout: 'lightHorizontalLines',
|
||||
table: {
|
||||
headerRows: 1,
|
||||
widths: ['*', 'auto', 'auto', 'auto', 'auto'],
|
||||
body: [
|
||||
['Comprobación', 'Electrodo', 'Resultado', 'Rango', 'Anormal'],
|
||||
['duration', '—', '20 min', '10 / —', 'No'],
|
||||
['flat', 'O1', 'plano', '— / —', 'Sí'],
|
||||
],
|
||||
},
|
||||
},
|
||||
{ text: 'Métricas', bold: true, fontSize: 14, margin: [0, 12, 0, 5] },
|
||||
{
|
||||
layout: 'lightHorizontalLines',
|
||||
table: {
|
||||
headerRows: 1,
|
||||
widths: ['*', 'auto', 'auto', 'auto', 'auto'],
|
||||
body: [
|
||||
['Métrica', 'Valor', 'z', 'p5 / mediana / p95', 'Fuera de rango'],
|
||||
['posterior_rhythm', '6.5', '2.1', '1 / 2 / 3', '1'],
|
||||
['posterior_rhythm · O1', '6.4', '—', '— / — / —', '—'],
|
||||
['posterior_rhythm · occipital', '6.6', '2.1', '1 / 2 / 3', '1'],
|
||||
],
|
||||
},
|
||||
},
|
||||
{ text: 'ADOS-2', bold: true, fontSize: 14, margin: [0, 12, 0, 5] },
|
||||
'autism · CSS 7',
|
||||
{
|
||||
layout: 'lightHorizontalLines',
|
||||
table: {
|
||||
headerRows: 1,
|
||||
widths: ['*', 'auto'],
|
||||
body: [
|
||||
['Ítem', 'Puntuación'],
|
||||
['A-7 Señalar', '2'],
|
||||
['A-8 Gestos', '—'],
|
||||
['ignoring', '1'],
|
||||
],
|
||||
},
|
||||
},
|
||||
{ text: 'Advertencias', bold: true, fontSize: 14, margin: [0, 12, 0, 5] },
|
||||
{ ul: ['sin curva en producción para spindles_n2'] },
|
||||
]);
|
||||
});
|
||||
|
||||
it('marks an invalid study with its error and no ADOS-2 or warnings', () => {
|
||||
const content = previewPdfContent({
|
||||
eeg: { ...result.eeg, valid: false, error: 'sin canales', checks: [], metrics: [] },
|
||||
ados2: null,
|
||||
warnings: [],
|
||||
});
|
||||
expect(content).toEqual([
|
||||
{ text: 'Vista previa del estudio EEG', fontSize: 18, bold: true },
|
||||
'complete · No válido',
|
||||
'sin canales',
|
||||
{ text: 'Comprobaciones', bold: true, fontSize: 14, margin: [0, 12, 0, 5] },
|
||||
'—',
|
||||
{ text: 'Métricas', bold: true, fontSize: 14, margin: [0, 12, 0, 5] },
|
||||
'—',
|
||||
]);
|
||||
});
|
||||
|
||||
it('names the file by domain, page and day only', () => {
|
||||
expect(previewPdfName(new Date('2026-11-30T12:00:00Z'))).toBe('tea-gobernanza-2026-11-30');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user