-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing closeSession() as uses third-party cookies. Create signOut p…
…age and redirect there so we can redirect user back to their previous page before signOut.
- Loading branch information
Showing
7 changed files
with
259 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import angular from 'angular' | ||
import commonModule from 'common/common.module' | ||
import sessionService, { Roles } from 'common/services/session/session.service' | ||
import template from './signOut.tpl.html' | ||
|
||
const componentName = 'signOut' | ||
|
||
class SignOutController { | ||
/* @ngInject */ | ||
constructor ($window, sessionService) { | ||
this.$window = $window | ||
this.sessionService = sessionService | ||
} | ||
|
||
$onInit () { | ||
if (this.sessionService.getRole() !== Roles.public) { | ||
this.redirectToHomepage() | ||
} else { | ||
this.redirectToLocationPriorToSignOut() | ||
} | ||
} | ||
|
||
redirectToHomepage () { | ||
this.$window.location.href = '/' | ||
} | ||
|
||
redirectToLocationPriorToSignOut () { | ||
this.showRedirectingLoadingIcon = true | ||
const locationToReturnUser = this.sessionService.hasLocationOnLogin() | ||
if (locationToReturnUser) { | ||
this.sessionService.removeLocationOnLogin() | ||
this.$window.location.href = locationToReturnUser | ||
} else { | ||
this.redirectToHomepage() | ||
} | ||
} | ||
|
||
closeRedirectingLoading () { | ||
this.showRedirectingLoadingIcon = false | ||
this.redirectToHomepage() | ||
} | ||
} | ||
|
||
export default angular | ||
.module(componentName, [ | ||
commonModule.name, | ||
sessionService.name | ||
]) | ||
.component(componentName, { | ||
controller: SignOutController, | ||
templateUrl: template | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import angular from 'angular' | ||
import 'angular-mocks' | ||
import module from './signOut.component' | ||
import { Observable } from 'rxjs/Observable' | ||
import 'rxjs/add/observable/of' | ||
import 'rxjs/add/observable/throw' | ||
|
||
describe('signOut', function () { | ||
beforeEach(angular.mock.module(module.name)) | ||
let $ctrl | ||
|
||
beforeEach(inject(function (_$componentController_) { | ||
$ctrl = _$componentController_(module.name, | ||
{ $window: { location: { href: '/sign-out.html'} } } | ||
) | ||
})) | ||
|
||
it('to be defined', function () { | ||
expect($ctrl).toBeDefined() | ||
}) | ||
|
||
it('redirectToHomepage()', function () { | ||
$ctrl.redirectToHomepage() | ||
expect($ctrl.$window.location.href).toEqual('/') | ||
}) | ||
|
||
describe('redirectToLocationPriorToSignOut()', () => { | ||
beforeEach(() => { | ||
jest.spyOn($ctrl, 'redirectToHomepage') | ||
jest.spyOn($ctrl.sessionService, 'removeLocationOnLogin') | ||
}) | ||
|
||
it('redirects to prior page if hasLocationOnLogin() returns value', () => { | ||
jest.spyOn($ctrl.sessionService, 'hasLocationOnLogin').mockReturnValue('https://give-stage2.cru.org/search-results.html') | ||
$ctrl.showRedirectingLoadingIcon = false | ||
$ctrl.redirectToLocationPriorToSignOut() | ||
expect($ctrl.showRedirectingLoadingIcon).toEqual(true) | ||
expect($ctrl.sessionService.hasLocationOnLogin).toHaveBeenCalled() | ||
expect($ctrl.sessionService.removeLocationOnLogin).toHaveBeenCalled() | ||
expect($ctrl.$window.location.href).toEqual('https://give-stage2.cru.org/search-results.html') | ||
}) | ||
|
||
it('redirects to home page if hasLocationOnLogin() returns no value', () => { | ||
jest.spyOn($ctrl.sessionService, 'hasLocationOnLogin').mockReturnValue(undefined) | ||
$ctrl.showRedirectingLoadingIcon = false | ||
$ctrl.redirectToLocationPriorToSignOut() | ||
expect($ctrl.showRedirectingLoadingIcon).toEqual(true) | ||
expect($ctrl.sessionService.hasLocationOnLogin).toHaveBeenCalled() | ||
expect($ctrl.sessionService.removeLocationOnLogin).not.toHaveBeenCalled() | ||
expect($ctrl.$window.location.href).toEqual('/') | ||
}) | ||
}) | ||
|
||
|
||
|
||
describe('as \'IDENTIFIED\'', () => { | ||
it('should redirect to the home page', () => { | ||
jest.spyOn($ctrl.sessionService, 'getRole').mockReturnValue('IDENTIFIED') | ||
jest.spyOn($ctrl, 'redirectToHomepage') | ||
jest.spyOn($ctrl, 'redirectToLocationPriorToSignOut') | ||
$ctrl.$onInit() | ||
|
||
expect($ctrl.redirectToHomepage).toHaveBeenCalled() | ||
expect($ctrl.redirectToLocationPriorToSignOut).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
describe('as \'REGISTERED\'', () => { | ||
it('should redirect to the home page', () => { | ||
jest.spyOn($ctrl.sessionService, 'getRole').mockReturnValue('REGISTERED') | ||
jest.spyOn($ctrl, 'redirectToHomepage') | ||
jest.spyOn($ctrl, 'redirectToLocationPriorToSignOut') | ||
$ctrl.$onInit() | ||
|
||
expect($ctrl.redirectToHomepage).toHaveBeenCalled() | ||
expect($ctrl.redirectToLocationPriorToSignOut).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
|
||
describe('as \'GUEST\'', () => { | ||
it('should run redirectToLocationPriorToSignOut()', () => { | ||
jest.spyOn($ctrl.sessionService, 'getRole').mockReturnValue('PUBLIC') | ||
jest.spyOn($ctrl, 'redirectToLocationPriorToSignOut') | ||
$ctrl.$onInit() | ||
|
||
expect($ctrl.redirectToLocationPriorToSignOut).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
describe('closeRedirectingLoading()', () => { | ||
it('should run redirectToHomepage()', () => { | ||
jest.spyOn($ctrl, 'redirectToHomepage') | ||
$ctrl.showRedirectingLoadingIcon = true | ||
$ctrl.closeRedirectingLoading() | ||
expect($ctrl.showRedirectingLoadingIcon).toEqual(false) | ||
expect($ctrl.redirectToHomepage).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="screenContent"> | ||
<div class="redirect-user-after-login" ng-if="$ctrl.showRedirectingLoadingIcon"> | ||
<div> | ||
<loading> | ||
<p><translate>Successfully logged out.</translate></p> | ||
<p><translate>Redirecting to your previous page...</translate></p> | ||
</loading> | ||
<button id="closeButtonTop" type="button" ng-click="$ctrl.closeRedirectingLoading()" class="btn btn-block btn-secondary" aria-label="{{'Close' | translate}}"> | ||
Close <span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.