79700: Tracking idleness & idle modal

This commit is contained in:
Marie Verdonck
2021-05-28 17:22:26 +02:00
parent b23522d39f
commit 38387d1a0f
17 changed files with 433 additions and 66 deletions

View File

@@ -23,7 +23,7 @@ import {
RetrieveAuthMethodsAction,
RetrieveAuthMethodsErrorAction,
RetrieveAuthMethodsSuccessAction,
SetRedirectUrlAction
SetRedirectUrlAction, SetUserAsIdleAction, UnsetUserAsIdleAction
} from './auth.actions';
import { AuthTokenInfo } from './models/auth-token-info.model';
import { EPersonMock } from '../../shared/testing/eperson.mock';
@@ -44,6 +44,7 @@ describe('authReducer', () => {
loaded: false,
blocking: true,
loading: false,
idle: false
};
const action = new AuthenticateAction('user', 'password');
const newState = authReducer(initialState, action);
@@ -53,7 +54,8 @@ describe('authReducer', () => {
blocking: true,
error: undefined,
loading: true,
info: undefined
info: undefined,
idle: false
};
expect(newState).toEqual(state);
@@ -66,7 +68,8 @@ describe('authReducer', () => {
error: undefined,
blocking: true,
loading: true,
info: undefined
info: undefined,
idle: false
};
const action = new AuthenticationSuccessAction(mockTokenInfo);
const newState = authReducer(initialState, action);
@@ -81,7 +84,8 @@ describe('authReducer', () => {
error: undefined,
blocking: true,
loading: true,
info: undefined
info: undefined,
idle: false
};
const action = new AuthenticationErrorAction(mockError);
const newState = authReducer(initialState, action);
@@ -92,7 +96,8 @@ describe('authReducer', () => {
loading: false,
info: undefined,
authToken: undefined,
error: 'Test error message'
error: 'Test error message',
idle: false
};
expect(newState).toEqual(state);
@@ -105,7 +110,8 @@ describe('authReducer', () => {
loaded: false,
error: undefined,
loading: true,
info: undefined
info: undefined,
idle: false
};
const action = new AuthenticatedAction(mockTokenInfo);
const newState = authReducer(initialState, action);
@@ -115,7 +121,8 @@ describe('authReducer', () => {
loaded: false,
error: undefined,
loading: true,
info: undefined
info: undefined,
idle: false
};
expect(newState).toEqual(state);
});
@@ -127,7 +134,8 @@ describe('authReducer', () => {
error: undefined,
blocking: true,
loading: true,
info: undefined
info: undefined,
idle: false
};
const action = new AuthenticatedSuccessAction(true, mockTokenInfo, EPersonMock._links.self.href);
const newState = authReducer(initialState, action);
@@ -138,7 +146,8 @@ describe('authReducer', () => {
error: undefined,
blocking: true,
loading: true,
info: undefined
info: undefined,
idle: false
};
expect(newState).toEqual(state);
});
@@ -150,7 +159,8 @@ describe('authReducer', () => {
error: undefined,
blocking: true,
loading: true,
info: undefined
info: undefined,
idle: false
};
const action = new AuthenticatedErrorAction(mockError);
const newState = authReducer(initialState, action);
@@ -161,7 +171,8 @@ describe('authReducer', () => {
loaded: true,
blocking: false,
loading: false,
info: undefined
info: undefined,
idle: false
};
expect(newState).toEqual(state);
});
@@ -172,6 +183,7 @@ describe('authReducer', () => {
loaded: false,
blocking: false,
loading: false,
idle: false
};
const action = new CheckAuthenticationTokenAction();
const newState = authReducer(initialState, action);
@@ -180,6 +192,7 @@ describe('authReducer', () => {
loaded: false,
blocking: true,
loading: true,
idle: false
};
expect(newState).toEqual(state);
});
@@ -190,6 +203,7 @@ describe('authReducer', () => {
loaded: false,
blocking: false,
loading: true,
idle: false
};
const action = new CheckAuthenticationTokenCookieAction();
const newState = authReducer(initialState, action);
@@ -198,6 +212,7 @@ describe('authReducer', () => {
loaded: false,
blocking: true,
loading: true,
idle: false
};
expect(newState).toEqual(state);
});
@@ -211,7 +226,8 @@ describe('authReducer', () => {
blocking: false,
loading: false,
info: undefined,
userId: EPersonMock.id
userId: EPersonMock.id,
idle: false
};
const action = new LogOutAction();
@@ -229,7 +245,8 @@ describe('authReducer', () => {
blocking: false,
loading: false,
info: undefined,
userId: EPersonMock.id
userId: EPersonMock.id,
idle: false
};
const action = new LogOutSuccessAction();
@@ -243,7 +260,8 @@ describe('authReducer', () => {
loading: true,
info: undefined,
refreshing: false,
userId: undefined
userId: undefined,
idle: false
};
expect(newState).toEqual(state);
});
@@ -257,7 +275,8 @@ describe('authReducer', () => {
blocking: false,
loading: false,
info: undefined,
userId: EPersonMock.id
userId: EPersonMock.id,
idle: false
};
const action = new LogOutErrorAction(mockError);
@@ -270,7 +289,8 @@ describe('authReducer', () => {
blocking: false,
loading: false,
info: undefined,
userId: EPersonMock.id
userId: EPersonMock.id,
idle: false
};
expect(newState).toEqual(state);
});
@@ -283,7 +303,8 @@ describe('authReducer', () => {
error: undefined,
blocking: true,
loading: true,
info: undefined
info: undefined,
idle: false
};
const action = new RetrieveAuthenticatedEpersonSuccessAction(EPersonMock.id);
const newState = authReducer(initialState, action);
@@ -295,7 +316,8 @@ describe('authReducer', () => {
blocking: false,
loading: false,
info: undefined,
userId: EPersonMock.id
userId: EPersonMock.id,
idle: false
};
expect(newState).toEqual(state);
});
@@ -307,7 +329,8 @@ describe('authReducer', () => {
error: undefined,
blocking: true,
loading: true,
info: undefined
info: undefined,
idle: false
};
const action = new RetrieveAuthenticatedEpersonErrorAction(mockError);
const newState = authReducer(initialState, action);
@@ -318,7 +341,8 @@ describe('authReducer', () => {
loaded: true,
blocking: false,
loading: false,
info: undefined
info: undefined,
idle: false
};
expect(newState).toEqual(state);
});
@@ -332,7 +356,8 @@ describe('authReducer', () => {
blocking: false,
loading: false,
info: undefined,
userId: EPersonMock.id
userId: EPersonMock.id,
idle: false
};
const newTokenInfo = new AuthTokenInfo('Refreshed token');
const action = new RefreshTokenAction(newTokenInfo);
@@ -346,7 +371,8 @@ describe('authReducer', () => {
loading: false,
info: undefined,
userId: EPersonMock.id,
refreshing: true
refreshing: true,
idle: false
};
expect(newState).toEqual(state);
});
@@ -361,7 +387,8 @@ describe('authReducer', () => {
loading: false,
info: undefined,
userId: EPersonMock.id,
refreshing: true
refreshing: true,
idle: false
};
const newTokenInfo = new AuthTokenInfo('Refreshed token');
const action = new RefreshTokenSuccessAction(newTokenInfo);
@@ -375,7 +402,8 @@ describe('authReducer', () => {
loading: false,
info: undefined,
userId: EPersonMock.id,
refreshing: false
refreshing: false,
idle: false
};
expect(newState).toEqual(state);
});
@@ -390,7 +418,8 @@ describe('authReducer', () => {
loading: false,
info: undefined,
userId: EPersonMock.id,
refreshing: true
refreshing: true,
idle: false
};
const action = new RefreshTokenErrorAction();
const newState = authReducer(initialState, action);
@@ -403,7 +432,8 @@ describe('authReducer', () => {
loading: false,
info: undefined,
refreshing: false,
userId: undefined
userId: undefined,
idle: false
};
expect(newState).toEqual(state);
});
@@ -417,7 +447,8 @@ describe('authReducer', () => {
blocking: false,
loading: false,
info: undefined,
userId: EPersonMock.id
userId: EPersonMock.id,
idle: false
};
state = {
@@ -428,7 +459,8 @@ describe('authReducer', () => {
loading: false,
error: undefined,
info: 'Message',
userId: undefined
userId: undefined,
idle: false
};
});
@@ -450,6 +482,7 @@ describe('authReducer', () => {
loaded: false,
blocking: false,
loading: false,
idle: false
};
const action = new AddAuthenticationMessageAction('Message');
const newState = authReducer(initialState, action);
@@ -458,7 +491,8 @@ describe('authReducer', () => {
loaded: false,
blocking: false,
loading: false,
info: 'Message'
info: 'Message',
idle: false
};
expect(newState).toEqual(state);
});
@@ -470,7 +504,8 @@ describe('authReducer', () => {
blocking: false,
loading: false,
error: 'Error',
info: 'Message'
info: 'Message',
idle: false
};
const action = new ResetAuthenticationMessagesAction();
const newState = authReducer(initialState, action);
@@ -480,7 +515,8 @@ describe('authReducer', () => {
blocking: false,
loading: false,
error: undefined,
info: undefined
info: undefined,
idle: false
};
expect(newState).toEqual(state);
});
@@ -490,7 +526,8 @@ describe('authReducer', () => {
authenticated: false,
loaded: false,
blocking: false,
loading: false
loading: false,
idle: false
};
const action = new SetRedirectUrlAction('redirect.url');
const newState = authReducer(initialState, action);
@@ -499,7 +536,8 @@ describe('authReducer', () => {
loaded: false,
blocking: false,
loading: false,
redirectUrl: 'redirect.url'
redirectUrl: 'redirect.url',
idle: false
};
expect(newState).toEqual(state);
});
@@ -510,7 +548,8 @@ describe('authReducer', () => {
loaded: false,
blocking: false,
loading: false,
authMethods: []
authMethods: [],
idle: false
};
const action = new RetrieveAuthMethodsAction(new AuthStatus(), true);
const newState = authReducer(initialState, action);
@@ -519,7 +558,8 @@ describe('authReducer', () => {
loaded: false,
blocking: true,
loading: true,
authMethods: []
authMethods: [],
idle: false
};
expect(newState).toEqual(state);
});
@@ -530,7 +570,8 @@ describe('authReducer', () => {
loaded: false,
blocking: true,
loading: true,
authMethods: []
authMethods: [],
idle: false
};
const authMethods = [
new AuthMethod(AuthMethodType.Password),
@@ -543,7 +584,8 @@ describe('authReducer', () => {
loaded: false,
blocking: false,
loading: false,
authMethods: authMethods
authMethods: authMethods,
idle: false
};
expect(newState).toEqual(state);
});
@@ -554,7 +596,8 @@ describe('authReducer', () => {
loaded: false,
blocking: true,
loading: true,
authMethods: []
authMethods: [],
idle: false
};
const authMethods = [
new AuthMethod(AuthMethodType.Password),
@@ -588,7 +631,50 @@ describe('authReducer', () => {
loaded: false,
blocking: false,
loading: false,
authMethods: [new AuthMethod(AuthMethodType.Password)]
authMethods: [new AuthMethod(AuthMethodType.Password)],
idle: false
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a SET_USER_AS_IDLE action', () => {
initialState = {
authenticated: true,
loaded: true,
blocking: false,
loading: false,
idle: false
};
const action = new SetUserAsIdleAction();
const newState = authReducer(initialState, action);
state = {
authenticated: true,
loaded: true,
blocking: false,
loading: false,
idle: true
};
expect(newState).toEqual(state);
});
it('should properly set the state, in response to a UNSET_USER_AS_IDLE action', () => {
initialState = {
authenticated: true,
loaded: true,
blocking: false,
loading: false,
idle: true
};
const action = new UnsetUserAsIdleAction();
const newState = authReducer(initialState, action);
state = {
authenticated: true,
loaded: true,
blocking: false,
loading: false,
idle: false
};
expect(newState).toEqual(state);
});