test(webapp): seed the visual login session in indicadores specs
The indicadores navigation, sections and cancer-journey specs routed through the real routes without a session, so authGuard redirected to LoginPage. Add auth.testing helpers that seed and clear the sessionStorage session, use them in those specs, and add a spec that /indicadores/<dominio> without a session presents LoginPage with returnUrl.
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
import { Usuario } from './auth.service';
|
||||||
|
|
||||||
|
/** Same key AuthService persists the visual session under. */
|
||||||
|
const CLAVE_SESION = 'isssteleon.sesion';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seeds the browser-only visual session before the router and AuthService are created,
|
||||||
|
* so routes behind authGuard render instead of redirecting to /login. Pair every call
|
||||||
|
* with `limpiarSesionVisual()` in afterEach so the session never leaks between tests.
|
||||||
|
*/
|
||||||
|
export function iniciarSesionVisual(sesion: Usuario = { usuario: 'admin', nombre: 'Administrador', dominios: ['cacu', 'cama', 'tea'] }): void {
|
||||||
|
sessionStorage.setItem(CLAVE_SESION, JSON.stringify(sesion));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function limpiarSesionVisual(): void {
|
||||||
|
sessionStorage.removeItem(CLAVE_SESION);
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ import { provideRouter, Router } from '@angular/router';
|
|||||||
import { RouterTestingHarness } from '@angular/router/testing';
|
import { RouterTestingHarness } from '@angular/router/testing';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { routes } from '../../app.routes';
|
import { routes } from '../../app.routes';
|
||||||
|
import { LoginPage } from '../../auth/login-page';
|
||||||
|
import { iniciarSesionVisual, limpiarSesionVisual } from '../../auth/auth.testing';
|
||||||
import { IndicadorCatalogCard } from './indicador-catalog-card';
|
import { IndicadorCatalogCard } from './indicador-catalog-card';
|
||||||
import { IndicadorFigurePanel } from './indicador-figure-panel';
|
import { IndicadorFigurePanel } from './indicador-figure-panel';
|
||||||
import { IndicadoresPage } from './indicadores-page';
|
import { IndicadoresPage } from './indicadores-page';
|
||||||
@@ -22,6 +24,7 @@ class ChartStub { figure?: PlotlyFigure; }
|
|||||||
describe('UX-04 navegación Angular', () => {
|
describe('UX-04 navegación Angular', () => {
|
||||||
let http: HttpTestingController;
|
let http: HttpTestingController;
|
||||||
async function setup() {
|
async function setup() {
|
||||||
|
iniciarSesionVisual();
|
||||||
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
|
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
|
||||||
TestBed.configureTestingModule({ providers: [provideRouter(routes), provideHttpClient(), provideHttpClientTesting(), periodAvailabilityProvider, kpiQueriesProvider] });
|
TestBed.configureTestingModule({ providers: [provideRouter(routes), provideHttpClient(), provideHttpClientTesting(), periodAvailabilityProvider, kpiQueriesProvider] });
|
||||||
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
||||||
@@ -39,7 +42,14 @@ describe('UX-04 navegación Angular', () => {
|
|||||||
req.flush({ data: [{ y: [0, null] }], layout: {} });
|
req.flush({ data: [{ y: [0, null] }], layout: {} });
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
afterEach(() => { http.verify(); vi.unstubAllGlobals(); });
|
afterEach(() => { http.verify(); vi.unstubAllGlobals(); limpiarSesionVisual(); });
|
||||||
|
it.each(['tea', 'cacu', 'cama'] as const)('sin sesión visual, /indicadores/%s presenta LoginPage y conserva returnUrl', async domain => {
|
||||||
|
const harness = await setup();
|
||||||
|
limpiarSesionVisual();
|
||||||
|
await harness.navigateByUrl('/indicadores/' + domain, LoginPage);
|
||||||
|
expect(TestBed.inject(Router).url).toBe('/login?returnUrl=%2Findicadores%2F' + domain);
|
||||||
|
http.expectNone(() => true);
|
||||||
|
});
|
||||||
it.each(['tea', 'cacu', 'cama'] as const)('navegación %s mantiene tres enlaces, estado, decoración y foco independiente', async domain => {
|
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();
|
const harness = await setup();
|
||||||
await harness.navigateByUrl('/indicadores/' + domain, IndicadoresPage);
|
await harness.navigateByUrl('/indicadores/' + domain, IndicadoresPage);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { HttpTestingController, provideHttpClientTesting } from '@angular/common
|
|||||||
import { provideRouter } from '@angular/router';
|
import { provideRouter } from '@angular/router';
|
||||||
import { RouterTestingHarness } from '@angular/router/testing';
|
import { RouterTestingHarness } from '@angular/router/testing';
|
||||||
import { routes } from '../../app.routes';
|
import { routes } from '../../app.routes';
|
||||||
|
import { iniciarSesionVisual, limpiarSesionVisual } from '../../auth/auth.testing';
|
||||||
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
|
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
|
||||||
import fixtureData from './fixtures/cama_seguimiento.json';
|
import fixtureData from './fixtures/cama_seguimiento.json';
|
||||||
import { CAMA_ANALYSIS_ENABLED, IndicadoresPage } from './indicadores-page';
|
import { CAMA_ANALYSIS_ENABLED, IndicadoresPage } from './indicadores-page';
|
||||||
@@ -41,13 +42,14 @@ describe('Recorrido de cáncer de mama: análisis, lista, ficha y regreso', () =
|
|||||||
let http: HttpTestingController;
|
let http: HttpTestingController;
|
||||||
const corte = hoyIso();
|
const corte = hoyIso();
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
iniciarSesionVisual();
|
||||||
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
|
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
|
||||||
TestBed.configureTestingModule({ providers: [provideRouter(routes), provideHttpClient(withInterceptors([sinAnalisisDescriptivo])), provideHttpClientTesting(), periodAvailabilityProvider, kpiQueriesProvider] });
|
TestBed.configureTestingModule({ providers: [provideRouter(routes), provideHttpClient(withInterceptors([sinAnalisisDescriptivo])), provideHttpClientTesting(), periodAvailabilityProvider, kpiQueriesProvider] });
|
||||||
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
||||||
TestBed.overrideComponent(IndicadoresAnalisis, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
TestBed.overrideComponent(IndicadoresAnalisis, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
||||||
http = TestBed.inject(HttpTestingController);
|
http = TestBed.inject(HttpTestingController);
|
||||||
});
|
});
|
||||||
afterEach(() => { http.verify(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });
|
afterEach(() => { http.verify(); vi.restoreAllMocks(); vi.unstubAllGlobals(); limpiarSesionVisual(); });
|
||||||
|
|
||||||
async function entrar() {
|
async function entrar() {
|
||||||
const harness = await RouterTestingHarness.create();
|
const harness = await RouterTestingHarness.create();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { provideRouter } from '@angular/router';
|
|||||||
import { RouterTestingHarness } from '@angular/router/testing';
|
import { RouterTestingHarness } from '@angular/router/testing';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { routes } from '../../app.routes';
|
import { routes } from '../../app.routes';
|
||||||
|
import { iniciarSesionVisual, limpiarSesionVisual } from '../../auth/auth.testing';
|
||||||
import { IndicadoresPage } from './indicadores-page';
|
import { IndicadoresPage } from './indicadores-page';
|
||||||
import { IndicadoresDefinitions } from './indicadores-definitions';
|
import { IndicadoresDefinitions } from './indicadores-definitions';
|
||||||
import { IndicadorCatalogCard } from './indicador-catalog-card';
|
import { IndicadorCatalogCard } from './indicador-catalog-card';
|
||||||
@@ -24,12 +25,13 @@ const catalog: Indicador[] = [
|
|||||||
describe('Secciones compartidas por dominio', () => {
|
describe('Secciones compartidas por dominio', () => {
|
||||||
let http: HttpTestingController;
|
let http: HttpTestingController;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
iniciarSesionVisual();
|
||||||
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
|
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
|
||||||
TestBed.configureTestingModule({ providers: [provideRouter(routes), provideHttpClient(), provideHttpClientTesting(), periodAvailabilityProvider, kpiQueriesProvider] });
|
TestBed.configureTestingModule({ providers: [provideRouter(routes), provideHttpClient(), provideHttpClientTesting(), periodAvailabilityProvider, kpiQueriesProvider] });
|
||||||
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
TestBed.overrideComponent(IndicadorFigureCard, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } });
|
||||||
http = TestBed.inject(HttpTestingController);
|
http = TestBed.inject(HttpTestingController);
|
||||||
});
|
});
|
||||||
afterEach(() => { http.verify(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });
|
afterEach(() => { http.verify(); vi.restoreAllMocks(); vi.unstubAllGlobals(); limpiarSesionVisual(); });
|
||||||
|
|
||||||
it.each(DOMINIOS)('entrada directa en %s presenta sus pestañas y Resumen seleccionado', async domain => {
|
it.each(DOMINIOS)('entrada directa en %s presenta sus pestañas y Resumen seleccionado', async domain => {
|
||||||
const harness = await RouterTestingHarness.create();
|
const harness = await RouterTestingHarness.create();
|
||||||
|
|||||||
Reference in New Issue
Block a user