Files
WebApp/src/app/features/indicadores/indicadores-page.spec.ts
T
2026-10-13 16:01:48 -06:00

363 lines
26 KiB
TypeScript

import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { provideRouter } from '@angular/router';
import { By } from '@angular/platform-browser';
import { IndicadoresPage } from './indicadores-page';
import { IndicadorCatalogCard } from './indicador-catalog-card';
import { IndicadorFigurePanel } from './indicador-figure-panel';
import { IndicadorFigureCard } from './indicador-figure-card';
import { IndicadorPeriodFilters } from './indicador-period-filters';
import { MatSelect } from '@angular/material/select';
import { NgModel } from '@angular/forms';
import { IndicadoresMemory } from './indicadores-memory';
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: '' })
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'] };
describe('UX-05B catálogo expandible', () => {
let fixture: ReturnType<typeof TestBed.createComponent<IndicadoresPage>>;
let page: IndicadoresPage;
let http: HttpTestingController;
beforeEach(() => {
TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting()] });
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
fixture = TestBed.createComponent(IndicadoresPage); page = fixture.componentInstance;
http = TestBed.inject(HttpTestingController);
});
afterEach(() => { fixture.destroy(); http.verify(); });
function load(items: Indicador[] = [item, second], domain = 'tea') {
http.expectOne('/' + domain + '/indicadores').flush(items); fixture.detectChanges();
}
function cards() { return fixture.debugElement.queryAll(By.directive(IndicadorCatalogCard)).map(e => e.componentInstance as IndicadorCatalogCard); }
function panels() { return fixture.debugElement.queryAll(By.directive(IndicadorFigurePanel)).map(e => e.componentInstance as IndicadorFigurePanel); }
function toggle(index = 0) { cards()[index].toggle(); fixture.detectChanges(); }
function request(figure: string) { return http.expectOne(r => r.url.endsWith('/figuras/' + figure)); }
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 => {
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('D.1 conserva KPI durante carga, error, reintento y catálogo vacío sin HTTP propio', () => {
fixture.detectChanges();
const kpis = Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'));
expect(kpis).toHaveLength(2);
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);
});
it('D.1 separa secciones y conserva tarjetas, orden, identidades y figuras dentro del grid', () => {
load(); const before = cards();
const grid = fixture.nativeElement.querySelector('.catalog-grid') as HTMLElement;
expect(getComputedStyle(grid).display).toBe('grid');
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(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(cards()).toEqual(before); expect(cards().every(card => card.expanded)).toBe(true);
http.expectNone(() => true);
});
it('UX-06C: tarjeta contraída contiene solo identidad y flecha decorativa en un botón nativo', () => {
load();
const host = fixture.nativeElement.querySelector('app-indicador-catalog-card') as HTMLElement;
const header = host.querySelector('header')!;
expect(header.querySelector('h2')?.textContent).toBe('Uno');
expect(header.querySelector('.indicator-id')?.textContent).toBe('i1');
expect(host.textContent).not.toContain('Contrato');
expect(host.textContent).not.toContain('figuras publicadas');
expect(host.querySelectorAll('app-indicador-figure-panel')).toHaveLength(0);
const button = header.querySelector('button')!;
expect(button.type).toBe('button');
expect(button.tabIndex).toBe(0);
expect(button.getAttribute('aria-expanded')).toBe('false');
expect(button.getAttribute('aria-label')).toContain('Expandir tea · i1 · Uno');
expect(button.querySelector('mat-icon')?.textContent?.trim()).toBe('expand_more');
expect(button.querySelector('mat-icon')?.getAttribute('aria-hidden')).toBe('true');
http.expectNone(() => true);
});
it('UX-06C: conserva encabezado, botón y relación accesible al abrir varias figuras y contraer', () => {
load();
const host = fixture.nativeElement.querySelector('app-indicador-catalog-card') as HTMLElement;
const header = host.querySelector('header')!;
const button = header.querySelector('button')!;
const contentId = button.getAttribute('aria-controls')!;
button.click(); fixture.detectChanges(); flushAll();
expect(host.querySelector('header')).toBe(header);
expect(header.querySelector('button')).toBe(button);
expect(button.getAttribute('aria-controls')).toBe(contentId);
expect(button.getAttribute('aria-expanded')).toBe('true');
expect(button.querySelector('mat-icon')?.textContent?.trim()).toBe('expand_less');
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);
button.click(); fixture.detectChanges();
expect(host.querySelector('.catalog-metadata')).toBeNull();
expect(host.querySelectorAll('app-indicador-figure-panel')).toHaveLength(0);
expect(button.querySelector('mat-icon')?.textContent?.trim()).toBe('expand_more');
http.expectNone(() => true);
});
it('UX-06C: conserva título largo completo y el control separado de la identidad', () => {
const title = 'Distribución de indicadores con un título extenso y múltiples palabras para revisión responsive';
load([{ ...item, titulo: title }, second]);
const header = fixture.nativeElement.querySelector('app-indicador-catalog-card header') as HTMLElement;
expect(header.querySelector('h2')?.textContent).toBe(title);
expect(header.querySelector('.card-identity button')).toBeNull();
expect(header.lastElementChild?.tagName).toBe('BUTTON');
expect(header.querySelector('button')?.getAttribute('aria-label')).toContain(title);
http.expectNone(() => true);
});
it('UX-06B conserva una navegación con rutas y estado activo en los tres dominios', () => {
const domains = ['tea', 'cacu', 'cama'] as const;
for (const domain of domains) {
if (domain !== 'tea') page.changeDominio(domain);
load([], domain);
const navs = fixture.nativeElement.querySelectorAll('nav') as NodeListOf<HTMLElement>;
expect(navs).toHaveLength(1);
expect(navs[0].getAttribute('aria-label')).toBe('Dominios de indicadores');
const links = Array.from(navs[0].querySelectorAll('a'));
expect(links.map(link => link.textContent?.trim())).toEqual(['TEA', 'CaCu', 'CaMa']);
expect(links.map(link => link.getAttribute('href'))).toEqual(domains.map(d => '/indicadores/' + d));
expect(links.filter(link => link.getAttribute('aria-current') === 'page')).toHaveLength(1);
expect(links[domains.indexOf(domain)].getAttribute('aria-current')).toBe('page');
expect(cards()).toHaveLength(0);
http.expectNone(() => true);
}
});
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.textContent).not.toContain('Tema del dominio');
expect(page.tema).toBe('claro');
page.changeTema('oscuro'); fixture.detectChanges();
expect(page.tema).toBe('oscuro');
expect(cards().every(card => !card.expanded)).toBe(true);
http.expectNone(() => true);
});
it.each([0, 2, 18, 37])('catálogo de %i conserva orden y no consulta figuras inicialmente', count => {
const items = Array.from({ length: count }, (_, i) => ({ ...item, id: 'id-' + i }));
load(items);
expect(cards().map(c => c.indicador.id)).toEqual(items.map(i => i.id));
expect(cards().every(c => !c.expanded)).toBe(true);
expect(panels()).toHaveLength(0); http.expectNone(r => r.url.includes('/figuras/'));
if (!count) expect(fixture.nativeElement.textContent).toContain('No hay indicadores disponibles');
});
it('un indicador se abre y consulta exactamente una vez cada figura publicada', () => {
load([item]); expect(cards()[0].expanded).toBe(true); expect(panels()).toHaveLength(2);
request('f1').flush({ data: [], layout: {} }); request('f2').flush({ data: [], layout: {} });
fixture.detectChanges(); fixture.detectChanges(); http.expectNone(() => true);
});
it('la preferencia false prevalece sobre apertura automática al volver', () => {
load([item]); flushAll(); toggle();
fixture.destroy(); fixture = TestBed.createComponent(IndicadoresPage); page = fixture.componentInstance;
load([item]); expect(cards()[0].expanded).toBe(false); http.expectNone(() => true);
});
it('indicador sin figuras informa y no consulta HTTP', () => {
load([{ ...item, figuras: [] }]); expect(cards()[0].expanded).toBe(true);
expect(fixture.nativeElement.textContent).toContain('no tiene figuras disponibles');
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: {} });
a.flush({ data: [{ y: [1] }], layout: {} });
expect(panels().map(p => p.result().figure?.data[0]['y'])).toEqual([[1], [2], [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);
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]); const a = request('f1'), b = request('f2');
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');
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]); flushAll(); const a = control(), b = control(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.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']);
themedA.flush({ data: [], layout: {} }); themedB.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'] }]); flushAll();
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 result = panel.result();
const button = fixture.nativeElement.querySelector('.methodology-toggle') as HTMLButtonElement;
for (let i = 0; i < 2; i++) {
button.click(); fixture.detectChanges();
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);
http.expectNone(() => true);
}
});
it('cerrar y reabrir restaura borrador y aplicado por figura sin confirmar borradores', () => {
load([item]); 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();
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']);
restored.flush({ data: [], layout: {} }); other.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');
expect(darkA.request.params.get('tema')).toBe('oscuro'); http.expectNone(r => r.url.endsWith('/g'));
darkA.flush({ data: [], layout: {} }); darkB.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);
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');
});
it('restaura expansión y tema de dominio sin aplicar borrador pendiente', () => {
load(); toggle(); flushAll(); control().changeMode('manual');
page.changeTema('oscuro'); fixture.detectChanges(); flushAll();
page.changeDominio('cacu'); fixture.detectChanges(); load(syntheticCatalogs.cacu, 'cacu'); flushAll();
toggle(); page.changeDominio('tea'); fixture.detectChanges(); load();
expect(cards()[0].expanded).toBe(true); expect(cards()[1].expanded).toBe(false);
expect(page.tema).toBe('oscuro'); 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: {} });
page.changeDominio('cacu'); fixture.detectChanges(); load(syntheticCatalogs.cacu, 'cacu');
expect(cards()[0].expanded).toBe(false); expect(page.tema).toBe('claro'); http.expectNone(() => true);
});
it('identidades estables conservan componentes al reordenar el catálogo', () => {
load(); toggle(); flushAll(); const card = cards()[0], panel = panels()[0];
page.catalog.set([second, item]); fixture.detectChanges();
expect(cards()[1]).toBe(card); expect(panels()[0]).toBe(panel); http.expectNone(() => true);
});
it('identidad eliminada no se monta aunque exista preferencia anterior', () => {
TestBed.inject(IndicadoresMemory).rememberExpansion('tea', 'removed', true);
load([second]); expect(cards().map(c => c.indicador.id)).toEqual(['i2']); flushAll();
});
it('botones semánticos anuncian expansión, IDs únicos y devuelven foco al contraer contenido', () => {
load();
const buttons = fixture.nativeElement.querySelectorAll('app-indicador-catalog-card header button') as NodeListOf<HTMLButtonElement>;
expect(buttons[0].tagName).toBe('BUTTON'); expect(buttons[0].getAttribute('aria-expanded')).toBe('false');
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;
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);
expect(new Set(ids).size).toBe(ids.length);
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]); 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();
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);
expect(panels()[0].result().presentationFigure).not.toBe(raw);
expect(fixture.nativeElement.textContent).not.toContain('reportes no están disponibles');
});
it.each(['cacu', 'cama'] as const)('preserva advertencias y filtros mensuales de %s', domain => {
load([]); page.changeDominio(domain); load(syntheticCatalogs[domain], domain); 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/'));
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 %');
});
it('catálogo error, reintento y vacío no dejan paneles', () => {
http.expectOne('/tea/indicadores').flush('private', { status: 500, statusText: 'Error' }); fixture.detectChanges();
expect(page.catalogError()).toContain('error interno'); expect(fixture.nativeElement.textContent).not.toContain('private');
page.retryCatalog(); load([]); expect(panels()).toHaveLength(0);
});
it.each(['M02_sexo', 'K01_evaluacion_3_meses'])('UX-04A: %s conserva selección vacía estable al reabrir sin escrituras ni HTTP redundantes', async id => {
load(syntheticCatalogs.tea);
const index = cards().findIndex(c => c.indicador.id === id);
toggle(index); flushAll();
const c = control(); c.changeMode('manual'); fixture.detectChanges(); await fixture.whenStable();
expect(c.canApply).toBe(false); http.expectNone(() => true);
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 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++) {
select.componentInstance.open(); fixture.detectChanges(); await fixture.whenStable();
expect(select.componentInstance.panelOpen).toBe(true);
select.componentInstance.close(); fixture.detectChanges(); await fixture.whenStable();
}
expect(writes).not.toHaveBeenCalled(); expect(saves).not.toHaveBeenCalled();
expect(panels()[0].result()).toBe(state); http.expectNone(() => true);
});
it('UX-06D retira solo el aviso general del catálogo', () => {
load(); expect(fixture.nativeElement.querySelector('.notice')).toBeNull();
expect(fixture.nativeElement.textContent).not.toContain('Uso exclusivo de investigación. No usar para decisiones clínicas.');
});
it('IDs distintos con el mismo título y figura conservan paneles y etiquetas independientes', () => {
load([{ ...item, figuras: ['f1'] }, { ...second, titulo: item.titulo, figuras: ['f1'] }]);
toggle(0); toggle(1);
const a = http.expectOne(r => r.url.endsWith('/i1/figuras/f1'));
const b = http.expectOne(r => r.url.endsWith('/i2/figuras/f1'));
a.flush({ data: [{ y: [1] }], layout: {} }); b.flush({ data: [{ y: [2] }], layout: {} }); fixture.detectChanges();
const buttons = fixture.nativeElement.querySelectorAll('app-indicador-catalog-card header button') as NodeListOf<HTMLButtonElement>;
expect(buttons[0].getAttribute('aria-label')).not.toBe(buttons[1].getAttribute('aria-label'));
expect(buttons[0].tabIndex).toBe(0); expect(buttons[1].tabIndex).toBe(0);
expect(panels().map(p => p.result().figure?.data[0]['y'])).toEqual([[1], [2]]);
});
});