mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[DSC-287] fix test
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import { ServerCheckGuard } from './server-check.guard';
|
||||
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||
import { first } from 'rxjs/operators';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { getPageInternalServerErrorRoute } from '../../app-routing-paths';
|
||||
import { Router } from '@angular/router';
|
||||
import { RootDataService } from '../data/root-data.service';
|
||||
import { Root } from '../data/root.model';
|
||||
import SpyObj = jasmine.SpyObj;
|
||||
|
||||
describe('ServerCheckGuard', () => {
|
||||
let guard: ServerCheckGuard;
|
||||
let router;
|
||||
let rootDataServiceStub: any;
|
||||
let router: SpyObj<Router>;
|
||||
let rootDataServiceStub: SpyObj<RootDataService>;
|
||||
|
||||
rootDataServiceStub = jasmine.createSpyObj('RootDataService', {
|
||||
findRoot: jasmine.createSpy('findRoot')
|
||||
@@ -19,18 +23,22 @@ describe('ServerCheckGuard', () => {
|
||||
guard = new ServerCheckGuard(router, rootDataServiceStub);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
router.navigateByUrl.calls.reset();
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(guard).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('when root endpoint has succeeded', () => {
|
||||
beforeEach(() => {
|
||||
rootDataServiceStub.findRoot.and.returnValue(createSuccessfulRemoteDataObject$({}));
|
||||
rootDataServiceStub.findRoot.and.returnValue(createSuccessfulRemoteDataObject$<Root>({} as any));
|
||||
});
|
||||
|
||||
it('should not redirect to error page', () => {
|
||||
guard.canActivate({} as any, {} as any).pipe(
|
||||
first()
|
||||
take(1)
|
||||
).subscribe((canActivate: boolean) => {
|
||||
expect(canActivate).toEqual(true);
|
||||
expect(router.navigateByUrl).not.toHaveBeenCalled();
|
||||
@@ -40,12 +48,12 @@ describe('ServerCheckGuard', () => {
|
||||
|
||||
describe('when root endpoint has not succeeded', () => {
|
||||
beforeEach(() => {
|
||||
rootDataServiceStub.findRoot.and.returnValue(createFailedRemoteDataObject$());
|
||||
rootDataServiceStub.findRoot.and.returnValue(createFailedRemoteDataObject$<Root>());
|
||||
});
|
||||
|
||||
it('should redirect to error page', () => {
|
||||
guard.canActivate({} as any, {} as any).pipe(
|
||||
first()
|
||||
take(1)
|
||||
).subscribe((canActivate: boolean) => {
|
||||
expect(canActivate).toEqual(false);
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith(getPageInternalServerErrorRoute());
|
||||
|
Reference in New Issue
Block a user