feat(indicadores): agregar prototipo de dashboard TEA
Implementa el prototipo del dashboard de indicadores TEA. - Integra catálogo y figuras mediante WebApi. - Incorpora visualizaciones interactivas con Plotly.js. - Agrega controles de indicadores, figuras, periodos y temas. - Implementa estados de carga, errores y diseño responsive. - Incluye explicaciones para los contratos C1, C2 y C3r. - Incorpora pruebas unitarias y de integración de componentes. Prototipo para investigación con datos sintéticos.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { vi } from 'vitest';
|
||||
import { PlotlyChart } from './plotly-chart';
|
||||
import { PLOTLY_LOADER } from './plotly-runtime';
|
||||
const mocks = { load: vi.fn(), react: vi.fn(), purge: vi.fn(), resize: vi.fn() };
|
||||
|
||||
describe('PlotlyChart lifecycle', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
mocks.react.mockResolvedValue(undefined);
|
||||
mocks.resize.mockResolvedValue(undefined);
|
||||
mocks.load.mockResolvedValue({ react: mocks.react, purge: mocks.purge, Plots: { resize: mocks.resize } });
|
||||
TestBed.configureTestingModule({ imports: [PlotlyChart], providers: [{ provide: PLOTLY_LOADER, useValue: mocks.load }] });
|
||||
});
|
||||
it('monta el host, actualiza inputs y desconecta ResizeObserver', async () => {
|
||||
const disconnect = vi.fn(); const observe = vi.fn();
|
||||
vi.stubGlobal('ResizeObserver', class { observe = observe; disconnect = disconnect; });
|
||||
const fixture = TestBed.createComponent(PlotlyChart);
|
||||
fixture.componentRef.setInput('figure', { data: [], layout: {} });
|
||||
fixture.detectChanges(); await fixture.whenStable(); for (let i = 0; i < 12; i++) await Promise.resolve();
|
||||
expect(observe).toHaveBeenCalledWith(fixture.nativeElement.querySelector('.plot'));
|
||||
expect(mocks.react).toHaveBeenCalledTimes(1);
|
||||
fixture.componentRef.setInput('figure', { data: [{ y: [1] }], layout: {} });
|
||||
fixture.detectChanges(); await fixture.whenStable(); for (let i = 0; i < 12; i++) await Promise.resolve();
|
||||
expect(mocks.react).toHaveBeenCalledTimes(2);
|
||||
fixture.destroy(); expect(disconnect).toHaveBeenCalled(); expect(mocks.purge).toHaveBeenCalled();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
it('muestra error asíncrono y se recupera con reintento', async () => {
|
||||
mocks.react.mockRejectedValueOnce(new Error('render failed'));
|
||||
const fixture = TestBed.createComponent(PlotlyChart);
|
||||
fixture.componentRef.setInput('figure', { data: [], layout: {} });
|
||||
fixture.detectChanges(); await fixture.whenStable(); for (let i = 0; i < 12; i++) await Promise.resolve(); fixture.detectChanges();
|
||||
expect(fixture.nativeElement.textContent).toContain('No se pudo representar');
|
||||
fixture.nativeElement.querySelector('button').click();
|
||||
await fixture.whenStable(); for (let i = 0; i < 12; i++) await Promise.resolve(); fixture.detectChanges();
|
||||
expect(fixture.componentInstance.status()).toBe('ready'); fixture.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user