957f4cd024
- Leyenda con botones, como la distribución de resultados citológicos de cáncer cervicouterino: el grupo o la categoría elegida conserva su color, el resto se atenúa, «Volver» retrocede y un clic en la figura equivale al botón (indicadores-highlight.ts). - M21, M22 y M24 con botones por grupo de edad; el centro de las donas muestra la selección. - En TEA, la dona C2 de un periodo (M23) se dibuja con ambos anillos y botones, y sus barras también los tienen.
94 lines
7.0 KiB
TypeScript
94 lines
7.0 KiB
TypeScript
import { Component } from '@angular/core';
|
|
import { TestBed } from '@angular/core/testing';
|
|
import { provideHttpClient } from '@angular/common/http';
|
|
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
|
import { IndicadorFigurePanel } from './indicador-figure-panel';
|
|
import { IndicadorFigureCard } from './indicador-figure-card';
|
|
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
|
|
import { GlobalApplied } from './indicadores-memory';
|
|
import { c2Fixture } from './indicadores-c2-adapter.testing';
|
|
import { IndicadoresSnapshots } from './indicadores-snapshots';
|
|
import { READABLE_VISUAL_PROFILE, BASE_VISUAL_PROFILE } from './indicadores-visual-profile';
|
|
|
|
@Component({ selector: 'app-plotly-chart', inputs: ['figure','label','showNotes'], template: '' })
|
|
class ChartStub {}
|
|
const applied: GlobalApplied = { tipo: 'semestre', selection: { mode: 'explicit', periodos: ['2025-S2'] }, revision: 1 };
|
|
const item = { id: 'i1', titulo: 'Distribución sintética', contrato: 'C2', figuras: ['fig_c2_donas','fig_c2_barras'], tipos_periodo: ['semestre'] };
|
|
describe('estrategia C2 /datos y respaldo /figuras', () => {
|
|
let fixture: ReturnType<typeof TestBed.createComponent<IndicadorFigurePanel>>, http: HttpTestingController;
|
|
beforeEach(() => {
|
|
TestBed.configureTestingModule({ imports: [IndicadorFigurePanel], providers: [provideHttpClient(),provideHttpClientTesting()] });
|
|
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
|
http = TestBed.inject(HttpTestingController); fixture = TestBed.createComponent(IndicadorFigurePanel);
|
|
for (const [name,value] of Object.entries({ dominio: 'tea', indicador: item, figuraId: 'fig_c2_donas', tema: 'claro', applied })) fixture.componentRef.setInput(name,value);
|
|
});
|
|
afterEach(() => { fixture.destroy(); http.verify(); });
|
|
const dataRequest = () => http.expectOne(r => r.url.endsWith('/datos'));
|
|
it('reutiliza payload del KPI y conserva notas al adaptar perfil y ancho, sin /figuras', () => {
|
|
TestBed.inject(IndicadoresSnapshots).datos('tea','i1','semestre',['2025-S2']).subscribe(); dataRequest().flush(c2Fixture());
|
|
fixture.detectChanges(); expect(fixture.componentInstance.result().source).toBe('datos'); http.expectNone(() => true);
|
|
for (const profile of [BASE_VISUAL_PROFILE,READABLE_VISUAL_PROFILE]) {
|
|
fixture.componentRef.setInput('visualProfile',profile); fixture.detectChanges(); fixture.componentInstance.updatePlotWidth(320);
|
|
expect(fixture.componentInstance.result().footnotes).toEqual(c2Fixture().notas);
|
|
expect(fixture.nativeElement.textContent).toContain('Nota metodológica publicada.'); http.expectNone(() => true);
|
|
}
|
|
});
|
|
it.each([404,500,503])('HTTP %s en datos es error visible, no figura de respaldo', status => {
|
|
fixture.detectChanges(); dataRequest().flush({}, { status, statusText: 'Failure' }); fixture.detectChanges();
|
|
expect(fixture.componentInstance.result().status).toBe('error'); expect(fixture.nativeElement.querySelector('[role="alert"]')).toBeTruthy(); http.expectNone(() => true);
|
|
fixture.componentInstance.requestFigure(); dataRequest().flush(c2Fixture()); expect(fixture.componentInstance.result().source).toBe('datos');
|
|
});
|
|
it('respuesta malformada/contrato incorrecto no oculta error mediante respaldo', () => {
|
|
fixture.detectChanges(); dataRequest().flush({ ...c2Fixture(), contrato: 'C1' });
|
|
expect(fixture.componentInstance.result().status).toBe('error'); http.expectNone(() => true);
|
|
});
|
|
it.each(['suppressed','null','metadata','multiple-periods'])('caso %s usa figura publicada y conserva JSON completo', kind => {
|
|
fixture.detectChanges(); const data = c2Fixture();
|
|
if (kind === 'suppressed') data.filas[0]['suprimido'] = 1;
|
|
if (kind === 'null') data.filas[0]['n'] = null;
|
|
if (kind === 'metadata') delete data['unidad'];
|
|
if (kind === 'multiple-periods') { data.periodos = []; data.filas = []; }
|
|
dataRequest().flush(data);
|
|
const original = { data: [{type:'bar',x:[null],y:['Oculto']}],layout: {}, frames: [], unknown: { retained:true } };
|
|
http.expectOne(r => r.url.includes('/figuras/')).flush(original);
|
|
expect(fixture.componentInstance.result()).toMatchObject({ source:'figuras',figure:original });
|
|
expect(fixture.componentInstance.result().fallbackReason).toBeTruthy(); http.expectNone(() => true);
|
|
});
|
|
it('un error de /figuras durante respaldo también queda visible', () => {
|
|
fixture.detectChanges(); dataRequest().flush({ ...c2Fixture(), unidad: null });
|
|
http.expectOne(r => r.url.includes('/figuras/')).flush({}, {status:503,statusText:'Failure'});
|
|
expect(fixture.componentInstance.result().status).toBe('error');
|
|
});
|
|
it('TEA: dona de un periodo con ambos anillos y botones para resaltar grupos y categorías', () => {
|
|
fixture.detectChanges(); dataRequest().flush(c2Fixture());
|
|
const result = fixture.componentInstance.result();
|
|
expect(result.status).toBe('ready');
|
|
expect(result.hierarchy).toBeUndefined();
|
|
expect(result.figure?.data.map(t => t['name'])).toEqual(['centro', 'grupos', 'categorias']);
|
|
expect(result.highlight?.groups.length).toBeGreaterThan(0);
|
|
expect(result.highlight?.items.every(i => i.group)).toBe(true);
|
|
});
|
|
it('cambio de periodo cancela lectura, limpia selección y no expone snapshot previo', () => {
|
|
// TEA draws single-period C2 donuts with highlight buttons instead (indicadores-tea-c2.ts).
|
|
fixture.componentRef.setInput('dominio', 'cama');
|
|
fixture.detectChanges(); const old = dataRequest();
|
|
fixture.componentRef.setInput('applied', { ...applied, revision:2,selection:{mode:'explicit',periodos:['2026-S1']} }); fixture.detectChanges();
|
|
expect(old.cancelled).toBe(true); const current = dataRequest(); expect(current.request.params.get('periodos')).toBe('2026-S1');
|
|
const data = c2Fixture(); data.periodos = ['2026-S1']; data.filas.forEach(r => r['periodo'] = '2026-S1'); current.flush(data);
|
|
expect(fixture.componentInstance.result().figure?.layout['meta']).toMatchObject({period:'2026-S1'});
|
|
});
|
|
it('dominio y tema renuevan contexto sin mezclar transportes; tema reutiliza mismos datos', () => {
|
|
fixture.detectChanges(); dataRequest().flush(c2Fixture());
|
|
fixture.componentRef.setInput('tema','oscuro'); fixture.detectChanges();
|
|
expect(fixture.componentInstance.result().figure?.layout['paper_bgcolor']).toBe('#081839'); http.expectNone(() => true);
|
|
fixture.componentRef.setInput('dominio','cama'); fixture.detectChanges(); const next = dataRequest();
|
|
expect(next.request.url).toBe('/cama/indicadores/i1/datos'); next.flush(c2Fixture());
|
|
});
|
|
it('carga diferida no consulta datos ni figuras antes de activación', () => {
|
|
fixture.componentRef.setInput('visible',false); fixture.detectChanges(); http.expectNone(() => true);
|
|
expect(fixture.componentInstance.result().status).toBe('deferred');
|
|
fixture.componentRef.setInput('visible',true); fixture.detectChanges(); dataRequest().flush(c2Fixture());
|
|
expect(fixture.componentInstance.result().source).toBe('datos');
|
|
});
|
|
});
|