diff --git a/src/app/components/common/logout/logout.component.spec.ts b/src/app/components/common/logout/logout.component.spec.ts index bcf87fe68..52f5d28fb 100644 --- a/src/app/components/common/logout/logout.component.spec.ts +++ b/src/app/components/common/logout/logout.component.spec.ts @@ -24,23 +24,22 @@ */ import { TestBed, ComponentFixture } from '@angular/core/testing'; -import { TranslateModule, TranslateLoader, TranslateFakeLoader } from '@ngx-translate/core'; +import { AppTestingModule } from '../../../testing/app-testing.module'; import { LogoutComponent } from './logout.component'; import { Store } from '@ngrx/store'; import { SetSelectedNodesAction } from '@alfresco/aca-shared/store'; +import { AppConfigService, AuthenticationService } from '@alfresco/adf-core'; describe('LogoutComponent', () => { let fixture: ComponentFixture; let component: LogoutComponent; let store; + let authService: AuthenticationService; + let appConfig: AppConfigService; beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot({ - loader: { provide: TranslateLoader, useClass: TranslateFakeLoader } - }) - ], + imports: [AppTestingModule], declarations: [LogoutComponent], providers: [ { @@ -54,6 +53,8 @@ describe('LogoutComponent', () => { store = TestBed.inject(Store); fixture = TestBed.createComponent(LogoutComponent); + appConfig = TestBed.inject(AppConfigService); + authService = TestBed.inject(AuthenticationService); component = fixture.componentInstance; fixture.detectChanges(); }); @@ -63,4 +64,19 @@ describe('LogoutComponent', () => { expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([])); }); + + it('should return the login route in case of basic auth', () => { + spyOn(authService, 'isOauth').and.returnValue(false); + + const redirectLogout = component.getLogoutRedirectUri(); + expect(redirectLogout).toEqual('/login'); + }); + + it('should return the value of redirectUriLogout as route in case of SSO auth', () => { + spyOn(authService, 'isOauth').and.returnValue(true); + appConfig.config['oauth2.redirectUriLogout'] = 'fake-logout'; + + const redirectLogout = component.getLogoutRedirectUri(); + expect(redirectLogout).toEqual('fake-logout'); + }); }); diff --git a/src/app/components/common/logout/logout.component.ts b/src/app/components/common/logout/logout.component.ts index b78a8b541..beaa63e12 100644 --- a/src/app/components/common/logout/logout.component.ts +++ b/src/app/components/common/logout/logout.component.ts @@ -26,18 +26,27 @@ import { Component } from '@angular/core'; import { Store } from '@ngrx/store'; import { AppStore, SetSelectedNodesAction } from '@alfresco/aca-shared/store'; +import { AppConfigService, AuthenticationService } from '@alfresco/adf-core'; @Component({ selector: 'aca-logout', template: ` - ` }) export class LogoutComponent { - constructor(private store: Store) {} + constructor(private store: Store, private appConfig: AppConfigService, private auth: AuthenticationService) {} + + getLogoutRedirectUri() { + if (this.auth.isOauth()) { + const logoutRedirect = this.appConfig.get('oauth2.redirectUriLogout'); + return logoutRedirect; + } + return '/login'; + } onLogoutEvent() { this.store.dispatch(new SetSelectedNodesAction([]));