a05717f92d
- Filtro general: «Intervalo de análisis» (Semestral/Mensual) en lugar de «Modalidad»; al cambiar de intervalo se elige el periodo más reciente. - Resumen de TEA: evaluaciones con o sin diagnóstico y diagnóstico positivo de TEA explícito. - Seguimiento: panel «Alteraciones del EEG» (exponente aperiódico, husos del sueño, entropía multiescala) con posibles efectos asociados. Datos de ejemplo, pendientes de validación médica. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
6.2 KiB
TypeScript
93 lines
6.2 KiB
TypeScript
import { kpiQueriesProvider, periodAvailabilityProvider } from './indicadores-periodos.testing';
|
|
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 { provideRouter, Router } from '@angular/router';
|
|
import { RouterTestingHarness } from '@angular/router/testing';
|
|
import { By } from '@angular/platform-browser';
|
|
import { routes } from '../../app.routes';
|
|
import { IndicadorCatalogCard } from './indicador-catalog-card';
|
|
import { IndicadorFigurePanel } from './indicador-figure-panel';
|
|
import { IndicadoresPage } from './indicadores-page';
|
|
import { IndicadorFigureCard } from './indicador-figure-card';
|
|
import { IndicadorPeriodFilters } from './indicador-period-filters';
|
|
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
|
|
import { PlotlyFigure } from './indicadores.models';
|
|
import { syntheticCatalogs } from './indicadores.synthetic-fixtures';
|
|
|
|
@Component({ selector: 'app-plotly-chart', inputs: ['figure', 'label', 'showNotes'], template: '' })
|
|
class ChartStub { figure?: PlotlyFigure; }
|
|
|
|
describe('UX-04 navegación Angular', () => {
|
|
let http: HttpTestingController;
|
|
async function setup() {
|
|
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
|
|
TestBed.configureTestingModule({ providers: [provideRouter(routes), provideHttpClient(), provideHttpClientTesting(), periodAvailabilityProvider, kpiQueriesProvider] });
|
|
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
|
http = TestBed.inject(HttpTestingController);
|
|
return RouterTestingHarness.create();
|
|
}
|
|
function load(domain: 'tea' | 'cacu' | 'cama', harness: RouterTestingHarness) {
|
|
http.expectOne('/' + domain + '/indicadores').flush(syntheticCatalogs[domain]);
|
|
harness.detectChanges();
|
|
const page = harness.routeDebugElement!.componentInstance as IndicadoresPage;
|
|
vi.spyOn(page as unknown as { evaluateVisibility(): void }, 'evaluateVisibility').mockImplementation(() => {});
|
|
const card = harness.routeDebugElement!.query(By.directive(IndicadorCatalogCard)).componentInstance as IndicadorCatalogCard;
|
|
if (!card.visible) { card.setVisible(true); harness.detectChanges(); }
|
|
const req = http.expectOne(r => r.url.includes('/figuras/'));
|
|
req.flush({ data: [{ y: [0, null] }], layout: {} });
|
|
return req;
|
|
}
|
|
afterEach(() => { http.verify(); vi.unstubAllGlobals(); });
|
|
it.each(['tea', 'cacu', 'cama'] as const)('navegación %s mantiene tres enlaces, estado, decoración y foco independiente', async domain => {
|
|
const harness = await setup();
|
|
await harness.navigateByUrl('/indicadores/' + domain, IndicadoresPage);
|
|
load(domain, harness); harness.detectChanges();
|
|
// Our shell keeps the domain nav on the page itself, see indicadores-page.html.
|
|
expect(harness.routeNativeElement!.querySelectorAll('nav.domain-nav a')).toHaveLength(3);
|
|
http.expectNone(() => true);
|
|
});
|
|
it('mantiene la ruta, restaura borradores y reconsulta la aplicación entre TEA/CaCu/CaMa', async () => {
|
|
const harness = await setup();
|
|
const tea = await harness.navigateByUrl('/indicadores/tea', IndicadoresPage);
|
|
load('tea', harness); harness.detectChanges();
|
|
const control = harness.routeDebugElement!.query(By.directive(IndicadorPeriodFilters)).componentInstance as IndicadorPeriodFilters;
|
|
control.select([]); control.year = '2025'; control.unit = 'S1'; control.add();
|
|
(harness.routeDebugElement!.componentInstance as IndicadoresPage).applyFilters(); harness.detectChanges();
|
|
http.expectOne(r => r.url.includes('/figuras/')).flush({ data: [], layout: {} });
|
|
control.year = '2025'; control.unit = 'S2'; control.add();
|
|
await harness.navigateByUrl('/indicadores/cacu', IndicadoresPage); load('cacu', harness);
|
|
await harness.navigateByUrl('/indicadores/cama', IndicadoresPage); load('cama', harness);
|
|
const restored = await harness.navigateByUrl('/indicadores/tea', IndicadoresPage);
|
|
const req = load('tea', harness);
|
|
expect(req.request.params.get('periodos')).toBe('2025-S1');
|
|
expect((harness.routeDebugElement!.componentInstance as IndicadoresPage).filters?.editors.semestre?.draft).toEqual({ mode: 'explicit', periodos: ['2025-S2'] });
|
|
expect(TestBed.inject(Router).url).toBe('/indicadores/tea');
|
|
});
|
|
it('un nuevo arranque conserva la URL de entrada y reinicia indicador, tema y filtros', async () => {
|
|
let harness = await setup();
|
|
const page = await harness.navigateByUrl('/indicadores/cacu', IndicadoresPage);
|
|
load('cacu', harness); harness.detectChanges();
|
|
page.changeTema('oscuro'); harness.detectChanges();
|
|
http.expectOne(r => r.url.includes('/figuras/')).flush({ data: [], layout: {} });
|
|
const control = harness.routeDebugElement!.query(By.directive(IndicadorPeriodFilters)).componentInstance as IndicadorPeriodFilters;
|
|
control.changeTipo('mes'); control.year = '2025'; control.unit = '01'; control.add();
|
|
(harness.routeDebugElement!.componentInstance as IndicadoresPage).applyFilters(); harness.detectChanges();
|
|
http.expectOne(r => r.url.includes('/figuras/')).flush({ data: [], layout: {} });
|
|
const url = TestBed.inject(Router).url;
|
|
http.match(r => r.url.endsWith('/datos')).forEach(r => r.flush('missing', { status: 404, statusText: 'Not Found' }));
|
|
http.verify(); TestBed.resetTestingModule();
|
|
harness = await setup();
|
|
const restarted = await harness.navigateByUrl(url, IndicadoresPage);
|
|
const req = load('cacu', harness);
|
|
expect(TestBed.inject(Router).url).toBe('/indicadores/cacu');
|
|
expect((harness.routeDebugElement!.query(By.directive(IndicadorCatalogCard)).componentInstance as IndicadorCatalogCard).visible).toBe(true);
|
|
expect(restarted.tema).toBe('claro');
|
|
expect((harness.routeDebugElement!.componentInstance as IndicadoresPage).filters?.tipo).toBe('semestre');
|
|
expect((harness.routeDebugElement!.componentInstance as IndicadoresPage).filters?.editors.mes?.draft.mode).toBe('empty');
|
|
expect(req.request.params.has('periodos')).toBe(false);
|
|
expect(req.request.params.get('tema')).toBe('claro');
|
|
});
|
|
});
|