diff --git a/src/app/features/indicadores/indicador-figure-card.html b/src/app/features/indicadores/indicador-figure-card.html index d4f4a4d..cb66b09 100644 --- a/src/app/features/indicadores/indicador-figure-card.html +++ b/src/app/features/indicadores/indicador-figure-card.html @@ -6,11 +6,13 @@ @if (methodologyDetail.length) { -
+
@for (line of methodologyDetail; track $index) {

{{ line }}

}
} diff --git a/src/app/features/indicadores/indicador-figure-card.scss b/src/app/features/indicadores/indicador-figure-card.scss index 7be5486..ce2b6df 100644 --- a/src/app/features/indicadores/indicador-figure-card.scss +++ b/src/app/features/indicadores/indicador-figure-card.scss @@ -13,6 +13,9 @@ .interpretation li + li { margin-top: .25rem; } .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-detail { margin-top: var(--issste-space-3); } +.methodology-detail p { margin: 0; } +.methodology-detail p + p { margin-top: var(--issste-space-2); } .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; } diff --git a/src/app/features/indicadores/indicador-figure-card.spec.ts b/src/app/features/indicadores/indicador-figure-card.spec.ts index 0f99470..c8aa834 100644 --- a/src/app/features/indicadores/indicador-figure-card.spec.ts +++ b/src/app/features/indicadores/indicador-figure-card.spec.ts @@ -54,7 +54,7 @@ describe('IndicadorFigureCard', () => { fixture.componentInstance.retry.subscribe(retry); state({ status: 'error', message: 'La figura o los reportes no están disponibles para esta selección.' }); expect(fixture.nativeElement.querySelector('[role=alert]').textContent).toContain('reportes no están disponibles'); - fixture.nativeElement.querySelector('button').click(); + fixture.nativeElement.querySelector('.state button').click(); expect(retry).toHaveBeenCalledTimes(1); expect(fixture.debugElement.query(By.directive(PlotlyChart))).toBeNull(); }); @@ -107,7 +107,7 @@ describe('IndicadorFigureCard', () => { expect(fixture.nativeElement.textContent).toContain('No se pudo representar la figura'); const retry = vi.fn(); fixture.componentInstance.retry.subscribe(retry); - fixture.nativeElement.querySelector('button').click(); + fixture.nativeElement.querySelector('app-plotly-chart button').click(); await settle(); expect(react).toHaveBeenCalledTimes(2); expect(retry).not.toHaveBeenCalled(); @@ -128,11 +128,13 @@ describe('IndicadorFigureCard', () => { expect(purge).toHaveBeenCalledWith(secondHost); expect(disconnect).toHaveBeenCalledTimes(2); }); - it('UX-06D pliega solo el detalle complementario local C2 y mantiene advertencias visibles', () => { + it('UX-06E.B1 integra composición y 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).not.toContain('Las barras muestran la composición porcentual'); + expect(section.querySelectorAll('button')).toHaveLength(1); + expect(section.querySelectorAll('[hidden]')).toHaveLength(1); 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'); @@ -141,7 +143,10 @@ describe('IndicadorFigureCard', () => { 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([...detail.querySelectorAll('p')].map(p => p.textContent)).toEqual([ + 'Las barras muestran la composición porcentual de cada grupo y periodo.', + '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'); @@ -150,7 +155,7 @@ describe('IndicadorFigureCard', () => { 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 => { + it.each(['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' }); @@ -158,12 +163,16 @@ describe('IndicadorFigureCard', () => { 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 => { + it.each(['cacu', 'cama'])('UX-06E.B1 conserva advertencias C2 de %s y pliega solo composición', 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 %'); + expect(fixture.nativeElement.querySelector('.methodology-toggle')).not.toBeNull(); + const detail = fixture.nativeElement.querySelector('[hidden]') as HTMLElement; + expect(detail.hidden).toBe(true); + expect([...detail.querySelectorAll('p')].map(p => p.textContent)).toEqual(['Las barras muestran la composición porcentual de las categorías publicadas para cada periodo.']); + expect(fixture.nativeElement.querySelector('.interpretation > ul').textContent).toContain('SIN_DATO'); + expect(fixture.nativeElement.querySelector('.interpretation > ul').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: [ @@ -191,4 +200,69 @@ describe('IndicadorFigureCard', () => { expect(first).not.toBe(second); expect(fixture.nativeElement.querySelector('[id]').id).toBe(second); }); + it.each(['tea', 'cacu', 'cama'])('UX-06E.B1 conserva C1 de %s íntegro con condiciones críticas visibles', dominio => { + fixture.componentRef.setInput('dominio', dominio); + state({ status: 'idle' }); + const section = fixture.nativeElement.querySelector('.interpretation') as HTMLElement; + const button = section.querySelector('button')!; + const detail = section.querySelector('[hidden]') as HTMLElement; + expect(button.tagName).toBe('BUTTON'); expect(button.type).toBe('button'); + // jsdom does not perform native Enter/Space activation; leave both keys + // available to the browser and validate activation in Chrome. + for (const key of ['Enter', ' ']) { + const event = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true }); + button.dispatchEvent(event); expect(event.defaultPrevented).toBe(false); + } + expect(button.textContent).toContain('Cómo leer'); + expect(button.getAttribute('aria-label')).toBe('Cómo leer esta figura: Indicador de prueba · ' + dominio + ' · fig_c1_puntos'); + expect(button.getAttribute('aria-expanded')).toBe('false'); + expect(button.getAttribute('aria-controls')).toBe(detail.id); expect(detail.hidden).toBe(true); + const warnings = section.querySelector('ul')!; + expect(warnings.closest('[hidden]')).toBeNull(); + expect(warnings.textContent).toContain('100 % no implica certeza poblacional'); + expect(warnings.textContent).toContain('suprimidos no representan tasas observadas de 0 %'); + if (dominio === 'tea') { + expect(warnings.textContent).toContain('Wilson al 95 %'); + expect(warnings.textContent).toContain('No se infieren intervalos cuando faltan'); + expect(warnings.textContent).toContain('denominadores pequeños'); + } else expect(warnings.textContent).toContain('no entregan intervalos Wilson efectivos'); + expect([...detail.querySelectorAll('p')].map(p => p.textContent)).toEqual([fixture.componentInstance.interpretation[0]]); + expect([...detail.querySelectorAll('p'), ...warnings.querySelectorAll('li')].map(p => p.textContent)) + .toEqual(fixture.componentInstance.interpretation); + button.focus(); button.click(); fixture.detectChanges(); + expect(document.activeElement).toBe(button); expect(detail.hidden).toBe(false); + expect(button.getAttribute('aria-expanded')).toBe('true'); + button.click(); fixture.detectChanges(); + expect(document.activeElement).toBe(button); expect(detail.hidden).toBe(true); + }); + it('UX-06E.B1 mantiene la oración mixta C3r y todos sus límites visibles', () => { + fixture.componentRef.setInput('figuraId', 'fig_c3r_cajas'); state({ status: 'idle' }); + const section = fixture.nativeElement.querySelector('.interpretation') as HTMLElement; + expect(section.querySelector('[hidden]')).toBeNull(); + expect(section.querySelector('button')).toBeNull(); + expect([...section.querySelectorAll('li')].map(p => p.textContent)).toEqual([ + 'La caja representa Q1, mediana y Q3; no contiene observaciones individuales.', + 'Los límites de dibujo no representan necesariamente extremos observados.', + 'Plotly puede mostrar las etiquetas min/max para límites de dibujo derivados de Q1 y Q3. Estos valores no deben interpretarse como los extremos observados de los pacientes.', + 'Los puntos suprimidos no representan tasas observadas de 0 %.', + ]); + }); + it('UX-06E.B1 al alternar ayuda conserva Plotly, JSON, notas y observadores sin react ni purge', async () => { + const original: PlotlyFigure = { data: [{ y: [42, null] }], layout: { annotations: [{ text: 'Advertencia íntegra del servicio' }] } }; + const copy = ready(original); await settle(); + const snapshot = JSON.stringify(original), copySnapshot = JSON.stringify(copy); + const chart = fixture.debugElement.query(By.directive(PlotlyChart)).componentInstance; + const host = fixture.nativeElement.querySelector('.plot'), notes = fixture.nativeElement.querySelector('.notes'); + const button = fixture.nativeElement.querySelector('.methodology-toggle'); + const calls = react.mock.calls.length, observers = observe.mock.calls.length; + for (let i = 0; i < 4; i++) { button.click(); fixture.detectChanges(); await settle(); } + expect(fixture.debugElement.query(By.directive(PlotlyChart)).componentInstance).toBe(chart); + expect(fixture.nativeElement.querySelector('.plot')).toBe(host); + expect(fixture.nativeElement.querySelector('.notes')).toBe(notes); + expect(notes.closest('[hidden]')).toBeNull(); + expect(react).toHaveBeenCalledTimes(calls); expect(observe).toHaveBeenCalledTimes(observers); + expect(purge).not.toHaveBeenCalled(); expect(disconnect).not.toHaveBeenCalled(); + expect(JSON.stringify(original)).toBe(snapshot); expect(JSON.stringify(copy)).toBe(copySnapshot); + }); + }); diff --git a/src/app/features/indicadores/indicador-figure-card.ts b/src/app/features/indicadores/indicador-figure-card.ts index fbf67b0..42ae81a 100644 --- a/src/app/features/indicadores/indicador-figure-card.ts +++ b/src/app/features/indicadores/indicador-figure-card.ts @@ -1,5 +1,6 @@ import { Component, Input, output, signal } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; +import { MatIconModule } from '@angular/material/icon'; import { MatCardModule } from '@angular/material/card'; import { MatProgressBarModule } from '@angular/material/progress-bar'; import { Dominio, hasNoVisibleValues, Indicador, PlotlyFigure, Tema } from './indicadores.models'; @@ -39,7 +40,7 @@ const UNKNOWN_INTERPRETATION = ['No hay una explicación específica disponible @Component({ selector: 'app-indicador-figure-card', standalone: true, - imports: [MatButtonModule, MatCardModule, MatProgressBarModule, PlotlyChart], + imports: [MatButtonModule, MatIconModule, MatCardModule, MatProgressBarModule, PlotlyChart], templateUrl: './indicador-figure-card.html', styleUrl: './indicador-figure-card.scss', }) @@ -55,21 +56,28 @@ export class IndicadorFigureCard { 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. + // Editorial classification of complete local sentences by known family. + // Keep mixed C3r/Wilson sentences and all backend content visible. + private get contract(): string | undefined { + return this.figuraId.startsWith('fig_c1') ? 'C1' + : this.figuraId.startsWith('fig_c2') ? 'C2' + : this.figuraId.startsWith('fig_c3r') ? 'C3r' : this.selected?.contrato; + } + private get complementaryLineCount(): number { + return this.contract === 'C1' ? 1 + : this.contract === 'C2' ? (this.dominio === 'tea' ? 2 : 1) : 0; + } get methodologyDetail(): readonly string[] { - return this.interpretation.filter(line => line === CONTRACT_INTERPRETATIONS['C2'][1]); + return this.interpretation.slice(0, this.complementaryLineCount); } get visibleInterpretation(): readonly string[] { - return this.interpretation.filter(line => line !== CONTRACT_INTERPRETATIONS['C2'][1]); + return this.interpretation.slice(this.complementaryLineCount); } readonly hasNoVisibleValues = hasNoVisibleValues; readonly figureTitle = figureTitle; get interpretation(): readonly string[] { - const contract = this.figuraId.startsWith('fig_c1') ? 'C1' - : this.figuraId.startsWith('fig_c2') ? 'C2' - : this.figuraId.startsWith('fig_c3r') ? 'C3r' : this.selected?.contrato; + const contract = this.contract; if (contract === 'C2' && this.dominio !== 'tea') return [ 'Las barras muestran la composición porcentual de las categorías publicadas para cada periodo.', 'SIN_DATO, cuando aparece, es una categoría legítima de la representación.', diff --git a/src/app/features/indicadores/indicador-figure-panel.spec.ts b/src/app/features/indicadores/indicador-figure-panel.spec.ts index a48c4dd..93ce951 100644 --- a/src/app/features/indicadores/indicador-figure-panel.spec.ts +++ b/src/app/features/indicadores/indicador-figure-panel.spec.ts @@ -145,7 +145,7 @@ describe('IndicadorFigurePanel', () => { expect(page.result().message).toContain(message); fixture.detectChanges(); expect(fixture.nativeElement.textContent).not.toContain('error privado'); - fixture.nativeElement.querySelector('app-indicador-figure-card button').click(); + fixture.nativeElement.querySelector('app-indicador-figure-card .state button').click(); figure().flush({ data: [], layout: {} }); expect(page.result().status).toBe('ready'); }); @@ -219,4 +219,27 @@ describe('IndicadorFigurePanel', () => { expect(page.result().figure?.data[0]['y']).toEqual([12]); }); + it('UX-06E.B1 alterna ayuda sin HTTP y conserva filtros, borrador, memoria y panel', () => { + load(); figure().flush({ data: [{ y: [42] }], layout: {} }); + const control = filters(); control.changeMode('manual'); control.year = '2025'; control.unit = 'S1'; control.add(); + fixture.detectChanges(); + const result = page.result(), filterState = page.filters, snapshot = JSON.stringify(filterState); + const card = fixture.debugElement.query(By.directive(IndicadorFigureCard)).componentInstance; + const chart = fixture.debugElement.query(By.directive(ChartStub)).componentInstance; + const button = fixture.nativeElement.querySelector('.methodology-toggle'); + for (let i = 0; i < 4; i++) { button.click(); fixture.detectChanges(); } + http.expectNone(() => true); + expect(page.result()).toBe(result); expect(page.filters).toBe(filterState); + expect(JSON.stringify(page.filters)).toBe(snapshot); + expect(filters()).toBe(control); + expect(fixture.debugElement.query(By.directive(IndicadorFigureCard)).componentInstance).toBe(card); + expect(fixture.debugElement.query(By.directive(ChartStub)).componentInstance).toBe(chart); + fixture.destroy(); + fixture = TestBed.createComponent(IndicadorFigurePanel); + fixture.componentRef.setInput('dominio', 'tea'); fixture.componentRef.setInput('indicador', catalog[0]); + fixture.componentRef.setInput('figuraId', 'f1'); fixture.componentRef.setInput('tema', 'claro'); + page = fixture.componentInstance; load(); figure().flush({ data: [], layout: {} }); + expect(JSON.stringify(page.filters)).toBe(snapshot); + expect(fixture.nativeElement.querySelector('.methodology-toggle').getAttribute('aria-expanded')).toBe('false'); + }); }); diff --git a/src/app/features/indicadores/indicadores-search.spec.ts b/src/app/features/indicadores/indicadores-search.spec.ts index e053db5..db9fc8a 100644 --- a/src/app/features/indicadores/indicadores-search.spec.ts +++ b/src/app/features/indicadores/indicadores-search.spec.ts @@ -134,6 +134,14 @@ describe('UX-05C búsqueda local y partición estable', () => { const writes = selects.map(e => vi.spyOn(e.injector.get(NgModel).control, 'setValue')); const memory = TestBed.inject(IndicadoresMemory), saves = vi.spyOn(memory, 'save'), restores = vi.spyOn(memory, 'restore'); const reacts = runtime.react.mock.calls.length; + const helps = [...fixture.nativeElement.querySelectorAll('.methodology-toggle')] as HTMLButtonElement[]; + expect(helps).toHaveLength(3); + const helpIds = helps.map(button => button.getAttribute('aria-controls')!); + expect(new Set(helpIds).size).toBe(3); + for (const id of helpIds) expect(document.getElementById(id)?.hidden).toBe(true); + helps[0].click(); fixture.detectChanges(); await settle(); + expect(helps.map(button => button.getAttribute('aria-expanded'))).toEqual(['true', 'false', 'false']); + expect(helpIds.map(id => document.getElementById(id)?.hidden)).toEqual([false, true, true]); for (const query of ['sexo', 'evaluacion', '']) { if (query) await search(query); else { fixture.nativeElement.querySelector('.catalog-search button').click(); fixture.detectChanges(); await settle(); } @@ -143,6 +151,10 @@ describe('UX-05C búsqueda local y partición estable', () => { beforeCharts.forEach(c => expect(charts().find(chart => chart.host.nativeElement === c.host.nativeElement)).toBe(c)); } expect(cards()).toEqual(beforeCards); expect(beforeCards.slice(0, 3).every(c => c.expanded)).toBe(true); + for (const button of helps) expect(button.isConnected).toBe(true); + expect(helps.map(button => button.getAttribute('aria-expanded'))).toEqual(['true', 'false', 'false']); + helps[0].click(); fixture.detectChanges(); await settle(); + expect(document.getElementById(helpIds[0])?.hidden).toBe(true); expect(panels()).toEqual(beforePanels); expect(filters()).toEqual(beforeFilters); expect(charts()).toEqual(beforeCharts); expect(beforePanels.map(p => p.titleId)).toEqual(titleIds); for (const id of titleIds) {