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