feat(indicadores): mejorar presentación y legibilidad de figuras multidominio

This commit is contained in:
Angel Capetillo Zavala
2026-10-15 13:45:59 -06:00
parent 4685a91a7c
commit 11337679dc
18 changed files with 1197 additions and 25 deletions
@@ -36,6 +36,32 @@ describe('PlotlyChart lifecycle', () => {
await fixture.whenStable(); for (let i = 0; i < 12; i++) await Promise.resolve(); fixture.detectChanges();
expect(fixture.componentInstance.status()).toBe('ready'); fixture.destroy();
});
it('UX-07C comunica sólo cambios reales de ancho, agrupa notificaciones y cancela al destruir', async () => {
const frames: FrameRequestCallback[] = [], cancel = vi.fn(), disconnect = vi.fn();
let notify!: ResizeObserverCallback;
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => { frames.push(callback); return frames.length; });
vi.stubGlobal('cancelAnimationFrame', cancel);
vi.stubGlobal('ResizeObserver', class {
constructor(callback: ResizeObserverCallback) { notify = callback; }
observe = vi.fn(); disconnect = disconnect;
});
const fixture = TestBed.createComponent(PlotlyChart), widths: number[] = [];
fixture.componentInstance.widthChanged.subscribe(width => widths.push(width));
fixture.componentRef.setInput('figure', { data: [], layout: {} }); fixture.detectChanges();
const host = fixture.nativeElement.querySelector('.plot') as HTMLElement;
let width = 640;
vi.spyOn(host, 'getBoundingClientRect').mockImplementation(() => ({ width } as DOMRect));
const resize = () => notify([], {} as ResizeObserver);
const flush = () => frames.splice(0).forEach(callback => callback(0));
const pending = frames.length; // Angular may also schedule a render frame.
resize(); resize(); expect(frames).toHaveLength(pending);
flush(); expect(widths).toEqual([640]);
resize(); flush(); expect(widths).toEqual([640]); // Height-only notification.
width = 900; resize(); flush(); expect(widths).toEqual([640, 900]);
width = 0; resize(); flush(); expect(widths).toEqual([640, 900]); // Hidden host.
resize(); fixture.destroy(); expect(disconnect).toHaveBeenCalled(); expect(cancel).toHaveBeenCalled();
vi.unstubAllGlobals();
});
});