import { provideHttpClient } from '@angular/common/http'; import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; import { TestBed } from '@angular/core/testing'; import { provideRouter } from '@angular/router'; import { AUTH_BFF_BASE_URL, AUTH_CSRF_COOKIE_NAME } from 'feature-auth'; import { App } from './app'; const BFF_BASE = 'http://bff.test/api'; describe('App', () => { beforeEach(async () => { await TestBed.configureTestingModule({ imports: [App], providers: [ provideRouter([]), provideHttpClient(), provideHttpClientTesting(), { provide: AUTH_BFF_BASE_URL, useValue: BFF_BASE }, // ChatbotApiService injects the CSRF cookie name token; the // shell renders the chatbot host, so the App spec needs the // provider in scope even though no chat request is fired. { provide: AUTH_CSRF_COOKIE_NAME, useValue: 'portal_csrf_test' }, ], }).compileComponents(); }); it('renders the layout shell — skip link, header, sidebar, main, footer', async () => { const fixture = TestBed.createComponent(App); await fixture.whenStable(); const root = fixture.nativeElement as HTMLElement; expect(root.querySelector('a.skip-link')).not.toBeNull(); expect(root.querySelector('app-header')).not.toBeNull(); expect(root.querySelector('app-sidebar')).not.toBeNull(); expect(root.querySelector('main#main-content')).not.toBeNull(); expect(root.querySelector('app-footer')).not.toBeNull(); // Drain the bootstrap /me request fired by the Header's AuthService. const httpCtrl = TestBed.inject(HttpTestingController); httpCtrl .expectOne(`${BFF_BASE}/auth/me`) .flush({}, { status: 401, statusText: 'Unauthorized' }); }); });