diff --git a/src/app/components/login/login.component.spec.ts b/src/app/components/login/login.component.spec.ts index 9cc027b04..f7b4ab8bc 100644 --- a/src/app/components/login/login.component.spec.ts +++ b/src/app/components/login/login.component.spec.ts @@ -25,6 +25,7 @@ import { RouterTestingModule } from '@angular/router/testing'; import { Router } from '@angular/router'; +import { Location } from '@angular/common'; import { TestBed, async } from '@angular/core/testing'; import { CoreModule, AuthenticationService, UserPreferencesService } from '@alfresco/adf-core'; @@ -36,6 +37,7 @@ describe('LoginComponent', () => { let router; let userPreference; let auth; + let location; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -45,6 +47,9 @@ describe('LoginComponent', () => { ], declarations: [ LoginComponent + ], + providers: [ + Location ] }); @@ -52,6 +57,7 @@ describe('LoginComponent', () => { component = fixture.componentInstance; router = TestBed.get(Router); + location = TestBed.get(Location); auth = TestBed.get(AuthenticationService); userPreference = TestBed.get(UserPreferencesService); })); @@ -60,6 +66,7 @@ describe('LoginComponent', () => { spyOn(userPreference, 'setStoragePrefix'); spyOn(router, 'navigateByUrl'); spyOn(auth, 'getRedirectUrl').and.returnValue('/some-url'); + spyOn(location, 'forward'); }); describe('OnInit()', () => { @@ -67,14 +74,14 @@ describe('LoginComponent', () => { spyOn(auth, 'isEcmLoggedIn').and.returnValue(false); fixture.detectChanges(); - expect(router.navigateByUrl).not.toHaveBeenCalled(); + expect(location.forward).not.toHaveBeenCalled(); }); it('should redirect when user is logged in', () => { spyOn(auth, 'isEcmLoggedIn').and.returnValue(true); fixture.detectChanges(); - expect(router.navigateByUrl).toHaveBeenCalledWith('/some-url'); + expect(location.forward).toHaveBeenCalled(); }); }); diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index 3486e138f..7c52a8a4d 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -24,6 +24,7 @@ */ import { Component, OnInit } from '@angular/core'; +import { Location } from '@angular/common'; import { Router } from '@angular/router'; import { AuthenticationService, UserPreferencesService } from '@alfresco/adf-core'; @@ -33,13 +34,14 @@ import { AuthenticationService, UserPreferencesService } from '@alfresco/adf-cor export class LoginComponent implements OnInit { constructor( private router: Router, + private location: Location, private auth: AuthenticationService, private userPreferences: UserPreferencesService ) {} ngOnInit() { if (this.auth.isEcmLoggedIn()) { - this.router.navigateByUrl(this.auth.getRedirectUrl() || ''); + this.location.forward(); } }