feat(ui): incorporar filtros globales por dominio UX-06E.D.2

This commit is contained in:
Angel Capetillo Zavala
2026-10-13 19:45:48 -06:00
parent 98d0614d80
commit c4faa7d9f6
20 changed files with 467 additions and 218 deletions
@@ -77,7 +77,7 @@ describe('UX-05B catálogo expandible', () => {
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(['kpi-section-title', 'graphic-section-title']);
expect(Array.from(sections).map(section => section.getAttribute('aria-labelledby'))).toEqual(['global-filters-title', 'kpi-section-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();
@@ -157,7 +157,7 @@ describe('UX-05B catálogo expandible', () => {
it('UX-06D retira el selector visual, inicia claro y conserva oscuro sin recargar catálogo', async () => {
load();
await fixture.whenStable(); fixture.detectChanges();
expect(fixture.debugElement.query(By.directive(MatSelect))).toBeNull();
expect(fixture.nativeElement.querySelector('.global-filters mat-select')).toBeTruthy();
expect(fixture.nativeElement.textContent).not.toContain('Tema del dominio');
expect(page.tema).toBe('claro');
page.changeTema('oscuro'); fixture.detectChanges();
@@ -211,18 +211,18 @@ describe('UX-05B catálogo expandible', () => {
expect(fixture.nativeElement.textContent).toContain('No hay valores visibles');
panels()[0].requestFigure(); request('f1').flush({ data: [], layout: {} }); http.expectNone(() => true);
});
it('edición y aplicación son independientes por figura y tema utiliza aplicación', () => {
load([item]); toggle(); flushAll(); const a = control(), b = control(1);
it('un único borrador actualiza todas las figuras y tema usa aplicado', () => {
load([item]); toggle(); flushAll(); const a = control();
expect(fixture.debugElement.queryAll(By.directive(IndicadorPeriodFilters))).toHaveLength(1);
a.changeMode('manual'); a.year = '2025'; a.unit = 'S1'; a.add(); http.expectNone(() => true);
panels()[0].applyFilters(); const applied = request('f1'); expect(applied.request.params.get('periodos')).toBe('2025-S1');
applied.flush({ data: [], layout: {} }); a.unit = 'S2'; a.add();
b.changeTipo('mes'); b.year = '2026'; b.unit = '01'; b.add();
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();
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.has('periodos')).toBe(false);
expect(themedA.request.params.get('tema')).toBe('oscuro');
expect(a.selectedPeriods).toEqual(['2025-S1', '2025-S2']); expect(b.selectedPeriods).toEqual(['2026-01']);
expect(themedA.request.params.get('periodos')).toBe('2025-S1'); expect(themedB.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: {} });
});
it('UX-06D expandir metodología conserva panel, figura y borrador sin generar HTTP', () => {
@@ -230,7 +230,7 @@ describe('UX-05B catálogo expandible', () => {
const panel = panels()[0], chart = fixture.debugElement.query(By.directive(ChartStub)).componentInstance;
const filters = control();
filters.changeMode('manual'); filters.year = '2025'; filters.unit = 'S1'; filters.add();
const draft = structuredClone(filters.entry.draft), applied = structuredClone(panel.filters!.applied);
const draft = structuredClone(filters.entry.draft), applied = structuredClone(page.filters!.applied);
const result = panel.result();
const button = fixture.nativeElement.querySelector('.methodology-toggle') as HTMLButtonElement;
for (let i = 0; i < 2; i++) {
@@ -238,18 +238,17 @@ describe('UX-05B catálogo expandible', () => {
expect(button.getAttribute('aria-expanded')).toBe(i === 0 ? 'true' : 'false');
expect(panels()[0]).toBe(panel); expect(panel.result()).toBe(result);
expect(fixture.debugElement.query(By.directive(ChartStub)).componentInstance).toBe(chart);
expect(filters.entry.draft).toEqual(draft); expect(panel.filters!.applied).toEqual(applied);
expect(filters.entry.draft).toEqual(draft); expect(page.filters!.applied).toEqual(applied);
http.expectNone(() => true);
}
});
it('cerrar y reabrir restaura borrador y aplicado por figura sin confirmar borradores', () => {
it('cerrar y reabrir conserva borrador general y consulta aplicado en ambas figuras', () => {
load([item]); toggle(); flushAll(); const a = control(); a.changeMode('manual'); a.year = '2025'; a.unit = 'S1'; a.add();
panels()[0].applyFilters(); request('f1').flush({ data: [], layout: {} }); a.unit = 'S2'; a.add();
control(1).changeTipo('mes'); control(1).year = '2026'; control(1).unit = '01'; control(1).add();
page.applyFilters(); fixture.detectChanges(); flushAll(); a.unit = 'S2'; a.add();
toggle(); toggle();
const restored = request('f1'); expect(restored.request.params.get('periodos')).toBe('2025-S1');
const other = request('f2'); expect(other.request.params.has('periodos')).toBe(false);
expect(control().selectedPeriods).toEqual(['2025-S1', '2025-S2']); expect(control(1).selectedPeriods).toEqual(['2026-01']);
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');
expect(control()).toBe(a); expect(control().selectedPeriods).toEqual(['2025-S1', '2025-S2']);
restored.flush({ data: [], layout: {} }); other.flush({ data: [], layout: {} });
});
it('tema solo consulta paneles abiertos, cancela los anteriores y no repite el mismo tema', () => {
@@ -296,7 +295,7 @@ describe('UX-05B catálogo expandible', () => {
buttons[0].click(); fixture.detectChanges(); flushAll();
expect(buttons[0].getAttribute('aria-expanded')).toBe('true');
expect(document.getElementById(buttons[0].getAttribute('aria-controls')!)).toBeTruthy();
const input = fixture.nativeElement.querySelector('app-indicador-period-filters mat-select') as HTMLElement;
const input = fixture.nativeElement.querySelector('app-indicador-catalog-card .methodology-toggle') as HTMLElement;
input.focus(); expect(document.activeElement).toBe(input); cards()[0].toggle(); fixture.detectChanges();
expect(document.activeElement).toBe(buttons[0]);
const ids = Array.from(fixture.nativeElement.querySelectorAll('[id]') as NodeListOf<HTMLElement>).map(e => e.id);
@@ -315,7 +314,7 @@ describe('UX-05B catálogo expandible', () => {
it.each(['cacu', 'cama'] as const)('preserva advertencias y filtros mensuales de %s', domain => {
load([]); page.changeDominio(domain); load(syntheticCatalogs[domain], domain); toggle(); flushAll();
const c = control(); c.changeTipo('mes'); c.year = '2025'; c.unit = '01'; c.add(); http.expectNone(() => true);
panels()[0].applyFilters(); const r = http.expectOne(r => r.url.includes('/figuras/'));
page.applyFilters(); fixture.detectChanges(); const r = http.expectOne(r => r.url.includes('/figuras/'));
expect(r.request.params.get('periodos')).toBe('2025-01'); r.flush({ data: [{ y: [0, null] }], layout: {} }); fixture.detectChanges();
expect(fixture.nativeElement.textContent).toContain('no entregan intervalos Wilson efectivos');
expect(fixture.nativeElement.textContent).toContain('suprimidos no representan tasas observadas de 0 %');
@@ -334,7 +333,7 @@ describe('UX-05B catálogo expandible', () => {
c.year = '2025'; c.unit = 'S1'; c.add(); c.select([]); fixture.detectChanges(); await fixture.whenStable();
toggle(index); toggle(index); flushAll(); await fixture.whenStable();
expect(control().entry.draft.mode).toBe('empty'); expect(control().state.applied?.selection.mode).toBe('todos');
const state = panels()[0].result(); const saves = vi.spyOn(TestBed.inject(IndicadoresMemory), 'save');
const state = panels()[0].result(); const saves = vi.spyOn(TestBed.inject(IndicadoresMemory), 'saveGlobal');
const select = fixture.debugElement.queryAll(By.directive(MatSelect)).find(e => e.componentInstance.multiple)!;
const writes = vi.spyOn(select.injector.get(NgModel).control, 'setValue');
for (let i = 0; i < 3; i++) {