mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
added test and docs for 404 operator
This commit is contained in:
@@ -13,9 +13,11 @@ import {
|
||||
getRequestFromRequestUUID,
|
||||
getResourceLinksFromResponse,
|
||||
getResponseFromEntry,
|
||||
getSucceededRemoteData
|
||||
getSucceededRemoteData, redirectToPageNotFoundOn404
|
||||
} from './operators';
|
||||
import { RemoteData } from '../data/remote-data';
|
||||
import { RemoteDataError } from '../data/remote-data-error';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
|
||||
describe('Core Module - RxJS Operators', () => {
|
||||
let scheduler: TestScheduler;
|
||||
@@ -193,6 +195,34 @@ describe('Core Module - RxJS Operators', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('redirectToPageNotFoundOn404', () => {
|
||||
let router;
|
||||
beforeEach(() => {
|
||||
router = jasmine.createSpyObj('router', ['navigateByUrl']);
|
||||
});
|
||||
|
||||
it('should call navigateByUrl to a 404 page, when the remote data contains a 404 error', () => {
|
||||
const testRD = new RemoteData(false, false, false, new RemoteDataError(404, 'Not Found', 'Object was not found'), undefined);
|
||||
|
||||
observableOf(testRD).pipe(redirectToPageNotFoundOn404(router)).subscribe();
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith('/404', { skipLocationChange: true });
|
||||
});
|
||||
|
||||
it('should not call navigateByUrl to a 404 page, when the remote data contains another error than a 404', () => {
|
||||
const testRD = new RemoteData(false, false, false, new RemoteDataError(500, 'Server Error', 'Something went wrong'), undefined);
|
||||
|
||||
observableOf(testRD).pipe(redirectToPageNotFoundOn404(router)).subscribe();
|
||||
expect(router.navigateByUrl).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call navigateByUrl to a 404 page, when the remote data contains no error', () => {
|
||||
const testRD = new RemoteData(false, false, true, null, undefined);
|
||||
|
||||
observableOf(testRD).pipe(redirectToPageNotFoundOn404(router)).subscribe();
|
||||
expect(router.navigateByUrl).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getResponseFromEntry', () => {
|
||||
it('should return the response for all not empty request entries, when they have a value', () => {
|
||||
const source = hot('abcdefg', testRCEs);
|
||||
|
Reference in New Issue
Block a user