diff --git a/alfa-client/apps/admin/src/app/app.component.spec.ts b/alfa-client/apps/admin/src/app/app.component.spec.ts index 45e077a4ecea2d2e7e5429e8bab0ef4591ebf0cb..52e41ae571ae5ef0fc7a8c025e58bfe1a815abfb 100644 --- a/alfa-client/apps/admin/src/app/app.component.spec.ts +++ b/alfa-client/apps/admin/src/app/app.component.spec.ts @@ -11,6 +11,7 @@ import { createApiRootResource } from 'libs/api-root-shared/test/api-root'; import { MockComponent } from 'ng-mocks'; import { UserProfileButtonContainerComponent } from '../common/user-profile-button-container/user-profile.button-container.component'; import { PostfachNavigationItemComponent } from '../pages/postfach/postfach-navigation-item/postfach-navigation-item.component'; +import { Router } from '@angular/router'; describe('AppComponent', () => { let component: AppComponent; @@ -25,6 +26,8 @@ describe('AppComponent', () => { ...mock(AuthService), login: jest.fn().mockResolvedValue(Promise.resolve()), }; + + const router: Mock<Router> = mock(Router); const apiRootService: Mock<ApiRootService> = mock(ApiRootService); beforeEach(async () => { @@ -44,6 +47,10 @@ describe('AppComponent', () => { provide: ApiRootService, useValue: apiRootService, }, + { + provide: Router, + useValue: router, + }, ], }).compileComponents(); }); @@ -82,6 +89,12 @@ describe('AppComponent', () => { expect(apiRootService.getApiRoot).toHaveBeenCalled(); }); + + it('should navigate to default route', () => { + component.doAfterLoggedIn(); + + expect(router.navigate).toHaveBeenCalledWith(['/']); + }); }); }); diff --git a/alfa-client/apps/admin/src/app/app.component.ts b/alfa-client/apps/admin/src/app/app.component.ts index 20aeed47e05049ead0b29bccfa160876e9f692cd..a09ea6d8a5c4af992feea69f455f5c83c66f539d 100644 --- a/alfa-client/apps/admin/src/app/app.component.ts +++ b/alfa-client/apps/admin/src/app/app.component.ts @@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { AuthService } from '../common/auth/auth.service'; import { StateResource } from '@alfa-client/tech-shared'; +import { Router } from '@angular/router'; @Component({ selector: 'app-root', @@ -17,6 +18,7 @@ export class AppComponent implements OnInit { constructor( public authService: AuthService, private apiRootService: ApiRootService, + private router: Router, ) {} ngOnInit(): void { @@ -25,5 +27,6 @@ export class AppComponent implements OnInit { doAfterLoggedIn(): void { this.apiRootStateResource$ = this.apiRootService.getApiRoot(); + this.router.navigate(['/']); } }