mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-22 02:00:57 -04:00
Separate logout by user or inactivity
This commit is contained in:
@@ -15,17 +15,21 @@ window.GOVUK.Modules.TimeoutPopup = window.GOVUK.Modules.TimeoutPopup || {};
|
||||
var seconds = Math.floor((difference % (1000 * 60)) / 1000);
|
||||
document.getElementById("timeLeft").innerHTML = + minutes + "m " + seconds + "s";
|
||||
showTimer();
|
||||
document.getElementById("logOutTimer").addEventListener("click", logoutUser);
|
||||
document.getElementById("logOutTimer").addEventListener("click", signoutUser);
|
||||
document.getElementById("extendSessionTimer").addEventListener("click", extendSession);
|
||||
if (difference < 0) {
|
||||
clearInterval(intervalId);
|
||||
intervalId = null;
|
||||
closeTimer();
|
||||
logoutUser();
|
||||
expireUserSession();
|
||||
}
|
||||
}
|
||||
|
||||
function logoutUser() {
|
||||
function expireUserSession() {
|
||||
window.location.href = '/sign-out' + '?next=' + window.location.pathname;
|
||||
}
|
||||
|
||||
function signoutUser() {
|
||||
window.location.href = '/sign-out';
|
||||
}
|
||||
|
||||
@@ -51,7 +55,8 @@ window.GOVUK.Modules.TimeoutPopup = window.GOVUK.Modules.TimeoutPopup || {};
|
||||
}
|
||||
|
||||
global.GOVUK.Modules.TimeoutPopup.checkTimer = checkTimer;
|
||||
global.GOVUK.Modules.TimeoutPopup.logoutUser = logoutUser;
|
||||
global.GOVUK.Modules.TimeoutPopup.expireUserSession = expireUserSession;
|
||||
global.GOVUK.Modules.TimeoutPopup.signoutUser = signoutUser;
|
||||
global.GOVUK.Modules.TimeoutPopup.extendSession = extendSession;
|
||||
global.GOVUK.Modules.TimeoutPopup.showTimer = showTimer;
|
||||
global.GOVUK.Modules.TimeoutPopup.closeTimer = closeTimer;
|
||||
|
||||
@@ -72,16 +72,26 @@ describe('The session timer ', () => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
test('logoutUser method logs the user out', () => {
|
||||
const logoutUserMethod = window.GOVUK.Modules.TimeoutPopup.logoutUser;
|
||||
test('signoutUser method logs the user out', () => {
|
||||
const signoutUserMethod = window.GOVUK.Modules.TimeoutPopup.signoutUser;
|
||||
|
||||
expect(window.location.href).toEqual(expect.not.stringContaining('/sign-out'));
|
||||
|
||||
logoutUserMethod();
|
||||
signoutUserMethod();
|
||||
|
||||
expect(window.location.href).toEqual(expect.stringContaining('/sign-out'));
|
||||
});
|
||||
|
||||
test('expireUserSession method logs the user out with next query parameter', () => {
|
||||
const expireUserSessionMethod = window.GOVUK.Modules.TimeoutPopup.expireUserSession;
|
||||
|
||||
expect(window.location.href).toEqual(expect.not.stringContaining('/sign-out?next='));
|
||||
|
||||
expireUserSessionMethod();
|
||||
|
||||
expect(window.location.href).toEqual(expect.stringContaining('/sign-out?next='));
|
||||
});
|
||||
|
||||
test('extendSession method reloads the page', () => {
|
||||
const windowReload = jest.spyOn(window.location, 'reload');
|
||||
const extendSessionMethod = window.GOVUK.Modules.TimeoutPopup.extendSession;
|
||||
|
||||
Reference in New Issue
Block a user