From 37c4eacf849f904d9f7d3870da65a60120177215 Mon Sep 17 00:00:00 2001 From: Angel Capetillo Zavala Date: Tue, 13 Oct 2026 13:41:45 -0600 Subject: [PATCH] feat(ui): completar presentacion de figuras UX-06D --- src/app/app.html | 10 ++- src/app/app.scss | 22 ++++++- src/app/app.spec.ts | 65 +++++++++++++++++++ src/app/app.ts | 25 ++++++- .../indicadores/indicador-figure-card.html | 12 +++- .../indicadores/indicador-figure-card.scss | 24 +++++-- .../indicadores/indicador-figure-card.spec.ts | 63 ++++++++++++++++++ .../indicadores/indicador-figure-card.ts | 16 ++++- .../indicadores/indicadores-page.html | 6 -- .../indicadores/indicadores-page.scss | 1 - .../indicadores/indicadores-page.spec.ts | 30 +++++++-- src/app/shared/plotly/plotly-chart.ts | 5 +- 12 files changed, 250 insertions(+), 29 deletions(-) diff --git a/src/app/app.html b/src/app/app.html index 2cd6ad0..5d3c7ac 100644 --- a/src/app/app.html +++ b/src/app/app.html @@ -7,6 +7,14 @@ -
+
+ +@if (showBackToTop()) { + +} diff --git a/src/app/app.scss b/src/app/app.scss index 45363e3..f52f0dc 100644 --- a/src/app/app.scss +++ b/src/app/app.scss @@ -39,7 +39,7 @@ } main { - padding: var(--issste-space-4) var(--issste-page-gutter); + padding: var(--issste-space-4) var(--issste-page-gutter) 5.5rem; scroll-margin-top: var(--issste-header-clearance); } @@ -87,3 +87,23 @@ main { text-align: center; } } + +.back-to-top { + position: fixed; + right: max(var(--issste-page-gutter), env(safe-area-inset-right)); + bottom: max(var(--issste-space-4), env(safe-area-inset-bottom)); + z-index: 90; + display: grid; + place-items: center; + width: 48px; + height: 48px; + padding: 0; + border: 1px solid var(--issste-text); + border-radius: 50%; + background: var(--issste-text); + color: var(--issste-surface); + cursor: pointer; +} + +.back-to-top:hover { background: var(--issste-text-secondary); } +.back-to-top:focus-visible { outline: 3px solid var(--issste-text); outline-offset: 4px; } diff --git a/src/app/app.spec.ts b/src/app/app.spec.ts index 6f80b93..c6ea793 100644 --- a/src/app/app.spec.ts +++ b/src/app/app.spec.ts @@ -54,3 +54,68 @@ describe('App — UX-06B', () => { TestBed.inject(HttpTestingController).verify(); }); }); + +describe('App — UX-06D volver al inicio', () => { + let scrollY: number; + beforeEach(() => { + scrollY = 0; + vi.spyOn(window, 'scrollY', 'get').mockImplementation(() => scrollY); + TestBed.configureTestingModule({ imports: [App], providers: [provideRouter([])] }); + }); + afterEach(() => { vi.restoreAllMocks(); vi.unstubAllGlobals(); }); + function render() { + const fixture = TestBed.createComponent(App); + fixture.detectChanges(); + return fixture; + } + function scroll(fixture: ReturnType, position: number) { + scrollY = position; + window.dispatchEvent(new Event('scroll')); + fixture.detectChanges(); + } + it('oculta al inicio y en el umbral, muestra después y vuelve a ocultar al subir', () => { + const fixture = render(); + expect(fixture.nativeElement.querySelector('.back-to-top')).toBeNull(); + scroll(fixture, 400); + expect(fixture.nativeElement.querySelector('.back-to-top')).toBeNull(); + scroll(fixture, 401); + expect(fixture.nativeElement.querySelector('.back-to-top')).not.toBeNull(); + scroll(fixture, 0); + expect(fixture.nativeElement.querySelector('.back-to-top')).toBeNull(); + }); + it('reconoce una posición restaurada al montar el shell', () => { + scrollY = 900; + expect(render().nativeElement.querySelector('.back-to-top')).not.toBeNull(); + }); + it.each([false, true])('activa un botón nativo y respeta movimiento reducido=%s', reduced => { + const matchMedia = vi.fn().mockReturnValue({ matches: reduced } as MediaQueryList); + vi.stubGlobal('matchMedia', matchMedia); + const scrollTo = vi.spyOn(window, 'scrollTo').mockImplementation(() => {}); + const fixture = render(); + scroll(fixture, 900); + const button = fixture.nativeElement.querySelector('.back-to-top') as HTMLButtonElement; + const main = fixture.nativeElement.querySelector('main') as HTMLElement; + const focus = vi.spyOn(main, 'focus'); + expect(button.type).toBe('button'); + expect(button.tabIndex).toBe(0); + expect(button.getAttribute('aria-label')).toBe('Volver al inicio'); + expect(button.querySelector('svg')?.getAttribute('aria-hidden')).toBe('true'); + button.click(); + expect(matchMedia).toHaveBeenCalledWith('(prefers-reduced-motion: reduce)'); + expect(scrollTo).toHaveBeenCalledWith({ top: 0, behavior: reduced ? 'instant' : 'smooth' }); + expect(focus).toHaveBeenCalledWith({ preventScroll: true }); + // Native Enter/Space activation is checked in Chrome, not emulated by jsdom. + }); + it('registra un listener pasivo y elimina exactamente el mismo al destruir', () => { + const add = vi.spyOn(window, 'addEventListener'); + const remove = vi.spyOn(window, 'removeEventListener'); + const fixture = render(); + const registration = add.mock.calls.find(call => call[0] === 'scroll')!; + expect(registration[2]).toEqual({ passive: true }); + fixture.destroy(); + expect(remove).toHaveBeenCalledWith('scroll', registration[1]); + scrollY = 900; + window.dispatchEvent(new Event('scroll')); + expect(fixture.componentInstance.showBackToTop()).toBe(false); + }); +}); diff --git a/src/app/app.ts b/src/app/app.ts index 7af688e..ff7f2d1 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,4 +1,5 @@ -import { Component } from '@angular/core'; +import { DOCUMENT } from '@angular/common'; +import { Component, ElementRef, inject, OnDestroy, OnInit, signal, ViewChild } from '@angular/core'; import { RouterOutlet } from '@angular/router'; @Component({ @@ -7,6 +8,26 @@ import { RouterOutlet } from '@angular/router'; styleUrl: './app.scss', templateUrl: './app.html', }) -export class App { +export class App implements OnInit, OnDestroy { protected readonly title = 'Plataforma de Indicadores'; + readonly showBackToTop = signal(false); + @ViewChild('mainContent') private mainContent?: ElementRef; + private readonly browserWindow = inject(DOCUMENT).defaultView; + private readonly updateScroll = () => this.showBackToTop.set((this.browserWindow?.scrollY ?? 0) > 400); + + ngOnInit() { + this.updateScroll(); + this.browserWindow?.addEventListener('scroll', this.updateScroll, { passive: true }); + } + + backToTop() { + const reducedMotion = this.browserWindow?.matchMedia?.('(prefers-reduced-motion: reduce)').matches; + // Keep keyboard focus near the destination when the floating button disappears. + this.mainContent?.nativeElement.focus({ preventScroll: true }); + this.browserWindow?.scrollTo({ top: 0, behavior: reducedMotion ? 'instant' : 'smooth' }); + } + + ngOnDestroy() { + this.browserWindow?.removeEventListener('scroll', this.updateScroll); + } } diff --git a/src/app/features/indicadores/indicador-figure-card.html b/src/app/features/indicadores/indicador-figure-card.html index d0971ec..d4f4a4d 100644 --- a/src/app/features/indicadores/indicador-figure-card.html +++ b/src/app/features/indicadores/indicador-figure-card.html @@ -2,8 +2,18 @@

Cómo leer esta figura · {{ selected?.contrato }}

    - @for (line of interpretation; track $index) {
  • {{ line }}
  • } + @for (line of visibleInterpretation; track $index) {
  • {{ line }}
  • }
+ @if (methodologyDetail.length) { + +
+ @for (line of methodologyDetail; track $index) {

{{ line }}

} +
+ }

Un periodo puede tener reportes calculados sin valores estadísticos representables. La leyenda de la figura no permite determinar la disponibilidad real de cada periodo.

} diff --git a/src/app/features/indicadores/indicador-figure-card.scss b/src/app/features/indicadores/indicador-figure-card.scss index 576c8a6..7be5486 100644 --- a/src/app/features/indicadores/indicador-figure-card.scss +++ b/src/app/features/indicadores/indicador-figure-card.scss @@ -1,12 +1,22 @@ :host { display: block; min-width: 0; } -.interpretation { padding: 1rem 1.25rem; margin-bottom: 1.5rem; border-radius: 8px; background: var(--mat-sys-surface-container-low); color: var(--mat-sys-on-surface); font: var(--mat-sys-body-medium); line-height: 1.5; overflow-wrap: anywhere; } -.interpretation h2 { margin: 0 0 .5rem; font: var(--mat-sys-title-small); } +.interpretation { + padding: var(--issste-space-4); + margin-bottom: var(--issste-space-4); + border-left: 3px solid var(--issste-accent); + color: var(--issste-text); + font-family: var(--issste-font-body); + line-height: 1.5; + overflow-wrap: anywhere; +} +.interpretation h2 { margin: 0 0 .5rem; font-family: var(--issste-font-heading); font-size: 1.125rem; } .interpretation ul { margin: 0; padding-left: 1.25rem; } .interpretation li + li { margin-top: .25rem; } -.period-note { margin: .75rem 0 0; color: var(--mat-sys-on-surface-variant); } -.figure-card { overflow: hidden; min-width: 0; } -.figure-title { display: block; padding: 1rem 1rem 0; margin: 0; font: var(--mat-sys-title-medium); overflow-wrap: anywhere; } -.state { padding: 1.25rem; margin: 0; } +.period-note { margin: .75rem 0 0; color: var(--issste-text-secondary); } +.methodology-toggle { margin-top: var(--issste-space-3); min-height: 44px; max-width: 100%; height: auto; white-space: normal; } +.methodology-toggle:focus-visible { outline: 2px solid var(--issste-text); outline-offset: 3px; } +.figure-card { overflow: visible; min-width: 0; border: 1px solid var(--issste-border); } +.figure-title { display: block; padding: 1rem 1rem 0; margin: 0; font: var(--mat-sys-title-medium); font-family: var(--issste-font-heading); overflow-wrap: anywhere; } +.state { padding: 1.25rem; margin: 0; overflow-wrap: anywhere; } .dark { background: #151b28; color: #eef1f7; color-scheme: dark; --mat-sys-primary: #b1c9ff; --mat-sys-outline: #a1aabd; } .figure-id { padding: .25rem 1rem 0; margin: 0; font: var(--mat-sys-body-small); opacity: .8; overflow-wrap: anywhere; } -@media (max-width: 550px) { .interpretation { padding: 1rem; } } +@media (max-width: 550px) { .interpretation { padding: var(--issste-space-3); } } diff --git a/src/app/features/indicadores/indicador-figure-card.spec.ts b/src/app/features/indicadores/indicador-figure-card.spec.ts index d2e4d6d..0f99470 100644 --- a/src/app/features/indicadores/indicador-figure-card.spec.ts +++ b/src/app/features/indicadores/indicador-figure-card.spec.ts @@ -128,4 +128,67 @@ describe('IndicadorFigureCard', () => { expect(purge).toHaveBeenCalledWith(secondHost); expect(disconnect).toHaveBeenCalledTimes(2); }); + it('UX-06D pliega solo el detalle complementario local C2 y mantiene advertencias visibles', () => { + fixture.componentRef.setInput('figuraId', 'fig_c2_apiladas'); + state({ status: 'idle' }); + const section = fixture.nativeElement.querySelector('.interpretation') as HTMLElement; + expect(section.querySelector('ul')?.textContent).toContain('Las barras muestran la composición porcentual'); + expect(section.querySelector('ul')?.textContent).toContain('SIN_DATO'); + expect(section.querySelector('ul')?.textContent).toContain('suprimidos no representan tasas'); + expect(section.querySelector('.period-note')?.textContent).toContain('no permite determinar la disponibilidad'); + const button = section.querySelector('button')!; + const detail = section.querySelector('[id]') as HTMLElement; + expect(button.getAttribute('aria-expanded')).toBe('false'); + expect(button.getAttribute('aria-controls')).toBe(detail.id); + expect(detail.hidden).toBe(true); + expect(detail.textContent?.trim()).toBe('Las categorías corresponden a la distribución de cada grupo y periodo.'); + expect([...section.querySelectorAll('li')].map(li => li.textContent)).toEqual(fixture.componentInstance.visibleInterpretation); + button.click(); fixture.detectChanges(); + expect(detail.hidden).toBe(false); expect(button.getAttribute('aria-expanded')).toBe('true'); + state({ status: 'loading' }); + expect(detail.hidden).toBe(false); + button.click(); fixture.detectChanges(); + expect(detail.hidden).toBe(true); + }); + it.each(['fig_c1_puntos', 'fig_c3r_cajas', 'desconocida'])('UX-06D mantiene íntegra la interpretación %s sin separación insegura', figura => { + fixture.componentRef.setInput('figuraId', figura); + if (figura === 'desconocida') fixture.componentRef.setInput('selected', { ...selected, contrato: 'desconocido' }); + state({ status: 'idle' }); + expect(fixture.nativeElement.querySelector('.methodology-toggle')).toBeNull(); + expect([...fixture.nativeElement.querySelectorAll('.interpretation li')].map((li: any) => li.textContent)) + .toEqual(fixture.componentInstance.interpretation); + }); + it.each(['cacu', 'cama'])('UX-06D mantiene toda la interpretación C2 de %s visible', dominio => { + fixture.componentRef.setInput('dominio', dominio); + fixture.componentRef.setInput('figuraId', 'fig_c2_apiladas'); + state({ status: 'loading' }); + expect(fixture.nativeElement.querySelector('.methodology-toggle')).toBeNull(); + expect(fixture.nativeElement.querySelector('.interpretation').textContent).toContain('nulos o suprimidos no representan porcentajes observados de 0 %'); + }); + it('UX-06D conserva completas todas las anotaciones, sin clasificar ni plegar notas del backend', async () => { + const figure: PlotlyFigure = { data: [{ y: [null, 0] }], layout: { annotations: [ + { text: 'Denominador pequeño
Intervalos no disponibles' }, + { text: 'Uso exclusivo de investigación. No usar para decisiones clínicas.' }, + { text: 'Supresión: consulta las notas completas' }, + ] }, frames: [] }; + const snapshot = JSON.stringify(figure); + ready(figure); await settle(); + const notes = fixture.nativeElement.querySelector('.notes') as HTMLElement; + expect(notes.closest('[hidden]')).toBeNull(); + expect([...notes.querySelectorAll('p')].map(p => p.innerHTML)).toEqual((figure.layout['annotations'] as { text: string }[]).map(a => a.text)); + expect(JSON.stringify(figure)).toBe(snapshot); + expect(fixture.nativeElement.querySelector('.plot-viewport')?.getAttribute('tabindex')).toBe('0'); + }); + it('UX-06D mantiene relaciones de detalle únicas incluso con separadores en IDs publicados', () => { + fixture.componentRef.setInput('selected', { ...selected, contrato: 'C2', id: 'a--b' }); + fixture.componentRef.setInput('figuraId', 'fig_c2_apiladas'); + state({ status: 'idle' }); + const first = fixture.nativeElement.querySelector('.methodology-toggle').getAttribute('aria-controls'); + fixture.componentRef.setInput('selected', { ...selected, contrato: 'C2', id: 'a' }); + fixture.componentRef.setInput('figuraId', 'b--fig_c2_apiladas'); + fixture.detectChanges(); + const second = fixture.nativeElement.querySelector('.methodology-toggle').getAttribute('aria-controls'); + expect(first).not.toBe(second); + expect(fixture.nativeElement.querySelector('[id]').id).toBe(second); + }); }); diff --git a/src/app/features/indicadores/indicador-figure-card.ts b/src/app/features/indicadores/indicador-figure-card.ts index 625fd70..fbf67b0 100644 --- a/src/app/features/indicadores/indicador-figure-card.ts +++ b/src/app/features/indicadores/indicador-figure-card.ts @@ -1,9 +1,10 @@ -import { Component, Input, output } from '@angular/core'; +import { Component, Input, output, signal } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { MatCardModule } from '@angular/material/card'; import { MatProgressBarModule } from '@angular/material/progress-bar'; import { Dominio, hasNoVisibleValues, Indicador, PlotlyFigure, Tema } from './indicadores.models'; import { figureTitle } from './indicadores.presentation'; +import { figureIdentity, identityElementId } from './indicadores-identities'; import { PlotlyChart } from '../../shared/plotly/plotly-chart'; // The panel owns requests; the card receives the original and its presentation copy. @@ -49,6 +50,19 @@ export class IndicadorFigureCard { @Input({ required: true }) dominio!: Dominio; @Input({ required: true }) tema!: Tema; readonly retry = output(); + readonly methodologyExpanded = signal(false); + get methodologyId(): string { + return identityElementId(figureIdentity(this.dominio, this.selected?.id ?? '', this.figuraId)) + '-methodology'; + } + + // Only this exact local C2 sentence is complementary. Backend notes and + // uncertainty/suppression warnings are never classified or collapsed. + get methodologyDetail(): readonly string[] { + return this.interpretation.filter(line => line === CONTRACT_INTERPRETATIONS['C2'][1]); + } + get visibleInterpretation(): readonly string[] { + return this.interpretation.filter(line => line !== CONTRACT_INTERPRETATIONS['C2'][1]); + } readonly hasNoVisibleValues = hasNoVisibleValues; readonly figureTitle = figureTitle; diff --git a/src/app/features/indicadores/indicadores-page.html b/src/app/features/indicadores/indicadores-page.html index 7bed319..90cc577 100644 --- a/src/app/features/indicadores/indicadores-page.html +++ b/src/app/features/indicadores/indicadores-page.html @@ -9,7 +9,6 @@ {{ domainLabels[domain] }} } -

Uso exclusivo de investigación. No usar para decisiones clínicas.

@if (catalogLoading()) { @@ -21,11 +20,6 @@

No hay indicadores disponibles en el catálogo.

} @else { - Tema del dominio - - ClaroOscuro - -

{{ catalog().length }} indicadores publicados

@if (searchVisible()) {