e2b307abf5
How: on /indicadores/<domain> routes the App header shows the platform title and a mat-menu button named after the current domain, listing the other two (the same markup and styles as the deployed WebApp's app.html). Other routes (Conectar, Gobernanza) keep the "Análisis de información" breadcrumb. The indicators page drops its own TEA/CaCu/CaMa links, so there is one switcher. Implications: domain switching now depends on the App shell; a page embedded elsewhere has no way to change domain by itself. Specs that asserted the in-page links now assert their absence, and app.spec covers the menu.
93 lines
6.2 KiB
TypeScript
93 lines
6.2 KiB
TypeScript
import { kpiQueriesProvider, periodAvailabilityProvider } from './indicadores-periodos.testing';
|
|
import { Component } from '@angular/core';
|
|
import { TestBed } from '@angular/core/testing';
|
|
import { provideHttpClient } from '@angular/common/http';
|
|
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
|
import { provideRouter, Router } from '@angular/router';
|
|
import { RouterTestingHarness } from '@angular/router/testing';
|
|
import { By } from '@angular/platform-browser';
|
|
import { routes } from '../../app.routes';
|
|
import { IndicadorCatalogCard } from './indicador-catalog-card';
|
|
import { IndicadorFigurePanel } from './indicador-figure-panel';
|
|
import { IndicadoresPage } from './indicadores-page';
|
|
import { IndicadorFigureCard } from './indicador-figure-card';
|
|
import { IndicadorPeriodFilters } from './indicador-period-filters';
|
|
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
|
|
import { PlotlyFigure } from './indicadores.models';
|
|
import { syntheticCatalogs } from './indicadores.synthetic-fixtures';
|
|
|
|
@Component({ selector: 'app-plotly-chart', inputs: ['figure', 'label', 'showNotes'], template: '' })
|
|
class ChartStub { figure?: PlotlyFigure; }
|
|
|
|
describe('UX-04 navegación Angular', () => {
|
|
let http: HttpTestingController;
|
|
async function setup() {
|
|
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
|
|
TestBed.configureTestingModule({ providers: [provideRouter(routes), provideHttpClient(), provideHttpClientTesting(), periodAvailabilityProvider, kpiQueriesProvider] });
|
|
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
|
http = TestBed.inject(HttpTestingController);
|
|
return RouterTestingHarness.create();
|
|
}
|
|
function load(domain: 'tea' | 'cacu' | 'cama', harness: RouterTestingHarness) {
|
|
http.expectOne('/' + domain + '/indicadores').flush(syntheticCatalogs[domain]);
|
|
harness.detectChanges();
|
|
const page = harness.routeDebugElement!.componentInstance as IndicadoresPage;
|
|
vi.spyOn(page as unknown as { evaluateVisibility(): void }, 'evaluateVisibility').mockImplementation(() => {});
|
|
const card = harness.routeDebugElement!.query(By.directive(IndicadorCatalogCard)).componentInstance as IndicadorCatalogCard;
|
|
if (!card.visible) { card.setVisible(true); harness.detectChanges(); }
|
|
const req = http.expectOne(r => r.url.includes('/figuras/'));
|
|
req.flush({ data: [{ y: [0, null] }], layout: {} });
|
|
return req;
|
|
}
|
|
afterEach(() => { http.verify(); vi.unstubAllGlobals(); });
|
|
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();
|
|
// Domain switching lives in the App header (app.spec.ts); the page must not add a second one.
|
|
expect(harness.routeNativeElement!.querySelectorAll('nav.domain-nav a')).toHaveLength(0);
|
|
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);
|
|
load('tea', harness); harness.detectChanges();
|
|
const control = harness.routeDebugElement!.query(By.directive(IndicadorPeriodFilters)).componentInstance as IndicadorPeriodFilters;
|
|
control.select([]); control.year = '2025'; control.unit = 'S1'; control.add();
|
|
(harness.routeDebugElement!.componentInstance as IndicadoresPage).applyFilters(); harness.detectChanges();
|
|
http.expectOne(r => r.url.includes('/figuras/')).flush({ data: [], layout: {} });
|
|
control.year = '2025'; control.unit = 'S2'; control.add();
|
|
await harness.navigateByUrl('/indicadores/cacu', IndicadoresPage); load('cacu', harness);
|
|
await harness.navigateByUrl('/indicadores/cama', IndicadoresPage); load('cama', harness);
|
|
const restored = await harness.navigateByUrl('/indicadores/tea', IndicadoresPage);
|
|
const req = load('tea', harness);
|
|
expect(req.request.params.get('periodos')).toBe('2025-S1');
|
|
expect((harness.routeDebugElement!.componentInstance as IndicadoresPage).filters?.editors.semestre?.draft).toEqual({ mode: 'explicit', periodos: ['2025-S2'] });
|
|
expect(TestBed.inject(Router).url).toBe('/indicadores/tea');
|
|
});
|
|
it('un nuevo arranque conserva la URL de entrada y reinicia indicador, tema y filtros', async () => {
|
|
let harness = await setup();
|
|
const page = await harness.navigateByUrl('/indicadores/cacu', IndicadoresPage);
|
|
load('cacu', harness); harness.detectChanges();
|
|
page.changeTema('oscuro'); harness.detectChanges();
|
|
http.expectOne(r => r.url.includes('/figuras/')).flush({ data: [], layout: {} });
|
|
const control = harness.routeDebugElement!.query(By.directive(IndicadorPeriodFilters)).componentInstance as IndicadorPeriodFilters;
|
|
control.changeTipo('mes'); control.year = '2025'; control.unit = '01'; control.add();
|
|
(harness.routeDebugElement!.componentInstance as IndicadoresPage).applyFilters(); harness.detectChanges();
|
|
http.expectOne(r => r.url.includes('/figuras/')).flush({ data: [], layout: {} });
|
|
const url = TestBed.inject(Router).url;
|
|
http.match(r => r.url.endsWith('/datos')).forEach(r => r.flush('missing', { status: 404, statusText: 'Not Found' }));
|
|
http.verify(); TestBed.resetTestingModule();
|
|
harness = await setup();
|
|
const restarted = await harness.navigateByUrl(url, IndicadoresPage);
|
|
const req = load('cacu', harness);
|
|
expect(TestBed.inject(Router).url).toBe('/indicadores/cacu');
|
|
expect((harness.routeDebugElement!.query(By.directive(IndicadorCatalogCard)).componentInstance as IndicadorCatalogCard).visible).toBe(true);
|
|
expect(restarted.tema).toBe('claro');
|
|
expect((harness.routeDebugElement!.componentInstance as IndicadoresPage).filters?.tipo).toBe('semestre');
|
|
expect((harness.routeDebugElement!.componentInstance as IndicadoresPage).filters?.editors.mes?.draft.mode).toBe('empty');
|
|
expect(req.request.params.has('periodos')).toBe(false);
|
|
expect(req.request.params.get('tema')).toBe('claro');
|
|
});
|
|
});
|