mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 20:43:08 +00:00
79700: Doc fixes, Spec tests authService & ariaLabelledBy for idle-modal
This commit is contained in:
@@ -249,7 +249,7 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
.subscribe(([userIdle, authenticated]) => {
|
.subscribe(([userIdle, authenticated]) => {
|
||||||
if (userIdle && authenticated) {
|
if (userIdle && authenticated) {
|
||||||
if (!this.idleModalOpen) {
|
if (!this.idleModalOpen) {
|
||||||
const modalRef = this.modalService.open(IdleModalComponent);
|
const modalRef = this.modalService.open(IdleModalComponent, { ariaLabelledBy: 'idle-modal.header' });
|
||||||
this.idleModalOpen = true;
|
this.idleModalOpen = true;
|
||||||
modalRef.componentInstance.response.pipe(take(1)).subscribe((closed: boolean) => {
|
modalRef.componentInstance.response.pipe(take(1)).subscribe((closed: boolean) => {
|
||||||
if (closed) {
|
if (closed) {
|
||||||
|
@@ -31,6 +31,7 @@ import { NotificationsService } from '../../shared/notifications/notifications.s
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { getMockTranslateService } from '../../shared/mocks/translate.service.mock';
|
import { getMockTranslateService } from '../../shared/mocks/translate.service.mock';
|
||||||
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||||
|
import { SetUserAsIdleAction, UnsetUserAsIdleAction } from './auth.actions';
|
||||||
|
|
||||||
describe('AuthService test', () => {
|
describe('AuthService test', () => {
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ describe('AuthService test', () => {
|
|||||||
let token: AuthTokenInfo;
|
let token: AuthTokenInfo;
|
||||||
let authenticatedState;
|
let authenticatedState;
|
||||||
let unAuthenticatedState;
|
let unAuthenticatedState;
|
||||||
|
let idleState;
|
||||||
let linkService;
|
let linkService;
|
||||||
let hardRedirectService;
|
let hardRedirectService;
|
||||||
|
|
||||||
@@ -68,14 +70,24 @@ describe('AuthService test', () => {
|
|||||||
loaded: true,
|
loaded: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
authToken: token,
|
authToken: token,
|
||||||
user: EPersonMock
|
user: EPersonMock,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
unAuthenticatedState = {
|
unAuthenticatedState = {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
loaded: true,
|
loaded: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
authToken: undefined,
|
authToken: undefined,
|
||||||
user: undefined
|
user: undefined,
|
||||||
|
idle: false
|
||||||
|
};
|
||||||
|
idleState = {
|
||||||
|
authenticated: true,
|
||||||
|
loaded: true,
|
||||||
|
loading: false,
|
||||||
|
authToken: token,
|
||||||
|
user: EPersonMock,
|
||||||
|
idle: true
|
||||||
};
|
};
|
||||||
authRequest = new AuthRequestServiceStub();
|
authRequest = new AuthRequestServiceStub();
|
||||||
routeStub = new ActivatedRouteStub();
|
routeStub = new ActivatedRouteStub();
|
||||||
@@ -186,6 +198,26 @@ describe('AuthService test', () => {
|
|||||||
expect(authMethods.length).toBe(2);
|
expect(authMethods.length).toBe(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('setIdle true', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
authService.setIdle(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('store should dispatch SetUserAsIdleAction', () => {
|
||||||
|
expect(mockStore.dispatch).toHaveBeenCalledWith(new SetUserAsIdleAction());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setIdle false', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
authService.setIdle(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('store should dispatch UnsetUserAsIdleAction', () => {
|
||||||
|
expect(mockStore.dispatch).toHaveBeenCalledWith(new UnsetUserAsIdleAction());
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('', () => {
|
describe('', () => {
|
||||||
@@ -256,6 +288,12 @@ describe('AuthService test', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('isUserIdle should return false when user is not yet idle', () => {
|
||||||
|
authService.isUserIdle().subscribe((status: boolean) => {
|
||||||
|
expect(status).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('', () => {
|
describe('', () => {
|
||||||
@@ -514,4 +552,44 @@ describe('AuthService test', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when user is idle', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
init();
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
StoreModule.forRoot({ authReducer }, {
|
||||||
|
runtimeChecks: {
|
||||||
|
strictStateImmutability: false,
|
||||||
|
strictActionImmutability: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: AuthRequestService, useValue: authRequest },
|
||||||
|
{ provide: REQUEST, useValue: {} },
|
||||||
|
{ provide: Router, useValue: routerStub },
|
||||||
|
{ provide: RouteService, useValue: routeServiceStub },
|
||||||
|
{ provide: RemoteDataBuildService, useValue: linkService },
|
||||||
|
CookieService,
|
||||||
|
AuthService
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(inject([CookieService, AuthRequestService, Store, Router, RouteService], (cookieService: CookieService, authReqService: AuthRequestService, store: Store<AppState>, router: Router, routeService: RouteService, notificationsService: NotificationsService, translateService: TranslateService) => {
|
||||||
|
store
|
||||||
|
.subscribe((state) => {
|
||||||
|
(state as any).core = Object.create({});
|
||||||
|
(state as any).core.auth = idleState;
|
||||||
|
});
|
||||||
|
authService = new AuthService({}, window, undefined, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService, notificationsService, translateService);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('isUserIdle should return true when user is not idle', () => {
|
||||||
|
authService.isUserIdle().subscribe((status: boolean) => {
|
||||||
|
expect(status).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="modal-header">{{ "idle-modal.header" | translate }}
|
<div class="modal-header" id="idle-modal.header">{{ "idle-modal.header" | translate }}
|
||||||
<button type="button" class="close" (click)="closePressed()" aria-label="Close">
|
<button type="button" class="close" (click)="closePressed()" aria-label="Close">
|
||||||
<span aria-hidden="true">×</span>
|
<span aria-hidden="true">×</span>
|
||||||
</button>
|
</button>
|
||||||
|
@@ -42,16 +42,16 @@ export const environment: GlobalConfig = {
|
|||||||
timePerMethod: {[RestRequestMethod.PATCH]: 3} as any // time in seconds
|
timePerMethod: {[RestRequestMethod.PATCH]: 3} as any // time in seconds
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Authority settings
|
// Authentication settings
|
||||||
auth: {
|
auth: {
|
||||||
// Authority UI settings
|
// Authentication UI settings
|
||||||
ui: {
|
ui: {
|
||||||
// the amount of time before the idle warning is shown
|
// the amount of time before the idle warning is shown
|
||||||
timeUntilIdle: 15 * 60 * 1000, // 15 minutes
|
timeUntilIdle: 15 * 60 * 1000, // 15 minutes
|
||||||
// the amount of time the user has to react after the idle warning is shown before they are logged out.
|
// the amount of time the user has to react after the idle warning is shown before they are logged out.
|
||||||
idleGracePeriod: 5 * 60 * 1000, // 5 minutes
|
idleGracePeriod: 5 * 60 * 1000, // 5 minutes
|
||||||
},
|
},
|
||||||
// Authority REST settings
|
// Authentication REST settings
|
||||||
rest: {
|
rest: {
|
||||||
// If the rest token expires in less than this amount of time, it will be refreshed automatically.
|
// If the rest token expires in less than this amount of time, it will be refreshed automatically.
|
||||||
// This is independent from the idle warning.
|
// This is independent from the idle warning.
|
||||||
|
@@ -35,16 +35,16 @@ export const environment: Partial<GlobalConfig> = {
|
|||||||
timePerMethod: {[RestRequestMethod.PATCH]: 3} as any // time in seconds
|
timePerMethod: {[RestRequestMethod.PATCH]: 3} as any // time in seconds
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Authority settings
|
// Authentication settings
|
||||||
auth: {
|
auth: {
|
||||||
// Authority UI settings
|
// Authentication UI settings
|
||||||
ui: {
|
ui: {
|
||||||
// the amount of time before the idle warning is shown
|
// the amount of time before the idle warning is shown
|
||||||
timeUntilIdle: 20000, // 20 sec
|
timeUntilIdle: 20000, // 20 sec
|
||||||
// the amount of time the user has to react after the idle warning is shown before they are logged out.
|
// the amount of time the user has to react after the idle warning is shown before they are logged out.
|
||||||
idleGracePeriod: 20000, // 20 sec
|
idleGracePeriod: 20000, // 20 sec
|
||||||
},
|
},
|
||||||
// Authority REST settings
|
// Authentication REST settings
|
||||||
rest: {
|
rest: {
|
||||||
// If the rest token expires in less than this amount of time, it will be refreshed automatically.
|
// If the rest token expires in less than this amount of time, it will be refreshed automatically.
|
||||||
// This is independent from the idle warning.
|
// This is independent from the idle warning.
|
||||||
|
Reference in New Issue
Block a user