feat(ui): mejorar periodos KPI y presentacion del dashboard

This commit is contained in:
Angel Capetillo Zavala
2026-10-14 11:46:17 -06:00
parent 9fcc65d84f
commit 69afcc7fdb
26 changed files with 778 additions and 604 deletions
@@ -1,3 +1,4 @@
import { periodAvailabilityProvider } from './indicadores-periodos.testing';
import { TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
@@ -14,6 +15,7 @@ describe('UX-05B ciclo de vida con componentes Plotly y runtime simulado', () =>
const runtime = { react: vi.fn(), purge: vi.fn(), Plots: { resize: vi.fn() } };
const disconnects: ReturnType<typeof vi.fn>[] = [];
beforeEach(() => {
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
vi.resetAllMocks(); disconnects.length = 0;
runtime.react.mockResolvedValue(undefined); runtime.Plots.resize.mockResolvedValue(undefined);
vi.stubGlobal('ResizeObserver', class {
@@ -21,12 +23,13 @@ describe('UX-05B ciclo de vida con componentes Plotly y runtime simulado', () =>
// Material outline labels also observe size; track only Plotly hosts here.
observe = vi.fn((target: Element) => { if (target.classList.contains('plot')) disconnects.push(this.disconnect); });
});
TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting(),
TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting(), periodAvailabilityProvider,
{ provide: PLOTLY_LOADER, useValue: () => Promise.resolve(runtime) }] });
fixture = TestBed.createComponent(IndicadoresPage); http = TestBed.inject(HttpTestingController);
fixture = TestBed.createComponent(IndicadoresPage);
vi.spyOn(fixture.componentInstance as unknown as { evaluateVisibility(): void }, 'evaluateVisibility').mockImplementation(() => {}); http = TestBed.inject(HttpTestingController);
http.expectOne('/tea/indicadores').flush([{ id: 'i', titulo: 'I', contrato: 'C1', figuras: ['f', 'g'], tipos_periodo: ['semestre'] }, { id: 'j', titulo: 'J', contrato: 'C1', figuras: ['g'], tipos_periodo: ['semestre'] }]);
fixture.detectChanges();
for (const entry of fixture.debugElement.queryAll(By.directive(IndicadorCatalogCard))) (entry.componentInstance as IndicadorCatalogCard).toggle();
for (const entry of fixture.debugElement.queryAll(By.directive(IndicadorCatalogCard))) (entry.componentInstance as IndicadorCatalogCard).setVisible(true);
fixture.detectChanges();
});
afterEach(() => { fixture.destroy(); http.verify(); vi.unstubAllGlobals(); });
@@ -42,7 +45,7 @@ describe('UX-05B ciclo de vida con componentes Plotly y runtime simulado', () =>
expect(hosts[0]).not.toBe(hosts[1]); expect(hosts[0].getAttribute('aria-label')).toBe('tea · i · f');
expect(hosts[1].getAttribute('aria-label')).toBe('tea · j · g');
const card = fixture.debugElement.query(By.directive(IndicadorCatalogCard)).componentInstance as IndicadorCatalogCard;
card.toggle(); fixture.detectChanges();
fixture.componentInstance.catalog.set(fixture.componentInstance.catalog().slice(1)); fixture.detectChanges();
expect(runtime.purge).toHaveBeenCalledWith(hosts[0]);
expect(runtime.purge).not.toHaveBeenCalledWith(hosts[1]);
expect(disconnects[0]).toHaveBeenCalledTimes(1); expect(disconnects[1]).not.toHaveBeenCalled();