Merge branch 'master' into community-and-collection-forms

Conflicts:
	src/app/core/data/item-data.service.spec.ts
	src/app/core/data/item-data.service.ts
	src/app/core/shared/operators.spec.ts
	src/app/core/shared/operators.ts
	src/app/shared/shared.module.ts
This commit is contained in:
lotte
2019-01-22 08:34:51 +01:00
51 changed files with 2212 additions and 36 deletions

View File

@@ -7,9 +7,15 @@ import { RequestService } from '../data/request.service';
import {
configureRequest,
filterSuccessfulResponses,
getRemoteDataPayload, getRequestFromRequestHref, getRequestFromRequestUUID,
getResourceLinksFromResponse, getResponseFromEntry,
getAllSucceededRemoteData,
getRemoteDataPayload,
getRequestFromRequestHref,
getRequestFromRequestUUID,
getResourceLinksFromResponse,
getResponseFromEntry,
getSucceededRemoteData
} from './operators';
import { RemoteData } from '../data/remote-data';
describe('Core Module - RxJS Operators', () => {
let scheduler: TestScheduler;
@@ -48,7 +54,7 @@ describe('Core Module - RxJS Operators', () => {
const result = source.pipe(getRequestFromRequestHref(requestService));
const expected = cold('a', { a: new RequestEntry() });
expect(result).toBeObservable(expected)
expect(result).toBeObservable(expected);
});
it('should use the requestService to fetch the request by its self link', () => {
@@ -68,7 +74,7 @@ describe('Core Module - RxJS Operators', () => {
const result = source.pipe(getRequestFromRequestHref(requestService));
const expected = cold('-');
expect(result).toBeObservable(expected)
expect(result).toBeObservable(expected);
});
});
@@ -81,7 +87,7 @@ describe('Core Module - RxJS Operators', () => {
const result = source.pipe(getRequestFromRequestUUID(requestService));
const expected = cold('a', { a: new RequestEntry() });
expect(result).toBeObservable(expected)
expect(result).toBeObservable(expected);
});
it('should use the requestService to fetch the request by its request uuid', () => {
@@ -101,7 +107,7 @@ describe('Core Module - RxJS Operators', () => {
const result = source.pipe(getRequestFromRequestUUID(requestService));
const expected = cold('-');
expect(result).toBeObservable(expected)
expect(result).toBeObservable(expected);
});
});
@@ -111,7 +117,7 @@ describe('Core Module - RxJS Operators', () => {
const result = source.pipe(filterSuccessfulResponses());
const expected = cold('a--d-', testResponses);
expect(result).toBeObservable(expected)
expect(result).toBeObservable(expected);
});
});
@@ -124,7 +130,7 @@ describe('Core Module - RxJS Operators', () => {
d: testRCEs.d.response.resourceSelfLinks
});
expect(result).toBeObservable(expected)
expect(result).toBeObservable(expected);
});
});
@@ -136,7 +142,7 @@ describe('Core Module - RxJS Operators', () => {
scheduler.schedule(() => source.pipe(configureRequest(requestService)).subscribe());
scheduler.flush();
expect(requestService.configure).toHaveBeenCalledWith(testRequest)
expect(requestService.configure).toHaveBeenCalledWith(testRequest);
});
});
@@ -149,7 +155,25 @@ describe('Core Module - RxJS Operators', () => {
a: testRD.a.payload,
});
expect(result).toBeObservable(expected)
expect(result).toBeObservable(expected);
});
});
describe('getSucceededRemoteData', () => {
it('should return the first() hasSucceeded RemoteData Observable', () => {
const testRD = {
a: new RemoteData(false, false, true, null, undefined),
b: new RemoteData(false, false, false, null, 'b'),
c: new RemoteData(false, false, undefined, null, 'c'),
d: new RemoteData(false, false, true, null, 'd'),
e: new RemoteData(false, false, true, null, 'e'),
};
const source = hot('abcde', testRD);
const result = source.pipe(getSucceededRemoteData());
result.subscribe((value) => expect(value)
.toEqual(new RemoteData(false, false, true, null, 'd')));
});
});
@@ -168,4 +192,23 @@ describe('Core Module - RxJS Operators', () => {
expect(result).toBeObservable(expected)
});
});
describe('getAllSucceededRemoteData', () => {
it('should return all hasSucceeded RemoteData Observables', () => {
const testRD = {
a: new RemoteData(false, false, true, null, undefined),
b: new RemoteData(false, false, false, null, 'b'),
c: new RemoteData(false, false, undefined, null, 'c'),
d: new RemoteData(false, false, true, null, 'd'),
e: new RemoteData(false, false, true, null, 'e'),
};
const source = hot('abcde', testRD);
const result = source.pipe(getAllSucceededRemoteData());
const expected = cold('---de', testRD);
expect(result).toBeObservable(expected);
});
});
});