feat(ui): integrar grid y KPI preliminares UX-06E.D.1

This commit is contained in:
Angel Capetillo Zavala
2026-10-13 16:01:48 -06:00
parent f96fe97ed6
commit 35e1bc33d3
7 changed files with 216 additions and 50 deletions
@@ -0,0 +1,34 @@
import { TestBed } from '@angular/core/testing';
import { IndicadorKpiCard } from './indicador-kpi-card';
describe('UX-06E.D.1 KPI presentacional', () => {
it('presenta título y definición pendiente sin valores, unidades, fechas ni controles', () => {
const fixture = TestBed.createComponent(IndicadorKpiCard);
fixture.componentRef.setInput('title', 'Indicador destacado 1'); fixture.detectChanges();
expect(fixture.nativeElement.querySelector('h3').textContent).toBe('Indicador destacado 1');
expect(fixture.nativeElement.querySelector('.kpi-state').textContent).toBe('Pendiente de definición');
expect(fixture.nativeElement.querySelector('.value')).toBeNull();
expect(fixture.nativeElement.querySelectorAll('p')).toHaveLength(1);
expect(fixture.nativeElement.querySelector('button, input, app-plotly-chart')).toBeNull();
fixture.destroy();
});
it.each([null, undefined])('omite el valor opcional %s sin convertirlo a cero', value => {
const fixture = TestBed.createComponent(IndicadorKpiCard);
fixture.componentRef.setInput('title', 'Presentación'); fixture.componentRef.setInput('value', value);
fixture.detectChanges(); expect(fixture.nativeElement.querySelector('.value')).toBeNull(); fixture.destroy();
});
it('admite contenido opcional suministrado por su consumidor sin servicios ni formatos impuestos', () => {
const fixture = TestBed.createComponent(IndicadorKpiCard);
for (const [name, value] of Object.entries({ title: 'Título de prueba', value: 'Valor de prueba', unit: 'Unidad de prueba',
temporalReference: 'Referencia de prueba', state: 'Estado de prueba', additionalInfo: 'Información de prueba' })) {
fixture.componentRef.setInput(name, value);
}
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('.value').textContent).toContain('Valor de prueba');
expect(fixture.nativeElement.querySelector('.value span').textContent).toBe('Unidad de prueba');
expect(fixture.nativeElement.textContent).toContain('Referencia de prueba');
expect(fixture.nativeElement.querySelector('.kpi-state').textContent).toBe('Estado de prueba');
expect(fixture.nativeElement.querySelector('.additional-info').textContent).toBe('Información de prueba');
fixture.destroy();
});
});
@@ -0,0 +1,37 @@
import { Component, Input } from '@angular/core';
import { MatCardModule } from '@angular/material/card';
@Component({
selector: 'app-indicador-kpi-card',
imports: [MatCardModule],
template: `
<mat-card>
<h3>{{ title }}</h3>
@if (value !== null && value !== undefined) {
<p class="value">{{ value }}@if (unit) { <span>{{ unit }}</span> }</p>
}
@if (temporalReference) { <p>{{ temporalReference }}</p> }
<p class="kpi-state">{{ state }}</p>
@if (additionalInfo) { <p class="additional-info">{{ additionalInfo }}</p> }
</mat-card>
`,
styles: `
:host { display: block; min-width: 0; }
mat-card { box-sizing: border-box; height: 100%; padding: var(--issste-space-6);
background: var(--issste-surface); color: var(--issste-text); border: 1px solid var(--issste-border);
border-radius: var(--issste-radius); box-shadow: none; }
h3 { margin: 0; font-family: var(--issste-font-heading); font-size: 1.25rem; line-height: 1.3; }
h3, p { overflow-wrap: anywhere; }
p { margin: var(--issste-space-3) 0 0; }
.kpi-state, .additional-info { color: var(--issste-text-secondary); font: var(--mat-sys-body-medium); }
.value { font: var(--mat-sys-headline-medium); }
`,
})
export class IndicadorKpiCard {
@Input({ required: true }) title!: string;
@Input() value?: string | number | null;
@Input() unit?: string;
@Input() temporalReference?: string;
@Input() state = 'Pendiente de definición';
@Input() additionalInfo?: string;
}
@@ -10,41 +10,60 @@
}
</nav>
@if (catalogLoading()) {
<mat-progress-bar mode="indeterminate" aria-label="Cargando catálogo" />
<p role="status">Cargando catálogo de indicadores…</p>
} @else if (catalogError()) {
<mat-card class="state" role="alert"><p>{{ catalogError() }}</p>
<button mat-stroked-button (click)="retryCatalog()">Reintentar catálogo</button></mat-card>
} @else if (!catalog().length) {
<mat-card class="state"><p role="status">No hay indicadores disponibles en el catálogo.</p>
<button mat-stroked-button (click)="retryCatalog()">Actualizar catálogo</button></mat-card>
} @else {
<p role="status">{{ catalog().length }} indicadores publicados</p>
@if (searchVisible()) {
<div class="catalog-search">
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Buscar indicadores</mat-label>
<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-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) {
@if (searchResults().count) {
{{ searchResults().count }} coincidencias de {{ catalog().length }} indicadores. Todos permanecen disponibles.
} @else {
No se encontraron coincidencias. El catálogo completo permanece disponible en su orden original.
<section class="kpi-section" aria-labelledby="kpi-section-title" [attr.data-domain]="dominio">
<h2 id="kpi-section-title" class="section-title">Indicadores destacados — Vista preliminar</h2>
<p class="section-description">Muestra visual de {{ domainLabels[dominio] }}. Las definiciones y fuentes de estos indicadores están pendientes.</p>
<div class="kpi-grid">
@for (preview of kpiPreviewsByDomain[dominio]; track dominio + ':' + preview.id) {
<app-indicador-kpi-card [title]="preview.title" />
}
</div>
</section>
<section class="graphic-section" aria-labelledby="graphic-section-title">
<div class="catalog-heading">
<h2 id="graphic-section-title" class="section-title">Indicadores gráficos</h2>
@if (!catalogLoading() && !catalogError() && catalog().length) {
<p class="catalog-count" role="status">{{ catalog().length }} indicadores publicados</p>
}
</div>
@if (catalogLoading()) {
<mat-progress-bar mode="indeterminate" aria-label="Cargando catálogo" />
<p role="status">Cargando catálogo de indicadores…</p>
} @else if (catalogError()) {
<mat-card class="state" role="alert"><p>{{ catalogError() }}</p>
<button mat-stroked-button (click)="retryCatalog()">Reintentar catálogo</button></mat-card>
} @else if (!catalog().length) {
<mat-card class="state"><p role="status">No hay indicadores disponibles en el catálogo.</p>
<button mat-stroked-button (click)="retryCatalog()">Actualizar catálogo</button></mat-card>
} @else {
@if (searchVisible()) {
<div class="catalog-search">
<mat-form-field appearance="outline" subscriptSizing="dynamic">
<mat-label>Buscar indicadores</mat-label>
<input #searchInput matInput type="search" [ngModel]="searchQuery()" (ngModelChange)="changeSearchQuery($event)"
placeholder="Título o identificador" aria-describedby="catalog-search-help catalog-search-result" />
<button mat-icon-button matIconSuffix type="button" (click)="clearSearch()" [disabled]="!searchQuery()"
aria-label="Limpiar búsqueda"><mat-icon aria-hidden="true">close</mat-icon></button>
<mat-hint id="catalog-search-help">Las coincidencias aparecen primero; todos los indicadores siguen visibles.</mat-hint>
</mat-form-field>
</div>
<p id="catalog-search-result" class="search-result">
@if (searchResults().active) {
@if (searchResults().count) {
{{ searchResults().count }} coincidencias de {{ catalog().length }} indicadores. Todos permanecen disponibles.
} @else {
No se encontraron coincidencias. El catálogo completo permanece disponible en su orden original.
}
}
</p>
}
<div class="catalog-grid">
@for (item of searchResults().items; track cardIdentity(item)) {
<app-indicador-catalog-card [dominio]="dominio" [indicador]="item" [tema]="tema"
[initialExpanded]="catalog().length === 1" />
}
</p>
</div>
}
@for (item of searchResults().items; track cardIdentity(item)) {
<app-indicador-catalog-card [dominio]="dominio" [indicador]="item" [tema]="tema"
[initialExpanded]="catalog().length === 1" />
}
}
</section>
</section>
@@ -1,14 +1,28 @@
:host { display: block; }
.dashboard { max-width: 1440px; margin: 0 auto; }
:host { display: block; min-width: 0; }
.dashboard { max-width: 1440px; margin: 0 auto; min-width: 0; container: dashboard / inline-size; }
h1 { font: var(--mat-sys-headline-large); font-family: var(--issste-font-heading); font-weight: 700; margin: .65rem 0; }
header p { color: var(--mat-sys-on-surface-variant); margin-bottom: 1.5rem; }
.domain { color: var(--mat-sys-primary); font: var(--mat-sys-label-large); }
.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; 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); }
.section-title { font-family: var(--issste-font-heading); font-size: 1.5rem; line-height: 1.3; margin: 0; overflow-wrap: anywhere; }
.section-description { color: var(--issste-text-secondary); margin: var(--issste-space-2) 0 var(--issste-space-4); overflow-wrap: anywhere; }
.kpi-section, .graphic-section { min-width: 0; }
.graphic-section { margin-top: var(--issste-space-6); padding-top: var(--issste-space-6); border-top: 1px solid var(--issste-border); }
.kpi-grid, .catalog-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--issste-space-6); }
.catalog-grid { align-items: start; }
.catalog-grid > app-indicador-catalog-card { min-width: 0; margin: 0; }
.catalog-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--issste-space-3); margin-bottom: var(--issste-space-4); }
.catalog-count { margin: 0 0 0 auto; text-align: right; color: var(--issste-text-secondary); overflow-wrap: anywhere; }
.catalog-search { display: flex; justify-content: flex-end; margin-top: var(--issste-space-4); }
.catalog-search mat-form-field { width: 100%; min-width: 0; max-width: 32rem; }
.catalog-search button { width: 48px; height: 48px; }
.catalog-search button:focus-visible { outline: 2px solid var(--issste-text); outline-offset: -3px; }
// Keep search semantics; Material supplies the single accessible clear control.
.catalog-search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search-result { color: var(--mat-sys-on-surface-variant); font: var(--mat-sys-body-medium); text-align: right;
overflow-wrap: anywhere; margin: var(--issste-space-2) 0 var(--issste-space-4); }
@container dashboard (min-width: 600px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container dashboard (min-width: 1304px) { .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
nav {
display: flex;
@@ -19,7 +33,6 @@ nav {
margin: var(--issste-space-4) 0;
border-radius: var(--issste-radius);
}
nav a {
flex: 0 1 6rem;
max-width: 10rem;
@@ -29,18 +42,12 @@ nav a {
min-height: 44px;
border-radius: var(--issste-radius);
}
nav a[aria-current='page'] {
background: var(--issste-accent);
font-weight: 700;
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 { 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; }
h1 { font-size: var(--mat-sys-headline-medium-size); line-height: var(--mat-sys-headline-medium-line-height); }
nav { gap: var(--issste-space-2); padding-inline: 0; }
}
@@ -41,6 +41,51 @@ describe('UX-05B catálogo expandible', () => {
function flushAll() { http.match(r => r.url.includes('/figuras/')).forEach(r => r.flush({ data: [{ y: [0, null] }], layout: {} })); fixture.detectChanges(); }
function control(index = 0) { return fixture.debugElement.queryAll(By.directive(IndicadorPeriodFilters))[index].componentInstance as IndicadorPeriodFilters; }
it.each(['tea', 'cacu', 'cama'] as const)('D.1 muestra dos KPI pendientes propios de %s fuera del catálogo', domain => {
if (domain !== 'tea') {
const initial = http.expectOne('/tea/indicadores');
page.changeDominio(domain); expect(initial.cancelled).toBe(true);
}
fixture.detectChanges();
const section = fixture.nativeElement.querySelector('.kpi-section') as HTMLElement;
expect(section.dataset['domain']).toBe(domain);
expect(section.querySelector('h2')?.textContent).toBe('Indicadores destacados — Vista preliminar');
expect(section.textContent).toContain('Muestra visual de ' + page.domainLabels[domain]);
const kpis = section.querySelectorAll('app-indicador-kpi-card');
expect(Array.from(kpis).map(kpi => kpi.querySelector('h3')?.textContent)).toEqual(['Indicador destacado 1', 'Indicador destacado 2']);
expect(Array.from(kpis).map(kpi => kpi.querySelector('.kpi-state')?.textContent)).toEqual(['Pendiente de definición', 'Pendiente de definición']);
expect(section.querySelector('.value, button, input, app-plotly-chart')).toBeNull();
expect(section.textContent).not.toContain('publicados');
load([], domain); expect(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card')).toHaveLength(2);
http.expectNone(() => true);
});
it('D.1 conserva KPI durante carga, error, reintento y catálogo vacío sin HTTP propio', () => {
fixture.detectChanges();
const kpis = Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'));
expect(kpis).toHaveLength(2);
http.expectOne('/tea/indicadores').flush('private', { status: 500, statusText: 'Error' }); fixture.detectChanges();
expect(Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'))).toEqual(kpis);
page.retryCatalog(); fixture.detectChanges();
expect(Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'))).toEqual(kpis);
load([]); expect(Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'))).toEqual(kpis);
expect(fixture.nativeElement.querySelector('.catalog-count')).toBeNull(); http.expectNone(() => true);
});
it('D.1 separa secciones y conserva tarjetas, orden, identidades y figuras dentro del grid', () => {
load(); const before = cards();
const grid = fixture.nativeElement.querySelector('.catalog-grid') as HTMLElement;
expect(getComputedStyle(grid).display).toBe('grid');
expect(grid.children).toHaveLength(2);
expect(Array.from(grid.children).every(host => host.tagName === 'APP-INDICADOR-CATALOG-CARD')).toBe(true);
const sections = fixture.nativeElement.querySelectorAll('.dashboard > section') as NodeListOf<HTMLElement>;
expect(Array.from(sections).map(section => section.getAttribute('aria-labelledby'))).toEqual(['kpi-section-title', 'graphic-section-title']);
expect(fixture.nativeElement.querySelector('.catalog-count').textContent.trim()).toBe('2 indicadores publicados');
expect(getComputedStyle(fixture.nativeElement.querySelector('.catalog-count')).textAlign).toBe('right');
toggle(0); toggle(1); flushAll();
expect(Array.from(grid.children).map(host => host.querySelectorAll('app-indicador-figure-panel').length)).toEqual([2, 1]);
expect(panels().map(panel => panel.figuraId)).toEqual(['f1', 'f2', 'g']);
expect(cards()).toEqual(before); expect(cards().every(card => card.expanded)).toBe(true);
http.expectNone(() => true);
});
it('UX-06C: tarjeta contraída contiene solo identidad y flecha decorativa en un botón nativo', () => {
load();
const host = fixture.nativeElement.querySelector('app-indicador-catalog-card') as HTMLElement;
@@ -15,12 +15,13 @@ import { Dominio, DOMINIOS, isDominio, Indicador, Tema } from './indicadores.mod
import { IndicadoresService } from './indicadores.service';
import { IndicadoresMemory } from './indicadores-memory';
import { IndicadorCatalogCard } from './indicador-catalog-card';
import { IndicadorKpiCard } from './indicador-kpi-card';
import { indicatorIdentity } from './indicadores-identities';
import { httpMessage } from './indicadores-http';
@Component({
selector: 'app-indicadores-page',
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, IndicadorCatalogCard],
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, IndicadorCatalogCard, IndicadorKpiCard],
templateUrl: './indicadores-page.html',
styleUrl: './indicadores-page.scss',
})
@@ -55,6 +56,12 @@ export class IndicadoresPage {
readonly dominios = DOMINIOS;
dominio: Dominio = 'tea';
readonly domainLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'CaCu', cama: 'CaMa' };
// Presentation samples only. Each domain can replace its own future configuration.
readonly kpiPreviewsByDomain: Record<Dominio, readonly { id: string; title: string }[]> = {
tea: [{ id: 'preview-1', title: 'Indicador destacado 1' }, { id: 'preview-2', title: 'Indicador destacado 2' }],
cacu: [{ id: 'preview-1', title: 'Indicador destacado 1' }, { id: 'preview-2', title: 'Indicador destacado 2' }],
cama: [{ id: 'preview-1', title: 'Indicador destacado 1' }, { id: 'preview-2', title: 'Indicador destacado 2' }],
};
private readonly catalogRequests = new Subject<void>();
readonly catalog = signal<Indicador[]>([]);
readonly searchQuery = signal('');
@@ -85,6 +85,23 @@ describe('UX-05C búsqueda local y partición estable', () => {
if (!(query as string).trim()) expect(fixture.nativeElement.querySelector('#catalog-search-result').textContent.trim()).toBe('');
http.expectNone(() => true);
});
it('D.1 mantiene KPI fuera de la búsqueda y del recuento y utiliza un único suffix Material', async () => {
load(); await settle();
const kpis = Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'));
const field = fixture.nativeElement.querySelector('.catalog-search mat-form-field') as HTMLElement;
const clear = field.querySelector('button')!;
expect(clear.hasAttribute('matIconSuffix')).toBe(true);
expect(clear.closest('.mat-mdc-form-field-icon-suffix')).toBeTruthy();
expect(fixture.nativeElement.querySelectorAll('.catalog-search button')).toHaveLength(1);
expect(input().type).toBe('search');
for (const query of ['sexo', 'Indicador destacado', '']) {
await search(query);
expect(Array.from(fixture.nativeElement.querySelectorAll('app-indicador-kpi-card'))).toEqual(kpis);
expect(fixture.nativeElement.querySelector('.catalog-count').textContent.trim()).toBe('5 indicadores publicados');
expect(cards()).toHaveLength(5);
}
http.expectNone(() => true);
});
it('escritura y limpieza mantienen foco, cursor, etiqueta y ayudas sin HTTP', async () => {
load(); await settle(); const field = input(); field.focus(); await search('sexo');
expect(document.activeElement).toBe(field); expect(field.value).toBe('sexo');