feat(ui): mejorar presentacion y disponibilidad inicial de KPI

This commit is contained in:
Angel Capetillo Zavala
2026-10-14 13:00:54 -06:00
parent 69afcc7fdb
commit 4685a91a7c
19 changed files with 466 additions and 102 deletions
@@ -32,7 +32,7 @@ describe('UX-06E.D.3.A catálogo permanentemente desplegado', () => {
fixture = TestBed.createComponent(IndicadoresPage); page = fixture.componentInstance; vi.spyOn(page as unknown as { evaluateVisibility(): void }, 'evaluateVisibility').mockImplementation(() => {});
http = TestBed.inject(HttpTestingController);
});
afterEach(() => { fixture.destroy(); http.verify(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });
afterEach(() => { http.match(r => r.url.endsWith('/datos')).forEach(r => r.flush('missing', { status: 404, statusText: 'Not Found' })); fixture.destroy(); http.verify(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });
function load(items: Indicador[] = [item, second], domain = 'tea') {
http.expectOne('/' + domain + '/indicadores').flush(items); fixture.detectChanges();
}
@@ -43,34 +43,26 @@ describe('UX-06E.D.3.A catálogo permanentemente desplegado', () => {
function flushAll() { http.match(r => r.url.includes('/figuras/')).forEach(r => r.flush({ data: [{ y: [0, null] }], layout: {} })); fixture.detectChanges(); }
function control(index = 0) { return fixture.debugElement.queryAll(By.directive(IndicadorPeriodFilters))[index].componentInstance as IndicadorPeriodFilters; }
it.each(['tea'] as const)('D.1 muestra dos KPI pendientes propios de %s fuera del catálogo', domain => {
if (domain !== 'tea') {
const initial = http.expectOne('/tea/indicadores');
page.changeDominio(domain); expect(initial.cancelled).toBe(true);
}
fixture.detectChanges();
const section = fixture.nativeElement.querySelector('.kpi-section') as HTMLElement;
expect(section.dataset['domain']).toBe(domain);
expect(section.querySelector('h2')?.textContent).toBe('Indicadores destacados — Vista preliminar');
expect(section.textContent).toContain('Muestra visual de ' + page.domainLabels[domain]);
const kpis = section.querySelectorAll('app-indicador-kpi-card');
expect(Array.from(kpis).map(kpi => kpi.querySelector('h3')?.textContent)).toEqual(['Indicador destacado 1', 'Indicador destacado 2']);
expect(Array.from(kpis).map(kpi => kpi.querySelector('.kpi-state')?.textContent)).toEqual(['Pendiente de definición', 'Pendiente de definición']);
expect(section.querySelector('.value, button, input, app-plotly-chart')).toBeNull();
expect(section.textContent).not.toContain('publicados');
load([], domain); expect(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card')).toHaveLength(2);
http.expectNone(() => true);
it('KPI-DYNAMIC TEA no deja sección, encabezado, tarjetas ni grid residual', () => {
load();
expect(fixture.nativeElement.querySelector('.kpi-section, #kpi-section-title, .kpi-grid, app-indicador-kpi-card')).toBeNull();
expect(fixture.nativeElement.textContent).not.toContain('Indicadores destacados');
http.expectNone(r => r.url.endsWith('/datos'));
});
it('D.1 conserva KPI durante carga, error, reintento y catálogo vacío sin HTTP propio', () => {
it('KPI-DYNAMIC distingue carga, error y catálogo vacío confirmado', () => {
fixture.detectChanges();
const kpis = Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'));
expect(kpis).toHaveLength(2);
expect(page.catalogLoading()).toBe(true);
expect(fixture.nativeElement.textContent).toContain('Cargando catálogo');
expect(fixture.nativeElement.textContent).not.toContain('No hay indicadores disponibles');
http.expectOne('/tea/indicadores').flush('private', { status: 500, statusText: 'Error' }); fixture.detectChanges();
expect(Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'))).toEqual(kpis);
page.retryCatalog(); fixture.detectChanges();
expect(Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'))).toEqual(kpis);
load([]); expect(Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'))).toEqual(kpis);
expect(fixture.nativeElement.querySelector('.catalog-count')).toBeNull(); http.expectNone(() => true);
expect(page.catalogError()).toBeTruthy();
expect(fixture.nativeElement.querySelector('[role="alert"]')).toBeTruthy();
expect(fixture.nativeElement.textContent).not.toContain('No hay indicadores disponibles');
page.retryCatalog(); fixture.detectChanges(); load([]);
expect(page.catalogLoading()).toBe(false); expect(page.catalogError()).toBe('');
expect(fixture.nativeElement.textContent).toContain('No hay indicadores disponibles');
expect(fixture.nativeElement.querySelector('.kpi-section')).toBeNull();
http.expectNone(() => true);
});
it('D.1 separa secciones y conserva tarjetas, orden, identidades y figuras dentro del grid', () => {
load(); const before = cards();
@@ -79,7 +71,7 @@ describe('UX-06E.D.3.A catálogo permanentemente desplegado', () => {
expect(grid.children).toHaveLength(2);
expect(Array.from(grid.children).every(host => host.tagName === 'APP-INDICADOR-CATALOG-CARD')).toBe(true);
const sections = fixture.nativeElement.querySelectorAll('.dashboard > section') as NodeListOf<HTMLElement>;
expect(Array.from(sections).map(section => section.getAttribute('aria-labelledby'))).toEqual(['global-filters-title', 'kpi-section-title', 'graphic-section-title']);
expect(Array.from(sections).map(section => section.getAttribute('aria-labelledby'))).toEqual(['global-filters-title', 'graphic-section-title']);
expect(fixture.nativeElement.querySelector('.catalog-count').textContent.trim()).toBe('2 indicadores publicados');
expect(getComputedStyle(fixture.nativeElement.querySelector('.catalog-count')).textAlign).toBe('right');
toggle(0); toggle(1); flushAll();