feat(ui): incorporar selector de figuras KPI y fijacion de indicadores
This commit is contained in:
@@ -16,7 +16,7 @@ import { PlotlyChart } from '../../shared/plotly/plotly-chart';
|
||||
import { Indicador, PlotlyFigure } from './indicadores.models';
|
||||
import { syntheticCatalogs } from './indicadores.synthetic-fixtures';
|
||||
|
||||
@Component({ selector: 'app-plotly-chart', inputs: ['figure', 'label'], template: '' })
|
||||
@Component({ selector: 'app-plotly-chart', inputs: ['figure', 'label', 'showNotes'], template: '' })
|
||||
class ChartStub { figure?: PlotlyFigure; }
|
||||
const item: Indicador = { id: 'i1', titulo: 'Uno', contrato: 'C1', figuras: ['f1', 'f2'], tipos_periodo: ['semestre', 'mes'] };
|
||||
const second: Indicador = { ...item, id: 'i2', titulo: 'Dos', figuras: ['g'] };
|
||||
@@ -41,7 +41,7 @@ describe('UX-05B catálogo expandible', () => {
|
||||
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', 'cacu', 'cama'] as const)('D.1 muestra dos KPI pendientes propios de %s fuera del catálogo', domain => {
|
||||
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);
|
||||
@@ -81,8 +81,8 @@ describe('UX-05B catálogo expandible', () => {
|
||||
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();
|
||||
expect(Array.from(grid.children).map(host => host.querySelectorAll('app-indicador-figure-panel').length)).toEqual([2, 1]);
|
||||
expect(panels().map(panel => panel.figuraId)).toEqual(['f1', 'f2', 'g']);
|
||||
expect(Array.from(grid.children).map(host => host.querySelectorAll('app-indicador-figure-panel').length)).toEqual([1, 1]);
|
||||
expect(panels().map(panel => panel.figuraId)).toEqual(['f1', 'g']);
|
||||
expect(cards()).toEqual(before); expect(cards().every(card => card.expanded)).toBe(true);
|
||||
http.expectNone(() => true);
|
||||
});
|
||||
@@ -119,7 +119,7 @@ describe('UX-05B catálogo expandible', () => {
|
||||
expect(button.getAttribute('aria-label')).toContain('Contraer tea · i1 · Uno');
|
||||
expect(header.textContent).not.toContain('Contrato');
|
||||
expect(host.querySelector('.catalog-metadata')?.textContent).toContain('Contrato C1 · 2 figuras publicadas');
|
||||
expect(host.querySelectorAll('app-indicador-figure-panel')).toHaveLength(2);
|
||||
expect(host.querySelectorAll('app-indicador-figure-panel')).toHaveLength(1);
|
||||
button.click(); fixture.detectChanges();
|
||||
expect(host.querySelector('.catalog-metadata')).toBeNull();
|
||||
expect(host.querySelectorAll('app-indicador-figure-panel')).toHaveLength(0);
|
||||
@@ -173,9 +173,9 @@ describe('UX-05B catálogo expandible', () => {
|
||||
expect(panels()).toHaveLength(0); http.expectNone(r => r.url.includes('/figuras/'));
|
||||
if (!count) expect(fixture.nativeElement.textContent).toContain('No hay indicadores disponibles');
|
||||
});
|
||||
it('abrir manualmente un indicador consulta exactamente una vez cada figura publicada', () => {
|
||||
load([item]); toggle(); expect(cards()[0].expanded).toBe(true); expect(panels()).toHaveLength(2);
|
||||
request('f1').flush({ data: [], layout: {} }); request('f2').flush({ data: [], layout: {} });
|
||||
it('abrir manualmente consulta exactamente una vez la primera figura publicada', () => {
|
||||
load([item]); toggle(); expect(cards()[0].expanded).toBe(true); expect(panels()).toHaveLength(1);
|
||||
request('f1').flush({ data: [], layout: {} });
|
||||
fixture.detectChanges(); fixture.detectChanges(); http.expectNone(() => true);
|
||||
});
|
||||
it('el cierre manual se conserva al volver sin consultar figuras', () => {
|
||||
@@ -189,22 +189,22 @@ describe('UX-05B catálogo expandible', () => {
|
||||
expect(panels()).toHaveLength(0); http.expectNone(() => true);
|
||||
});
|
||||
it('varias tarjetas y figuras abiertas mantienen solicitudes concurrentes independientes', () => {
|
||||
load(); toggle(0); const a = request('f1'), b = request('f2'); toggle(1); const c = request('g');
|
||||
expect(a.cancelled).toBe(false); expect(b.cancelled).toBe(false);
|
||||
b.flush({ data: [{ y: [2] }], layout: {} }); c.flush({ data: [{ y: [3] }], layout: {} });
|
||||
load(); toggle(0); const a = request('f1'); toggle(1); const c = request('g');
|
||||
expect(a.cancelled).toBe(false);
|
||||
c.flush({ data: [{ y: [3] }], layout: {} });
|
||||
a.flush({ data: [{ y: [1] }], layout: {} });
|
||||
expect(panels().map(p => p.result().figure?.data[0]['y'])).toEqual([[1], [2], [3]]);
|
||||
expect(panels().map(p => p.result().figure?.data[0]['y'])).toEqual([[1], [3]]);
|
||||
expect(cards().every(c => c.expanded)).toBe(true);
|
||||
});
|
||||
it('contraer cancela solo sus figuras, descarta respuestas y destruye paneles', () => {
|
||||
load(); toggle(); toggle(1); const a = request('f1'), b = request('f2'), c = request('g');
|
||||
toggle(); expect(a.cancelled).toBe(true); expect(b.cancelled).toBe(true); expect(c.cancelled).toBe(false);
|
||||
load(); toggle(); toggle(1); const a = request('f1'), c = request('g');
|
||||
toggle(); expect(a.cancelled).toBe(true); expect(c.cancelled).toBe(false);
|
||||
expect(() => a.flush({ data: [{ y: [99] }], layout: {} })).toThrow();
|
||||
expect(panels()).toHaveLength(1); c.flush({ data: [{ y: [3] }], layout: {} });
|
||||
expect(panels()[0].result().figure?.data[0]['y']).toEqual([3]);
|
||||
});
|
||||
it('404 y reintento afectan solo una figura y 200 sin puntos sigue siendo resultado', () => {
|
||||
load([item]); toggle(); const a = request('f1'), b = request('f2');
|
||||
load(); toggle(); toggle(1); const a = request('f1'), b = request('g');
|
||||
a.flush('private', { status: 404, statusText: 'Not Found' });
|
||||
b.flush({ data: [{ y: [null] }], layout: {} }); fixture.detectChanges();
|
||||
expect(panels()[0].result().status).toBe('error'); expect(panels()[1].result().status).toBe('ready');
|
||||
@@ -216,14 +216,14 @@ describe('UX-05B catálogo expandible', () => {
|
||||
expect(fixture.debugElement.queryAll(By.directive(IndicadorPeriodFilters))).toHaveLength(1);
|
||||
a.changeMode('manual'); a.year = '2025'; a.unit = 'S1'; a.add(); http.expectNone(() => true);
|
||||
page.applyFilters(); fixture.detectChanges();
|
||||
const appliedA = request('f1'), appliedB = request('f2');
|
||||
expect(appliedA.request.params.get('periodos')).toBe('2025-S1'); expect(appliedB.request.params.get('periodos')).toBe('2025-S1');
|
||||
appliedA.flush({ data: [], layout: {} }); appliedB.flush({ data: [], layout: {} }); a.unit = 'S2'; a.add();
|
||||
const appliedA = request('f1');
|
||||
expect(appliedA.request.params.get('periodos')).toBe('2025-S1');
|
||||
appliedA.flush({ data: [], layout: {} }); a.unit = 'S2'; a.add();
|
||||
page.changeTema('oscuro'); fixture.detectChanges();
|
||||
const themedA = request('f1'), themedB = request('f2');
|
||||
expect(themedA.request.params.get('periodos')).toBe('2025-S1'); expect(themedB.request.params.get('periodos')).toBe('2025-S1');
|
||||
const themedA = request('f1');
|
||||
expect(themedA.request.params.get('periodos')).toBe('2025-S1');
|
||||
expect(themedA.request.params.get('tema')).toBe('oscuro'); expect(a.selectedPeriods).toEqual(['2025-S1', '2025-S2']);
|
||||
themedA.flush({ data: [], layout: {} }); themedB.flush({ data: [], layout: {} });
|
||||
themedA.flush({ data: [], layout: {} });
|
||||
});
|
||||
it('UX-06D expandir metodología conserva panel, figura y borrador sin generar HTTP', () => {
|
||||
load([{ ...item, contrato: 'C2', figuras: ['fig_c2_apiladas'] }]); toggle(); flushAll();
|
||||
@@ -242,27 +242,27 @@ describe('UX-05B catálogo expandible', () => {
|
||||
http.expectNone(() => true);
|
||||
}
|
||||
});
|
||||
it('cerrar y reabrir conserva borrador general y consulta aplicado en ambas figuras', () => {
|
||||
it('cerrar y reabrir conserva borrador general y consulta aplicado en la figura seleccionada', () => {
|
||||
load([item]); toggle(); flushAll(); const a = control(); a.changeMode('manual'); a.year = '2025'; a.unit = 'S1'; a.add();
|
||||
page.applyFilters(); fixture.detectChanges(); flushAll(); a.unit = 'S2'; a.add();
|
||||
toggle(); toggle();
|
||||
const restored = request('f1'), other = request('f2');
|
||||
expect(restored.request.params.get('periodos')).toBe('2025-S1'); expect(other.request.params.get('periodos')).toBe('2025-S1');
|
||||
const restored = request('f1');
|
||||
expect(restored.request.params.get('periodos')).toBe('2025-S1');
|
||||
expect(control()).toBe(a); expect(control().selectedPeriods).toEqual(['2025-S1', '2025-S2']);
|
||||
restored.flush({ data: [], layout: {} }); other.flush({ data: [], layout: {} });
|
||||
restored.flush({ data: [], layout: {} });
|
||||
});
|
||||
it('tema solo consulta paneles abiertos, cancela los anteriores y no repite el mismo tema', () => {
|
||||
load(); toggle(); const a = request('f1'), b = request('f2');
|
||||
page.changeTema('oscuro'); fixture.detectChanges(); expect(a.cancelled).toBe(true); expect(b.cancelled).toBe(true);
|
||||
const darkA = request('f1'), darkB = request('f2');
|
||||
load(); toggle(); const a = request('f1');
|
||||
page.changeTema('oscuro'); fixture.detectChanges(); expect(a.cancelled).toBe(true);
|
||||
const darkA = request('f1');
|
||||
expect(darkA.request.params.get('tema')).toBe('oscuro'); http.expectNone(r => r.url.endsWith('/g'));
|
||||
darkA.flush({ data: [], layout: {} }); darkB.flush({ data: [], layout: {} });
|
||||
darkA.flush({ data: [], layout: {} });
|
||||
page.changeTema('oscuro'); fixture.detectChanges(); http.expectNone(() => true);
|
||||
toggle(1); const later = request('g'); expect(later.request.params.get('tema')).toBe('oscuro'); later.flush({ data: [], layout: {} });
|
||||
});
|
||||
it('salir del dominio cancela paneles y catálogos obsoletos', () => {
|
||||
load(); toggle(); const a = request('f1'), b = request('f2');
|
||||
page.changeDominio('cacu'); fixture.detectChanges(); expect(a.cancelled).toBe(true); expect(b.cancelled).toBe(true);
|
||||
load(); toggle(); const a = request('f1');
|
||||
page.changeDominio('cacu'); fixture.detectChanges(); expect(a.cancelled).toBe(true);
|
||||
const oldCatalog = http.expectOne('/cacu/indicadores'); page.changeDominio('cama'); fixture.detectChanges();
|
||||
expect(oldCatalog.cancelled).toBe(true); load(syntheticCatalogs.cama, 'cama'); flushAll();
|
||||
expect(() => oldCatalog.flush(syntheticCatalogs.cacu)).toThrow(); expect(page.dominio).toBe('cama');
|
||||
@@ -275,7 +275,7 @@ describe('UX-05B catálogo expandible', () => {
|
||||
expect(cards()[0].expanded).toBe(true); expect(cards()[1].expanded).toBe(false);
|
||||
expect(page.tema).toBe('oscuro'); expect(cards()[0].awaitingFigures).toBe(true); http.expectNone(() => true);
|
||||
toggle(); const a = request('f1'); expect(a.request.params.has('periodos')).toBe(false);
|
||||
expect(control().entry.draft.mode).toBe('empty'); a.flush({ data: [], layout: {} }); request('f2').flush({ data: [], layout: {} });
|
||||
expect(control().entry.draft.mode).toBe('empty'); a.flush({ data: [], layout: {} });
|
||||
page.changeDominio('cacu'); fixture.detectChanges(); load(syntheticCatalogs.cacu, 'cacu');
|
||||
expect(cards()[0].expanded).toBe(false); expect(page.tema).toBe('claro'); http.expectNone(() => true);
|
||||
});
|
||||
@@ -303,8 +303,8 @@ describe('UX-05B catálogo expandible', () => {
|
||||
expect(buttons[0].getAttribute('aria-label')).not.toBe(buttons[1].getAttribute('aria-label'));
|
||||
});
|
||||
it('copia de presentación y gráficos independientes conservan JSON binario, notas, ceros y nulos', () => {
|
||||
load([item]); toggle(); const raw = { data: [{ y: { dtype: 'f8', bdata: 'AAAAAAAAAAA=' }, customdata: [[0, null]] }], layout: { annotations: [{ text: 'Nota' }] } };
|
||||
const before = JSON.stringify(raw); request('f1').flush(raw); request('f2').flush({ data: [{ y: [0, null] }], layout: {} }); fixture.detectChanges();
|
||||
load(); toggle(0); toggle(1); const raw = { data: [{ y: { dtype: 'f8', bdata: 'AAAAAAAAAAA=' }, customdata: [[0, null]] }], layout: { annotations: [{ text: 'Nota' }] } };
|
||||
const before = JSON.stringify(raw); request('f1').flush(raw); request('g').flush({ data: [{ y: [0, null] }], layout: {} }); fixture.detectChanges();
|
||||
expect(JSON.stringify(raw)).toBe(before); expect(panels()[0].result().figure).toEqual(raw);
|
||||
const charts = fixture.debugElement.queryAll(By.directive(ChartStub)); expect(charts).toHaveLength(2);
|
||||
expect(charts[0].componentInstance.figure).not.toBe(charts[1].componentInstance.figure);
|
||||
|
||||
Reference in New Issue
Block a user