added test and docs for 404 operator

This commit is contained in:
lotte
2019-05-09 13:39:24 +02:00
parent ee5a9c7df5
commit 187c70847c
9 changed files with 55 additions and 20 deletions

View File

@@ -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);