feat(ui): incorporar selector de figuras KPI y fijacion de indicadores

This commit is contained in:
Angel Capetillo Zavala
2026-10-13 22:34:57 -06:00
parent c4faa7d9f6
commit 9fcc65d84f
26 changed files with 723 additions and 85 deletions
@@ -14,7 +14,7 @@ import { Indicador } from './indicadores.models';
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
import { PLOTLY_LOADER } from '../../shared/plotly/plotly-runtime';
@Component({ selector: 'app-plotly-chart', inputs: ['figure', 'label'], template: '' })
@Component({ selector: 'app-plotly-chart', inputs: ['figure', 'label', 'showNotes'], template: '' })
class ChartStub {}
const items: Indicador[] = Array.from({ length: 5 }, (_, i) => ({
id: 'i' + i, titulo: 'Indicador ' + i, contrato: 'C1', figuras: ['f'], tipos_periodo: ['semestre', 'mes'],
@@ -103,6 +103,23 @@ describe('UX-06E.D.1.1 visibilidad controlada', () => {
expect(frames.size).toBe(0);
}
it('D.3.B fijar invalida la fila pendiente y aplica visibilidad actual sin anticipar carga', async () => {
await load();
positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await frame();
const original = cards();
original[4].host.nativeElement.querySelector<HTMLButtonElement>('.pin-toggle')!.click(); await render();
expect(cards()[0]).toBe(original[4]);
positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]);
http.expectNone(() => true); await frame(); http.expectNone(() => true);
await frame(); expect(cards()[0].expanded).toBe(true); expect(original[0].expanded).toBe(false);
http.expectOne(r => r.url.endsWith('/i4/figuras/f')).flush({ data: [], layout: {} }); await idle();
cards()[0].toggle(); await render();
original[0].host.nativeElement.querySelector<HTMLButtonElement>('.pin-toggle')!.click(); await render();
positions([[200, 0], [200, 650], [1000, 0], [1000, 650], [1200, 0]]); await confirm(); respond(); await idle();
expect(original[4].expanded).toBe(false); expect(memory.activation('tea', 'i4')).toBe('manual-closed');
http.expectNone(() => true);
});
it('observa sólo cabeceras gráficas con viewport, umbral y margen sticky medido', async () => {
await load();
expect(observer().options).toEqual({ root: null, threshold: 0.25, rootMargin: '-100px 0px 0px 0px' });
@@ -244,17 +261,16 @@ describe('UX-06E.D.1.1 visibilidad controlada', () => {
active.emit(target); sizeObserver.emit(); window.dispatchEvent(new Event('scroll'));
expect(frames.size).toBe(remaining); http.expectNone(() => true);
});
it('varias figuras mantienen errores y resultados independientes y se cancelan al cerrar', async () => {
it('apertura automática monta sólo la primera figura y el cierre cancela la seleccionada', async () => {
await load([{ ...items[0], figuras: ['f', 'g', 'h'] }]); positions([[200, 0]]); notify(); await confirm();
const requests = http.match(r => r.url.includes('/figuras/')); expect(requests).toHaveLength(3);
requests[0].flush('private', { status: 500, statusText: 'Error' }); requests[1].flush({ data: [{ y: [2] }], layout: {} }); await render();
expect(panels().map(panel => panel.result().status)).toEqual(['error', 'ready', 'loading']);
const filters = fixture.debugElement.query(By.directive(IndicadorPeriodFilters)).componentInstance as IndicadorPeriodFilters;
filters.changeMode('manual'); filters.year = '2025'; filters.unit = 'S1'; filters.add();
cards()[0].toggle(); await render(); expect(requests[2].cancelled).toBe(true);
const requests = http.match(r => r.url.includes('/figuras/')); expect(requests).toHaveLength(1);
requests[0].flush('private', { status: 500, statusText: 'Error' }); await render();
expect(panels().map(panel => panel.result().status)).toEqual(['error']);
cards()[0].selectFigure('g'); await render();
const current = http.expectOne(r => r.url.endsWith('/figuras/g'));
cards()[0].toggle(); await render(); expect(current.cancelled).toBe(true);
notify(); await idle(); http.expectNone(() => true); cards()[0].toggle(); await render();
expect(page.filters?.editors.semestre?.draft).toEqual({ mode: 'explicit', periodos: ['2025-S1'] });
expect(page.filters?.applied?.selection.mode).toBe('todos'); respond();
expect(panels()[0].figuraId).toBe('g'); respond();
});
it('fallback sin observers permite la apertura y cierre de una tarjeta pendiente', async () => {
http.expectOne('/tea/indicadores'); fixture.destroy(); vi.stubGlobal('IntersectionObserver', undefined); vi.stubGlobal('ResizeObserver', undefined); create();