feat(ui): mejorar periodos KPI y presentacion del dashboard
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { periodAvailabilityProvider } from './indicadores-periodos.testing';
|
||||
import { Component } from '@angular/core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { provideHttpClient } from '@angular/common/http';
|
||||
@@ -44,7 +45,7 @@ class ResizeControl {
|
||||
emit() { this.callback([], this as unknown as ResizeObserver); }
|
||||
}
|
||||
|
||||
describe('UX-06E.D.1.1 visibilidad controlada', () => {
|
||||
describe('UX-06E.D.3.A tarjetas permanentes y visibilidad controlada', () => {
|
||||
let fixture: ReturnType<typeof TestBed.createComponent<IndicadoresPage>>;
|
||||
let page: IndicadoresPage;
|
||||
let http: HttpTestingController;
|
||||
@@ -68,7 +69,7 @@ describe('UX-06E.D.1.1 visibilidad controlada', () => {
|
||||
sticky = document.createElement('header'); sticky.className = 'institutional-header'; document.body.append(sticky);
|
||||
geometry.set(sticky, rect(0, 0, 1440, 100));
|
||||
runtime.react.mockReset().mockResolvedValue(undefined); runtime.purge.mockReset(); runtime.Plots.resize.mockReset().mockResolvedValue(undefined);
|
||||
TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting(),
|
||||
TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting(), periodAvailabilityProvider,
|
||||
{ provide: PLOTLY_LOADER, useValue: () => Promise.resolve(runtime) }] });
|
||||
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
||||
create();
|
||||
@@ -88,7 +89,7 @@ describe('UX-06E.D.1.1 visibilidad controlada', () => {
|
||||
function positions(values: number[][]) {
|
||||
cards().forEach((card, i) => {
|
||||
geometry.set(card.host.nativeElement, rect(values[i][0], values[i][1]));
|
||||
geometry.set(card.visibilityHeader.nativeElement, rect(values[i][0] + 16, values[i][1]));
|
||||
geometry.set(card.visibilityRegion!.nativeElement, rect(values[i][0], values[i][1], 600, 620));
|
||||
});
|
||||
}
|
||||
function observer() { return IntersectionControl.instances.at(-1)!; }
|
||||
@@ -96,252 +97,125 @@ describe('UX-06E.D.1.1 visibilidad controlada', () => {
|
||||
const callbacks = [...frames.values()]; frames.clear(); callbacks.forEach(callback => callback(0)); await render();
|
||||
}
|
||||
async function confirm() { await frame(); await frame(); }
|
||||
function notify(index = 0, intersects = true) { observer().emit(cards()[index].visibilityHeader.nativeElement, intersects); }
|
||||
function notify(index = 0, intersects = true) { observer().emit(cards()[index].visibilityRegion!.nativeElement, intersects); }
|
||||
function respond() { http.match(r => r.url.includes('/figuras/')).forEach(r => r.flush({ data: [{ y: [1] }], layout: {} })); }
|
||||
async function idle() {
|
||||
for (let i = 0; i < 6 && frames.size; i++) await frame();
|
||||
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' });
|
||||
expect([...observer().targets]).toEqual(cards().map(card => card.visibilityHeader.nativeElement));
|
||||
expect([...observer().targets].every(target => target.tagName === 'HEADER')).toBe(true);
|
||||
expect(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card')).toHaveLength(2);
|
||||
await idle(); http.expectNone(() => true);
|
||||
});
|
||||
it('exige dos frames y activa una sola vez sin autocierre ni nuevas consultas', async () => {
|
||||
await load(); positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify();
|
||||
await frame(); expect(cards()[0].expanded).toBe(false); http.expectNone(() => true);
|
||||
await frame(); expect(memory.activation('tea', 'i0')).toBe('auto-open'); expect(panels()).toHaveLength(1); respond();
|
||||
const panel = panels()[0], result = panel.result();
|
||||
positions([[1000, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]);
|
||||
observer().emit(cards()[0].visibilityHeader.nativeElement, false); await idle();
|
||||
positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await idle();
|
||||
expect(cards()[0].expanded).toBe(true); expect(panels()[0]).toBe(panel); expect(panel.result()).toBe(result); http.expectNone(() => true);
|
||||
});
|
||||
it('abre juntas dos tarjetas de la fila real sin abrir filas inferiores', async () => {
|
||||
await load(); positions([[200, 0], [200.5, 650], [1000, 0], [1000, 650], [1200, 0]]); notify(); await confirm();
|
||||
expect(cards().map(card => card.expanded)).toEqual([true, true, false, false, false]);
|
||||
expect(panels()).toHaveLength(2); respond(); await idle(); http.expectNone(() => true);
|
||||
});
|
||||
it('en una columna no asocia dos indicadores por índice', async () => {
|
||||
await load(); positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await confirm();
|
||||
expect(cards().map(card => card.expanded)).toEqual([true, false, false, false, false]); respond(); await idle();
|
||||
});
|
||||
it('una intersección fugaz y una entrada antigua no abren una tarjeta ya fuera', async () => {
|
||||
await load(); positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await frame();
|
||||
positions([[900, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); await frame();
|
||||
notify(); await idle(); expect(cards().every(card => !card.expanded)).toBe(true); http.expectNone(() => true);
|
||||
});
|
||||
it('un desplazamiento rápido invalida la confirmación geométrica previa', async () => {
|
||||
await load(); positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await frame();
|
||||
positions([[400, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); await frame();
|
||||
expect(cards()[0].expanded).toBe(false); http.expectNone(() => true);
|
||||
positions([[1000, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); await idle();
|
||||
});
|
||||
it('procesa primero la fila superior y descarta inferiores desplazadas por reflow', async () => {
|
||||
await load(); positions([[200, 0], [200, 650], [400, 0], [400, 650], [1000, 0]]); notify(2); await confirm();
|
||||
expect(cards().map(card => card.expanded)).toEqual([true, true, false, false, false]); respond();
|
||||
positions([[200, 0], [200, 650], [1100, 0], [1100, 650], [1300, 0]]); await idle();
|
||||
expect(cards()[2].expanded).toBe(false); http.expectNone(() => true);
|
||||
});
|
||||
it('las filas todavía visibles se activan en nuevas evaluaciones después de render', async () => {
|
||||
await load(); positions([[200, 0], [200, 650], [450, 0], [450, 650], [1000, 0]]); notify(); await confirm(); respond();
|
||||
await confirm(); expect(cards().map(card => card.expanded)).toEqual([true, true, true, true, false]); respond(); await idle();
|
||||
});
|
||||
it('recalcula asociaciones responsive entre los dos frames', async () => {
|
||||
await load(); positions([[200, 0], [200, 650], [1000, 0], [1000, 650], [1200, 0]]); notify(); await frame();
|
||||
positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); window.dispatchEvent(new Event('resize'));
|
||||
await frame(); expect(cards().every(card => !card.expanded)).toBe(true);
|
||||
await frame(); expect(cards().map(card => card.expanded)).toEqual([true, false, false, false, false]); respond(); await idle();
|
||||
});
|
||||
it('excluye cabeceras detrás de sticky y mide sus cambios de altura', async () => {
|
||||
await load(); positions([[0, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await idle(); http.expectNone(() => true);
|
||||
const old = observer(); geometry.set(sticky, rect(0, 0, 1440, 50)); ResizeControl.instances.find(instance => instance.targets.has(sticky))!.emit();
|
||||
await frame(); expect(old.disconnect).toHaveBeenCalled(); expect(observer().options.rootMargin).toBe('-50px 0px 0px 0px');
|
||||
await frame(); expect(cards()[0].expanded).toBe(true); respond(); await idle();
|
||||
});
|
||||
it('una cabecera parcialmente visible por debajo del umbral no se activa', async () => {
|
||||
await load(); positions([[770, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await idle();
|
||||
expect(cards()[0].expanded).toBe(false); http.expectNone(() => true);
|
||||
});
|
||||
it('cierre manual prevalece sobre una confirmación pendiente y permite reapertura', async () => {
|
||||
await load(); positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await frame();
|
||||
cards()[0].toggle(); await render(); const request = http.expectOne(r => r.url.includes('/figuras/'));
|
||||
cards()[0].toggle(); await render(); expect(request.cancelled).toBe(true);
|
||||
notify(); await idle(); expect(memory.activation('tea', 'i0')).toBe('manual-closed'); http.expectNone(() => true);
|
||||
cards()[0].toggle(); await render(); expect(memory.activation('tea', 'i0')).toBe('manual-open'); respond();
|
||||
});
|
||||
it('una compañera cerrada manualmente permanece cerrada', async () => {
|
||||
memory.rememberActivation('tea', 'i1', 'manual-closed'); await load();
|
||||
positions([[200, 0], [200, 650], [1000, 0], [1000, 650], [1200, 0]]); notify(); await confirm();
|
||||
expect(cards().map(card => card.expanded)).toEqual([true, false, false, false, false]); respond(); await idle();
|
||||
});
|
||||
it.each(['tea', 'cacu', 'cama'] as const)('singleton %s espera visibilidad antes de consultar', async domain => {
|
||||
it.each([{ domain: 'tea', count: 18 }, { domain: 'cacu', count: 8 }] as const)('%s no descarga todas las figuras al abrir', async ({ domain, count }) => {
|
||||
if (domain !== 'tea') { http.expectOne('/tea/indicadores'); page.changeDominio(domain); }
|
||||
await load([items[0]], domain); await idle(); http.expectNone(() => true); expect(cards()[0].expanded).toBe(false);
|
||||
positions([[200, 0]]); notify(); await confirm(); expect(memory.activation(domain, 'i0')).toBe('auto-open'); respond(); await idle();
|
||||
await load(Array.from({ length: count }, (_, i) => ({ ...items[0], id: 'i' + i })), domain);
|
||||
await idle(); expect(cards()).toHaveLength(count); expect(panels()).toHaveLength(count);
|
||||
expect(panels().every(p => p.result().status === 'deferred')).toBe(true); http.expectNone(() => true);
|
||||
expect(fixture.nativeElement.querySelectorAll('app-indicador-catalog-card header button')).toHaveLength(0);
|
||||
expect(fixture.nativeElement.querySelectorAll('.figure-skeleton')).toHaveLength(count);
|
||||
positions(cards().map((_, i) => [i < 2 ? 200 : 1200 + i * 1000, i === 1 ? 650 : 0])); notify(); await confirm();
|
||||
const requests = http.match(r => r.url.includes('/figuras/')); expect(requests).toHaveLength(2);
|
||||
requests.forEach(r => r.flush({ data: [{ y: [1] }], layout: {} })); await render(); await idle(); http.expectNone(() => true);
|
||||
});
|
||||
it('regresar conserva abierto sin montar fuera del viewport, y carga al entrar', async () => {
|
||||
await load([items[0]]); positions([[200, 0]]); notify(); await confirm(); respond();
|
||||
page.changeDominio('cacu'); await load([items[0]], 'cacu'); await idle();
|
||||
expect(cards()[0].expanded).toBe(false);
|
||||
page.changeDominio('tea'); await load([items[0]]); await idle();
|
||||
expect(cards()[0].expanded).toBe(true); expect(cards()[0].awaitingFigures).toBe(true); expect(panels()).toHaveLength(0); http.expectNone(() => true);
|
||||
expect(fixture.nativeElement.textContent).toContain('Apertura recordada');
|
||||
positions([[200, 0]]); notify(); await confirm(); expect(panels()).toHaveLength(1); respond(); await idle();
|
||||
expect(memory.activation('tea', 'i0')).toBe('auto-open');
|
||||
});
|
||||
it('fallback manual permite mostrar figuras restauradas al primer clic y cerrar al siguiente', async () => {
|
||||
http.expectOne('/tea/indicadores'); fixture.destroy(); vi.stubGlobal('IntersectionObserver', undefined); create(); memory.rememberActivation('tea', 'i0', 'auto-open');
|
||||
await load([items[0]]); expect(IntersectionControl.instances).toHaveLength(0); http.expectNone(() => true);
|
||||
const button = fixture.nativeElement.querySelector('app-indicador-catalog-card header button') as HTMLButtonElement;
|
||||
expect(button.getAttribute('aria-expanded')).toBe('true'); expect(button.getAttribute('aria-label')).toContain('Mostrar figuras');
|
||||
button.focus(); button.click(); await render(); expect(document.activeElement).toBe(button); expect(panels()).toHaveLength(1); respond();
|
||||
button.click(); await render(); expect(button.getAttribute('aria-expanded')).toBe('false'); expect(panels()).toHaveLength(0); http.expectNone(() => true);
|
||||
button.click(); await render(); expect(panels()).toHaveLength(1); respond();
|
||||
});
|
||||
it('búsqueda activa indirectamente una pendiente visible y conserva cierre manual al limpiar', async () => {
|
||||
memory.rememberActivation('tea', 'i0', 'manual-closed'); await load(); await idle();
|
||||
const original = cards(); page.changeSearchQuery('Indicador 4'); await render();
|
||||
expect(cards()[0]).toBe(original[4]); positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]);
|
||||
http.expectNone(() => true); notify(); await confirm(); respond();
|
||||
page.changeSearchQuery(''); await render(); expect(cards()).toEqual(original);
|
||||
positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await idle();
|
||||
expect(cards()[0].expanded).toBe(false); expect(cards()[4].expanded).toBe(true); http.expectNone(() => true);
|
||||
});
|
||||
it('reordenar una pendiente fuera de vista no autoriza carga con callback antiguo', async () => {
|
||||
await load(); positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); const target = cards()[0].visibilityHeader.nativeElement;
|
||||
notify(); await frame(); page.changeSearchQuery('Indicador 4'); await render();
|
||||
positions([[1000, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); observer().emit(target); await idle();
|
||||
expect(cards().every(card => !card.expanded)).toBe(true); http.expectNone(() => true);
|
||||
});
|
||||
it('retirar tarjetas desobserva sus cabeceras y descarta callbacks tardíos', async () => {
|
||||
await load(); const retired = cards()[0].visibilityHeader.nativeElement, active = observer();
|
||||
page.catalog.set(items.slice(1)); await render();
|
||||
expect(active.unobserve).toHaveBeenCalledWith(retired); active.emit(retired); await idle(); http.expectNone(() => true);
|
||||
});
|
||||
it('cambiar de dominio cancela HTTP e ignora el observer saliente', async () => {
|
||||
await load([items[0]]); positions([[200, 0]]); notify(); await confirm();
|
||||
const request = http.expectOne(r => r.url.includes('/figuras/')), old = observer(), target = cards()[0].visibilityHeader.nativeElement;
|
||||
page.changeDominio('cama'); await load([items[0]], 'cama'); expect(request.cancelled).toBe(true);
|
||||
expect(old.disconnect).toHaveBeenCalled(); old.emit(target); await idle(); http.expectNone(() => true);
|
||||
});
|
||||
it('destruir desconecta observers, cancela frames y hace inocuos callbacks tardíos', async () => {
|
||||
await load(); const active = observer(), target = cards()[0].visibilityHeader.nativeElement;
|
||||
positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await frame();
|
||||
const sizeObserver = ResizeControl.instances.find(instance => instance.targets.has(sticky))!;
|
||||
const scheduled = new Set(frames.keys());
|
||||
const cancellations = vi.mocked(window.cancelAnimationFrame).mock.calls.length;
|
||||
fixture.destroy(); expect(active.disconnect).toHaveBeenCalled(); expect(sizeObserver.disconnect).toHaveBeenCalled();
|
||||
const cancelled = vi.mocked(window.cancelAnimationFrame).mock.calls.slice(cancellations).map(([id]) => id);
|
||||
expect(cancelled.some(id => scheduled.has(id))).toBe(true);
|
||||
for (const id of cancelled) expect(frames.has(id)).toBe(false);
|
||||
// Angular/Material can own another global frame; late page callbacks must add none.
|
||||
const remaining = frames.size;
|
||||
active.emit(target); sizeObserver.emit(); window.dispatchEvent(new Event('scroll'));
|
||||
expect(frames.size).toBe(remaining); http.expectNone(() => true);
|
||||
});
|
||||
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(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(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();
|
||||
await load([items[0]]); expect(cards()[0].expanded).toBe(false); http.expectNone(() => true);
|
||||
const button = fixture.nativeElement.querySelector('app-indicador-catalog-card header button') as HTMLButtonElement;
|
||||
for (const key of ['Tab', 'Enter', ' ']) {
|
||||
const event = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true });
|
||||
button.dispatchEvent(event); expect(event.defaultPrevented).toBe(false);
|
||||
}
|
||||
button.click(); await render(); expect(memory.activation('tea', 'i0')).toBe('manual-open'); respond();
|
||||
button.click(); await render(); expect(memory.activation('tea', 'i0')).toBe('manual-closed'); http.expectNone(() => true);
|
||||
});
|
||||
it('la activación protegida nunca sobrescribe una decisión manual', async () => {
|
||||
memory.rememberActivation('tea', 'i0', 'manual-closed'); memory.rememberActivation('tea', 'i1', 'manual-open'); await load();
|
||||
cards()[0].activateVisible(); cards()[1].activateVisible(); await render();
|
||||
expect(memory.activation('tea', 'i0')).toBe('manual-closed'); expect(cards()[0].expanded).toBe(false);
|
||||
expect(memory.activation('tea', 'i1')).toBe('manual-open'); expect(cards()[1].figuresActivated).toBe(true); respond();
|
||||
cards()[1].activateVisible(); await render(); http.expectNone(() => true);
|
||||
});
|
||||
it('scroll progresivo reactiva evaluación sin mantener un bucle cuando todo está fuera', async () => {
|
||||
await load(); await idle(); positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]);
|
||||
window.dispatchEvent(new Event('scroll')); await confirm(); respond(); await idle();
|
||||
positions([[-1000, 0], [200, 0], [1200, 0], [1400, 0], [1600, 0]]);
|
||||
window.dispatchEvent(new Event('scroll')); await confirm(); respond(); await idle();
|
||||
expect(cards().map(card => card.expanded)).toEqual([true, true, false, false, false]); http.expectNone(() => true);
|
||||
});
|
||||
it('búsqueda reconstruye la fila visual usando las mismas instancias', async () => {
|
||||
await load(); await idle(); const before = cards(); page.changeSearchQuery('Indicador 4'); await render();
|
||||
positions([[200, 0], [200, 650], [1000, 0], [1000, 650], [1200, 0]]); notify(); await confirm(); respond(); await idle();
|
||||
expect(memory.activation('tea', 'i4')).toBe('auto-open'); expect(memory.activation('tea', 'i0')).toBe('auto-open');
|
||||
expect(memory.activation('tea', 'i1')).toBe('pending');
|
||||
expect(cards().every(card => before.includes(card))).toBe(true); http.expectNone(() => true);
|
||||
});
|
||||
it('una cabecera fuera horizontalmente no se considera visible', async () => {
|
||||
await load([items[0]]); positions([[200, 1500]]); notify(); await idle();
|
||||
expect(cards()[0].expanded).toBe(false); http.expectNone(() => true);
|
||||
});
|
||||
it('visibilidad y búsqueda conservan hosts Plotly, resultados y foco sin react ni purge repetidos', async () => {
|
||||
http.expectOne('/tea/indicadores'); fixture.destroy(); TestBed.resetTestingModule();
|
||||
TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting(),
|
||||
{ provide: PLOTLY_LOADER, useValue: () => Promise.resolve(runtime) }] }); create();
|
||||
await load(); positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]);
|
||||
const input = fixture.nativeElement.querySelector('.catalog-search input') as HTMLInputElement; input.focus(); notify(); await confirm(); respond(); await render();
|
||||
for (let i = 0; i < 12; i++) await Promise.resolve(); await render();
|
||||
const chart = fixture.debugElement.query(By.directive(PlotlyChart)).componentInstance as PlotlyChart;
|
||||
const host = chart.host.nativeElement, panel = panels()[0], result = panel.result(), reacts = runtime.react.mock.calls.length;
|
||||
expect(reacts).toBe(1); expect(document.activeElement).toBe(input);
|
||||
page.changeSearchQuery('Indicador 0'); await render(); notify(); await idle();
|
||||
expect(fixture.debugElement.query(By.directive(PlotlyChart)).componentInstance.host.nativeElement).toBe(host);
|
||||
expect(panels()[0]).toBe(panel); expect(panel.result()).toBe(result); expect(document.activeElement).toBe(input);
|
||||
expect(runtime.react).toHaveBeenCalledTimes(reacts); expect(runtime.purge).not.toHaveBeenCalled(); http.expectNone(() => true);
|
||||
});
|
||||
it('D.2 aplicar fuera de pantalla no activa tarjetas y scroll consulta la revisión vigente una sola vez', async () => {
|
||||
it('observa regiones gráficas permanentemente con margen de anticipación y sticky', async () => {
|
||||
await load(); await idle();
|
||||
expect(observer().options).toEqual({ root: null, threshold: 0, rootMargin: '-100px 0px 200px 0px' });
|
||||
expect([...observer().targets]).toEqual(cards().map(c => c.visibilityRegion!.nativeElement));
|
||||
positions([[900, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); notify(); await confirm(); respond(); await render();
|
||||
expect(observer().targets.size).toBe(5); expect(panels()[0].result().status).toBe('ready');
|
||||
expect(fixture.nativeElement.querySelectorAll('.figure-skeleton')).toHaveLength(4);
|
||||
});
|
||||
it('salir y volver conserva panel, resultado y selección sin HTTP redundante', async () => {
|
||||
await load(); positions([[200, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); notify(); await confirm(); respond(); await render();
|
||||
const panel = panels()[0], result = panel.result();
|
||||
positions([[-1000, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); notify(0, false); await idle();
|
||||
expect(cards()[0].visible).toBe(false); expect(panels()[0]).toBe(panel); expect(panel.result()).toBe(result);
|
||||
positions([[200, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); notify(); await idle();
|
||||
expect(panel.result()).toBe(result); http.expectNone(() => true);
|
||||
});
|
||||
it('filtro fuera de vista conserva host y consulta únicamente el último aplicado al regresar', async () => {
|
||||
await load(); positions([[200, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); notify(); await confirm(); respond(); await render();
|
||||
const panel = panels()[0], chart = fixture.nativeElement.querySelector('app-plotly-chart');
|
||||
positions([[-1000, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); window.dispatchEvent(new Event('scroll')); await idle();
|
||||
const filters = fixture.debugElement.query(By.directive(IndicadorPeriodFilters)).componentInstance as IndicadorPeriodFilters;
|
||||
filters.changeMode('manual'); filters.year = '2025'; filters.unit = 'S1'; filters.add();
|
||||
page.applyFilters(); await render(); await idle();
|
||||
expect(cards().every(card => !card.figuresActivated)).toBe(true); http.expectNone(() => true);
|
||||
positions([[200, 0], [1000, 0], [1200, 0], [1400, 0], [1600, 0]]);
|
||||
window.dispatchEvent(new Event('scroll')); await confirm();
|
||||
const first = http.expectOne(r => r.url.includes('/i0/figuras/'));
|
||||
expect(first.request.params.get('periodos')).toBe('2025-S1'); first.flush({ data: [], layout: {} });
|
||||
expect(panels()[0].applied.revision).toBe(1); await idle();
|
||||
cards()[0].toggle(); await render();
|
||||
filters.unit = 'S2'; filters.add(); page.applyFilters(); await render(); await idle();
|
||||
expect(memory.activation('tea', 'i0')).toBe('manual-closed'); http.expectNone(() => true);
|
||||
positions([[-1000, 0], [200, 0], [1200, 0], [1400, 0], [1600, 0]]);
|
||||
window.dispatchEvent(new Event('scroll')); await confirm();
|
||||
const second = http.expectOne(r => r.url.includes('/i1/figuras/'));
|
||||
expect(second.request.params.get('periodos')).toBe('2025-S1,2025-S2'); second.flush({ data: [], layout: {} });
|
||||
expect(panels()[0].applied.revision).toBe(2); await idle();
|
||||
notify(1); await idle(); page.applyFilters(); await render(); http.expectNone(() => true);
|
||||
filters.changeMode('manual'); filters.year = '2025'; filters.unit = 'S1'; filters.add(); page.applyFilters(); await render();
|
||||
filters.unit = 'S2'; filters.add(); page.applyFilters(); page.changeTema('oscuro'); await render(); await idle();
|
||||
expect(panels()[0]).toBe(panel); expect(panel.result().status).toBe('deferred');
|
||||
expect(fixture.nativeElement.querySelector('app-plotly-chart')).toBe(chart); http.expectNone(() => true);
|
||||
positions([[200, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); notify(); await confirm();
|
||||
const request = http.expectOne(r => r.url.includes('/i0/figuras/'));
|
||||
expect(request.request.params.get('periodos')).toBe('2025-S1,2025-S2'); expect(request.request.params.get('tema')).toBe('oscuro');
|
||||
request.flush({ data: [{ y: [2] }], layout: {} }); await render(); notify(); await idle(); http.expectNone(() => true);
|
||||
});
|
||||
it('aplicar antes del frame de scroll relee geometría y cancela petición obsoleta sin nueva descarga', async () => {
|
||||
await load(); positions([[200, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); notify(); await confirm();
|
||||
const old = http.expectOne(r => r.url.includes('/i0/figuras/'));
|
||||
positions([[-1000, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]); window.dispatchEvent(new Event('scroll'));
|
||||
page.filters!.editors.semestre!.draft = { mode: 'explicit', periodos: ['2025-S1'] }; page.applyFilters(); await render();
|
||||
expect(old.cancelled).toBe(true); expect(panels()[0].result().status).toBe('deferred'); http.expectNone(() => true);
|
||||
expect(() => old.flush({ data: [{ y: [99] }], layout: {} })).toThrow(); await idle();
|
||||
});
|
||||
it('cambio rápido de representación cancela saliente y fuera de vista difiere seleccionada', async () => {
|
||||
await load([{ ...items[0], figuras: ['f', 'g', 'h'] }]); positions([[200, 0]]); notify(); await confirm();
|
||||
const old = http.expectOne(r => r.url.endsWith('/figuras/f')); cards()[0].selectFigure('g'); await render();
|
||||
expect(old.cancelled).toBe(true); const next = http.expectOne(r => r.url.endsWith('/figuras/g'));
|
||||
cards()[0].selectFigure('h'); await render(); expect(next.cancelled).toBe(true);
|
||||
http.expectOne(r => r.url.endsWith('/figuras/h')).flush({ data: [], layout: {} }); await render();
|
||||
expect(panels()).toHaveLength(1); positions([[-1000, 0]]); notify(0, false); await idle();
|
||||
cards()[0].selectFigure('g'); await render(); http.expectNone(() => true); expect(panels()[0].result().status).toBe('deferred');
|
||||
positions([[200, 0]]); notify(); await confirm(); http.expectOne(r => r.url.endsWith('/figuras/g')).flush({ data: [], layout: {} });
|
||||
});
|
||||
it('fijación y búsqueda conservan componentes y descartan callbacks con geometría antigua', async () => {
|
||||
await load(); const before = cards(); positions([[200, 0], [1200, 0], [1400, 0], [1600, 0], [1800, 0]]);
|
||||
const target = before[0].visibilityRegion!.nativeElement; notify(); page.togglePinned(items[4]); await render();
|
||||
page.changeSearchQuery('Indicador 3'); await render(); positions(cards().map((_, i) => [1200 + i * 1000, 0]));
|
||||
observer().emit(target); await idle(); http.expectNone(() => true);
|
||||
expect(cards()[0]).toBe(before[3]); expect(cards()[1]).toBe(before[4]); expect(cards().every(c => before.includes(c))).toBe(true);
|
||||
positions(cards().map((_, i) => [i === 0 ? 200 : 1200 + i * 1000, 0])); notify(); await confirm();
|
||||
http.expectOne(r => r.url.includes('/i3/figuras/')).flush({ data: [], layout: {} }); await render();
|
||||
expect(cards()[0].selectedFigure).toBe('f');
|
||||
});
|
||||
it.each([{ data: [], layout: {} }, { data: [{ y: [null, null] }], layout: { annotations: [{ text: 'Valores ocultos por supresión.' }] } }])('resultado vacío o suprimido termina skeleton y conserva JSON: %j', async figure => {
|
||||
await load([items[0]]); positions([[200, 0]]); notify(); await confirm();
|
||||
http.expectOne(r => r.url.includes('/figuras/')).flush(figure); await render();
|
||||
expect(panels()[0].result().status).toBe('ready'); expect(panels()[0].result().figure).toEqual(figure);
|
||||
expect(fixture.nativeElement.querySelector('.figure-skeleton')).toBeNull(); expect(fixture.nativeElement.textContent).toContain('No hay valores visibles');
|
||||
if (figure.layout.annotations) expect(panels()[0].result().figure?.layout['annotations']).toEqual(figure.layout.annotations);
|
||||
});
|
||||
it('error HTTP termina skeleton y reintenta sólo la figura visible', async () => {
|
||||
await load([items[0]]); positions([[200, 0]]); notify(); await confirm();
|
||||
http.expectOne(r => r.url.includes('/figuras/')).flush('private', { status: 503, statusText: 'Unavailable' }); await render();
|
||||
expect(panels()[0].result().status).toBe('error'); expect(fixture.nativeElement.querySelector('.figure-skeleton')).toBeNull();
|
||||
panels()[0].requestFigure(); respond(); await render(); expect(panels()[0].result().status).toBe('ready');
|
||||
});
|
||||
it('fallback sin IntersectionObserver muestra las figuras sin interacción manual', async () => {
|
||||
http.expectOne('/tea/indicadores'); fixture.destroy(); vi.stubGlobal('IntersectionObserver', undefined); create();
|
||||
await load([items[0]]); respond(); await render(); expect(panels()[0].result().status).toBe('ready');
|
||||
expect(fixture.nativeElement.querySelector('app-indicador-catalog-card header button')).toBeNull(); http.expectNone(() => true);
|
||||
});
|
||||
it('dominio cancela solicitudes, desobserva tarjetas retiradas e ignora callback antiguo', async () => {
|
||||
await load(); const oldObserver = observer(), retired = cards()[0].visibilityRegion!.nativeElement;
|
||||
page.catalog.set(items.slice(1)); await render(); expect(oldObserver.unobserve).toHaveBeenCalledWith(retired);
|
||||
oldObserver.emit(retired); await idle(); http.expectNone(() => true);
|
||||
positions([[200, 0], [1200, 0], [1400, 0], [1600, 0]]); notify(); await confirm();
|
||||
const request = http.expectOne(r => r.url.includes('/figuras/'));
|
||||
page.changeDominio('cama'); await load([items[0]], 'cama'); expect(request.cancelled).toBe(true);
|
||||
expect(oldObserver.disconnect).toHaveBeenCalled(); oldObserver.emit(retired); await idle(); http.expectNone(() => true);
|
||||
});
|
||||
it('destrucción desconecta observers, cancela frame y vuelve inocuos callbacks tardíos', async () => {
|
||||
await load(); const active = observer(), target = cards()[0].visibilityRegion!.nativeElement;
|
||||
notify(); const pending = [...frames.keys()]; fixture.destroy();
|
||||
expect(active.disconnect).toHaveBeenCalled(); expect(ResizeControl.instances.some(o => o.disconnect.mock.calls.length)).toBe(true);
|
||||
expect(pending.some(id => vi.mocked(window.cancelAnimationFrame).mock.calls.some(call => call[0] === id))).toBe(true);
|
||||
const remaining = frames.size; active.emit(target); window.dispatchEvent(new Event('scroll')); expect(frames.size).toBe(remaining);
|
||||
});
|
||||
it('hosts Plotly permanecen montados fuera de vista y se purgan al destruir', async () => {
|
||||
http.expectOne('/tea/indicadores'); fixture.destroy(); TestBed.resetTestingModule();
|
||||
TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting(), periodAvailabilityProvider, { provide: PLOTLY_LOADER, useValue: () => Promise.resolve(runtime) }] }); create();
|
||||
await load([items[0]]); positions([[200, 0]]); notify(); await confirm(); respond(); await render();
|
||||
for (let i = 0; i < 12; i++) await Promise.resolve(); await render();
|
||||
const chart = fixture.debugElement.query(By.directive(PlotlyChart)).componentInstance as PlotlyChart, host = chart.host.nativeElement;
|
||||
expect(runtime.react).toHaveBeenCalledTimes(1); positions([[-1000, 0]]); notify(0, false); await idle();
|
||||
expect(chart.host.nativeElement).toBe(host); expect(runtime.purge).not.toHaveBeenCalled();
|
||||
positions([[200, 0]]); notify(); await idle(); expect(runtime.react).toHaveBeenCalledTimes(1); http.expectNone(() => true);
|
||||
fixture.destroy(); expect(runtime.purge).toHaveBeenCalledWith(host);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user