feat(ui): refinar buscador y navegacion UX-06E.A
This commit is contained in:
@@ -58,6 +58,28 @@ describe('IndicadorFigurePanel', () => {
|
||||
}
|
||||
expect(help).toContain('Un periodo puede tener reportes calculados sin valores estadísticos representables');
|
||||
});
|
||||
it('oculta sólo visualmente el encabezado y conserva identidad, lectura y títulos sin HTTP adicional', () => {
|
||||
load(); figure().flush({ data: [], layout: {} }); fixture.detectChanges();
|
||||
const id = page.titleId;
|
||||
const heading = fixture.nativeElement.querySelector('h3') as HTMLElement;
|
||||
const section = fixture.nativeElement.querySelector('section') as HTMLElement;
|
||||
expect(heading.id).toBe(id); expect(id).not.toBe('');
|
||||
expect(section.getAttribute('aria-labelledby')).toBe(id);
|
||||
expect(section.firstElementChild).toBe(heading);
|
||||
expect(heading.textContent).toBe('tea · i1 · Uno · f1');
|
||||
expect(heading.hasAttribute('aria-hidden')).toBe(false); expect(heading.hidden).toBe(false);
|
||||
const style = getComputedStyle(heading);
|
||||
expect(style.display).not.toBe('none'); expect(style.visibility).not.toBe('hidden');
|
||||
expect(style.position).toBe('absolute'); expect(style.width).toBe('1px'); expect(style.height).toBe('1px');
|
||||
expect(style.clipPath).toBe('inset(50%)'); expect(style.overflow).toBe('hidden');
|
||||
expect(fixture.nativeElement.querySelector('.figure-title').textContent).toBe('Uno');
|
||||
expect(fixture.nativeElement.querySelector('app-indicador-period-filters')).toBeTruthy();
|
||||
const result = page.result(), state = page.filters;
|
||||
fixture.detectChanges();
|
||||
expect(page.titleId).toBe(id); expect(page.filters).toBe(state); expect(page.result()).toBe(result);
|
||||
expect(fixture.nativeElement.querySelector('h3')).toBe(heading);
|
||||
http.expectNone(() => true);
|
||||
});
|
||||
it('entrega al gráfico una copia de presentación y conserva el JSON HTTP íntegro', () => {
|
||||
load();
|
||||
const received: PlotlyFigure = {
|
||||
|
||||
@@ -16,7 +16,7 @@ import { figureIdentity, identityElementId } from './indicadores-identities';
|
||||
imports: [IndicadorPeriodFilters, IndicadorFigureCard],
|
||||
template: `
|
||||
<section [attr.aria-labelledby]="titleId">
|
||||
<h3 [id]="titleId">{{ dominio }} · {{ indicador.id }} · {{ indicador.titulo }} · {{ figuraId }}</h3>
|
||||
<h3 class="visually-hidden" [id]="titleId">{{ dominio }} · {{ indicador.id }} · {{ indicador.titulo }} · {{ figuraId }}</h3>
|
||||
@if (filters; as state) {
|
||||
<app-indicador-period-filters [state]="state" [types]="indicador.tipos_periodo"
|
||||
(edited)="filtersEdited()" (apply)="applyFilters()" />
|
||||
@@ -28,8 +28,10 @@ import { figureIdentity, identityElementId } from './indicadores-identities';
|
||||
styles: `
|
||||
:host { display: block; min-width: 0; }
|
||||
section { margin-top: var(--issste-space-6); padding-top: var(--issste-space-4); border-top: 1px solid var(--issste-border); }
|
||||
h3 { margin: 0 0 var(--issste-space-4); overflow-wrap: anywhere; color: var(--issste-text);
|
||||
font-family: var(--issste-font-heading); font-weight: 600; font-size: 1.25rem; line-height: 1.4; }
|
||||
.visually-hidden {
|
||||
position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
|
||||
overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class IndicadorFigurePanel implements OnChanges, OnDestroy {
|
||||
|
||||
@@ -36,6 +36,34 @@ describe('UX-04 navegación Angular', () => {
|
||||
return req;
|
||||
}
|
||||
afterEach(() => http.verify());
|
||||
it.each(['tea', 'cacu', 'cama'] as const)('navegación %s mantiene tres enlaces, estado, decoración y foco independiente', async domain => {
|
||||
const harness = await setup();
|
||||
await harness.navigateByUrl('/indicadores/' + domain, IndicadoresPage);
|
||||
load(domain, harness); harness.detectChanges();
|
||||
const links = Array.from(harness.routeNativeElement!.querySelectorAll('nav a')) as HTMLAnchorElement[];
|
||||
expect(links.map(a => a.textContent?.trim())).toEqual(['TEA', 'CaCu', 'CaMa']);
|
||||
expect(links.map(a => a.getAttribute('href'))).toEqual(['/indicadores/tea', '/indicadores/cacu', '/indicadores/cama']);
|
||||
const selected = links.find(a => a.getAttribute('aria-current') === 'page')!;
|
||||
expect(selected.getAttribute('href')).toBe('/indicadores/' + domain);
|
||||
expect(links.filter(a => a.hasAttribute('aria-current'))).toHaveLength(1);
|
||||
// Check the compiled CSSOM rule against the actual encapsulated element.
|
||||
// jsdom's computed link decoration can remain stale after aria-current changes.
|
||||
const activeRule = Array.from(document.styleSheets).flatMap(sheet => Array.from(sheet.cssRules))
|
||||
.find((rule): rule is CSSStyleRule => rule instanceof CSSStyleRule
|
||||
&& rule.selectorText.includes('[aria-current=') && selected.matches(rule.selectorText))!;
|
||||
expect(activeRule).toBeTruthy();
|
||||
expect(activeRule.style.getPropertyValue('text-decoration')).toBe('none');
|
||||
expect(activeRule.style.getPropertyValue('font-weight')).toBe('700');
|
||||
expect(activeRule.style.getPropertyValue('background')).toBe('var(--issste-accent)');
|
||||
for (const link of links) {
|
||||
expect(link.tabIndex).toBe(0);
|
||||
link.focus(); expect(document.activeElement).toBe(link);
|
||||
const key = new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true });
|
||||
link.dispatchEvent(key); expect(key.defaultPrevented).toBe(false);
|
||||
expect(selected.getAttribute('aria-current')).toBe('page');
|
||||
}
|
||||
http.expectNone(() => true);
|
||||
});
|
||||
it('mantiene la ruta, restaura borradores y reconsulta la aplicación entre TEA/CaCu/CaMa', async () => {
|
||||
const harness = await setup();
|
||||
const tea = await harness.navigateByUrl('/indicadores/tea', IndicadoresPage);
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
<div class="catalog-search">
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Buscar indicadores</mat-label>
|
||||
<input matInput type="search" [ngModel]="searchQuery()" (ngModelChange)="changeSearchQuery($event)"
|
||||
<input #searchInput matInput type="search" [ngModel]="searchQuery()" (ngModelChange)="changeSearchQuery($event)"
|
||||
placeholder="Título o identificador" aria-describedby="catalog-search-help catalog-search-result" />
|
||||
<mat-hint id="catalog-search-help">Las coincidencias aparecen primero; todos los indicadores siguen visibles.</mat-hint>
|
||||
</mat-form-field>
|
||||
<button mat-stroked-button type="button" (click)="changeSearchQuery('')" [disabled]="!searchQuery()"
|
||||
aria-label="Limpiar búsqueda de indicadores">Limpiar</button>
|
||||
<button mat-icon-button type="button" (click)="clearSearch()" [disabled]="!searchQuery()"
|
||||
aria-label="Limpiar búsqueda"><mat-icon aria-hidden="true">close</mat-icon></button>
|
||||
</div>
|
||||
<p id="catalog-search-result" class="search-result">
|
||||
@if (searchResults().active) {
|
||||
|
||||
@@ -6,8 +6,8 @@ header p { color: var(--mat-sys-on-surface-variant); margin-bottom: 1.5rem; }
|
||||
.state { padding: 1.25rem; margin: 0; }
|
||||
mat-form-field { width: 100%; max-width: 24rem; }
|
||||
@media (max-width: 550px) { h1 { font-size: var(--mat-sys-headline-medium-size); line-height: var(--mat-sys-headline-medium-line-height); } }
|
||||
.catalog-search { display: flex; align-items: flex-start; gap: var(--issste-space-3); flex-wrap: wrap; margin-top: var(--issste-space-4); }
|
||||
.catalog-search button { margin-top: .5rem; }
|
||||
.catalog-search { display: flex; justify-content: flex-end; align-items: flex-start; gap: var(--issste-space-3); flex-wrap: wrap; margin-top: var(--issste-space-4); }
|
||||
.catalog-search button { flex: 0 0 48px; width: 48px; height: 48px; margin-top: .25rem; }
|
||||
.search-result { color: var(--mat-sys-on-surface-variant); font: var(--mat-sys-body-medium); }
|
||||
|
||||
nav {
|
||||
@@ -33,14 +33,14 @@ nav a {
|
||||
nav a[aria-current='page'] {
|
||||
background: var(--issste-accent);
|
||||
font-weight: 700;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: .25em;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.catalog-search mat-form-field { flex: 1 1 18rem; min-width: 0; max-width: 32rem; }
|
||||
.search-result { overflow-wrap: anywhere; margin: var(--issste-space-2) 0 var(--issste-space-4); }
|
||||
@media (max-width: 550px) {
|
||||
.catalog-search mat-form-field { flex-basis: 100%; max-width: none; }
|
||||
.catalog-search button { margin-top: 0; min-height: 44px; }
|
||||
.catalog-search { justify-content: flex-start; flex-wrap: nowrap; }
|
||||
.catalog-search mat-form-field { flex-basis: 0; width: auto; max-width: none; }
|
||||
.catalog-search button { margin-top: .25rem; }
|
||||
nav { gap: var(--issste-space-2); padding-inline: 0; }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { afterNextRender, ChangeDetectorRef, Component, DestroyRef, ElementRef, Injector, inject, computed, signal } from '@angular/core';
|
||||
import { afterNextRender, ChangeDetectorRef, Component, DestroyRef, ElementRef, Injector, inject, computed, signal, viewChild } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { ActivatedRoute, RouterLink } from '@angular/router';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
@@ -7,6 +7,7 @@ import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { catchError, map, of, startWith, Subject, switchMap } from 'rxjs';
|
||||
@@ -19,7 +20,7 @@ import { httpMessage } from './indicadores-http';
|
||||
|
||||
@Component({
|
||||
selector: 'app-indicadores-page',
|
||||
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatSelectModule, MatProgressBarModule, IndicadorCatalogCard],
|
||||
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, IndicadorCatalogCard],
|
||||
templateUrl: './indicadores-page.html',
|
||||
styleUrl: './indicadores-page.scss',
|
||||
})
|
||||
@@ -27,6 +28,11 @@ export class IndicadoresPage {
|
||||
private readonly document = inject(DOCUMENT);
|
||||
private readonly element = inject<ElementRef<HTMLElement>>(ElementRef);
|
||||
private readonly injector = inject(Injector);
|
||||
private readonly searchInput = viewChild<ElementRef<HTMLInputElement>>('searchInput');
|
||||
clearSearch() {
|
||||
this.changeSearchQuery('');
|
||||
this.searchInput()?.nativeElement.focus({ preventScroll: true });
|
||||
}
|
||||
changeSearchQuery(query: string) {
|
||||
const focused = this.document.activeElement;
|
||||
this.searchQuery.set(query);
|
||||
|
||||
@@ -93,8 +93,30 @@ describe('UX-05C búsqueda local y partición estable', () => {
|
||||
for (const id of field.getAttribute('aria-describedby')!.split(' ')) expect(document.getElementById(id)).toBeTruthy();
|
||||
expect(fixture.nativeElement.querySelector('#catalog-search-result').getAttribute('aria-live')).toBeNull();
|
||||
const clear = fixture.nativeElement.querySelector('.catalog-search button') as HTMLButtonElement;
|
||||
expect(clear.getAttribute('aria-label')).toContain('Limpiar búsqueda'); clear.click(); fixture.detectChanges(); await settle();
|
||||
expect(clear.getAttribute('aria-label')).toBe('Limpiar búsqueda'); clear.focus(); expect(document.activeElement).toBe(clear); clear.click(); fixture.detectChanges(); await settle();
|
||||
expect(page.searchQuery()).toBe(''); expect(field.value).toBe(''); expect(cards().map(c => c.indicador.id)).toEqual(items.map(i => i.id));
|
||||
expect(clear.disabled).toBe(true); expect(input()).toBe(field); expect(document.activeElement).toBe(field);
|
||||
await search('edad'); field.setSelectionRange(2, 2); expect(document.activeElement).toBe(field); expect(field.selectionStart).toBe(2);
|
||||
http.expectNone(() => true);
|
||||
});
|
||||
it('botón nativo iconográfico conserva nombre, semántica, tamaño y estado sin HTTP', async () => {
|
||||
load(); await settle();
|
||||
const clear = fixture.nativeElement.querySelector('.catalog-search button') as HTMLButtonElement;
|
||||
expect(clear.type).toBe('button'); expect(clear.disabled).toBe(true);
|
||||
expect(clear.getAttribute('aria-label')).toBe('Limpiar búsqueda');
|
||||
const icon = clear.querySelector('mat-icon')!;
|
||||
expect(icon.textContent).toBe('close'); expect(icon.getAttribute('aria-hidden')).toBe('true');
|
||||
expect(clear.textContent).not.toContain('Limpiar');
|
||||
expect(getComputedStyle(clear).width).toBe('48px'); expect(getComputedStyle(clear).height).toBe('48px');
|
||||
await search('sexo'); expect(clear.disabled).toBe(false); expect(clear.tabIndex).toBe(0);
|
||||
// jsdom does not synthesize native keyboard activation. Verify that keys remain
|
||||
// available to the browser; Enter/Space activation is a Chrome acceptance check.
|
||||
for (const key of ['Enter', ' ']) {
|
||||
const event = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true });
|
||||
clear.dispatchEvent(event); expect(event.defaultPrevented).toBe(false);
|
||||
}
|
||||
clear.focus(); clear.click(); fixture.detectChanges(); await settle();
|
||||
expect(document.activeElement).toBe(input()); expect(clear.disabled).toBe(true);
|
||||
http.expectNone(() => true);
|
||||
});
|
||||
it('tres tarjetas abiertas conservan paneles, borrador/aplicado, Forms, memoria y hosts Plotly sin react/purge', async () => {
|
||||
@@ -105,13 +127,16 @@ describe('UX-05C búsqueda local y partición estable', () => {
|
||||
c.unit = 'S2'; c.add(); c.year = '2026';
|
||||
beforeFilters[1].changeMode('manual'); fixture.detectChanges(); await settle();
|
||||
const states = beforePanels.map(p => p.filters), results = beforePanels.map(p => p.result());
|
||||
const titleIds = beforePanels.map(p => p.titleId);
|
||||
expect(new Set(titleIds).size).toBe(beforePanels.length);
|
||||
const snapshots = states.map(s => JSON.stringify(s)), hosts = beforeCharts.map(c => c.host.nativeElement);
|
||||
const selects = fixture.debugElement.queryAll(By.directive(MatSelect)).filter(e => e.componentInstance.multiple);
|
||||
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;
|
||||
for (const query of ['sexo', 'evaluacion', '']) {
|
||||
await search(query);
|
||||
if (query) await search(query);
|
||||
else { fixture.nativeElement.querySelector('.catalog-search button').click(); fixture.detectChanges(); await settle(); }
|
||||
for (const card of beforeCards) expect(cards().find(c => c.indicador.id === card.indicador.id)).toBe(card);
|
||||
for (const panel of beforePanels) expect(panels().find(p => p.indicador.id === panel.indicador.id)).toBe(panel);
|
||||
beforeFilters.forEach(c => expect(filters().find(f => f.state === c.state)).toBe(c));
|
||||
@@ -119,6 +144,11 @@ describe('UX-05C búsqueda local y partición estable', () => {
|
||||
}
|
||||
expect(cards()).toEqual(beforeCards); expect(beforeCards.slice(0, 3).every(c => c.expanded)).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) {
|
||||
const heading = document.getElementById(id)!;
|
||||
expect(heading.tagName).toBe('H3'); expect(heading.parentElement!.getAttribute('aria-labelledby')).toBe(id);
|
||||
}
|
||||
beforePanels.forEach((p, i) => { expect(p.filters).toBe(states[i]); expect(JSON.stringify(p.filters)).toBe(snapshots[i]); expect(p.result()).toBe(results[i]); });
|
||||
beforeCharts.forEach((c, i) => expect(c.host.nativeElement).toBe(hosts[i]));
|
||||
expect(c.year).toBe('2026'); expect(c.unit).toBe('S2'); expect(c.selectedPeriods).toEqual(['2025-S1', '2025-S2']);
|
||||
|
||||
Reference in New Issue
Block a user