mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
Add Item Status Edit Actions
Add the Item Withdraw and Reistate action Add the make Item Private and Public action Add the Permanently Delete action
This commit is contained in:
@@ -1,18 +1,23 @@
|
||||
import { cold, getTestScheduler, hot } from 'jasmine-marbles';
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
||||
import { getMockResponseCacheService } from '../../shared/mocks/mock-response-cache.service';
|
||||
import { ResponseCacheEntry } from '../cache/response-cache.reducer';
|
||||
import { ResponseCacheService } from '../cache/response-cache.service';
|
||||
import { GetRequest, RestRequest } from '../data/request.models';
|
||||
import { RequestEntry } from '../data/request.reducer';
|
||||
import { RequestService } from '../data/request.service';
|
||||
import {cold, getTestScheduler, hot} from 'jasmine-marbles';
|
||||
import {TestScheduler} from 'rxjs/testing';
|
||||
import {getMockRequestService} from '../../shared/mocks/mock-request.service';
|
||||
import {getMockResponseCacheService} from '../../shared/mocks/mock-response-cache.service';
|
||||
import {ResponseCacheEntry} from '../cache/response-cache.reducer';
|
||||
import {ResponseCacheService} from '../cache/response-cache.service';
|
||||
import {GetRequest} from '../data/request.models';
|
||||
import {RequestEntry} from '../data/request.reducer';
|
||||
import {RequestService} from '../data/request.service';
|
||||
import {
|
||||
configureRequest,
|
||||
filterSuccessfulResponses, getRemoteDataPayload,
|
||||
getRequestFromSelflink, getResourceLinksFromResponse,
|
||||
getResponseFromSelflink
|
||||
filterSuccessfulResponses,
|
||||
getAllSucceededRemoteData,
|
||||
getRemoteDataPayload,
|
||||
getRequestFromSelflink,
|
||||
getResourceLinksFromResponse,
|
||||
getResponseFromSelflink,
|
||||
getSucceededRemoteData
|
||||
} from './operators';
|
||||
import {RemoteData} from '../data/remote-data';
|
||||
|
||||
describe('Core Module - RxJS Operators', () => {
|
||||
let scheduler: TestScheduler;
|
||||
@@ -20,11 +25,11 @@ describe('Core Module - RxJS Operators', () => {
|
||||
const testSelfLink = 'https://rest.api/';
|
||||
|
||||
const testRCEs = {
|
||||
a: { response: { isSuccessful: true, resourceSelfLinks: ['a', 'b', 'c', 'd'] } },
|
||||
b: { response: { isSuccessful: false, resourceSelfLinks: ['e', 'f'] } },
|
||||
c: { response: { isSuccessful: undefined, resourceSelfLinks: ['g', 'h', 'i'] } },
|
||||
d: { response: { isSuccessful: true, resourceSelfLinks: ['j', 'k', 'l', 'm', 'n'] } },
|
||||
e: { response: { isSuccessful: 1, resourceSelfLinks: [] } }
|
||||
a: {response: {isSuccessful: true, resourceSelfLinks: ['a', 'b', 'c', 'd']}},
|
||||
b: {response: {isSuccessful: false, resourceSelfLinks: ['e', 'f']}},
|
||||
c: {response: {isSuccessful: undefined, resourceSelfLinks: ['g', 'h', 'i']}},
|
||||
d: {response: {isSuccessful: true, resourceSelfLinks: ['j', 'k', 'l', 'm', 'n']}},
|
||||
e: {response: {isSuccessful: 1, resourceSelfLinks: []}}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -36,31 +41,31 @@ describe('Core Module - RxJS Operators', () => {
|
||||
it('should return the RequestEntry corresponding to the self link in the source', () => {
|
||||
requestService = getMockRequestService();
|
||||
|
||||
const source = hot('a', { a: testSelfLink });
|
||||
const source = hot('a', {a: testSelfLink});
|
||||
const result = source.pipe(getRequestFromSelflink(requestService));
|
||||
const expected = cold('a', { a: new RequestEntry()});
|
||||
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', () => {
|
||||
requestService = getMockRequestService();
|
||||
|
||||
const source = hot('a', { a: testSelfLink });
|
||||
const source = hot('a', {a: testSelfLink});
|
||||
scheduler.schedule(() => source.pipe(getRequestFromSelflink(requestService)).subscribe());
|
||||
scheduler.flush();
|
||||
|
||||
expect(requestService.getByHref).toHaveBeenCalledWith(testSelfLink)
|
||||
expect(requestService.getByHref).toHaveBeenCalledWith(testSelfLink);
|
||||
});
|
||||
|
||||
it('shouldn\'t return anything if there is no request matching the self link', () => {
|
||||
requestService = getMockRequestService(cold('a', { a: undefined }));
|
||||
requestService = getMockRequestService(cold('a', {a: undefined}));
|
||||
|
||||
const source = hot('a', { a: testSelfLink });
|
||||
const source = hot('a', {a: testSelfLink});
|
||||
const result = source.pipe(getRequestFromSelflink(requestService));
|
||||
const expected = cold('-');
|
||||
|
||||
expect(result).toBeObservable(expected)
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -74,31 +79,31 @@ describe('Core Module - RxJS Operators', () => {
|
||||
it('should return the ResponseCacheEntry corresponding to the self link in the source', () => {
|
||||
responseCacheService = getMockResponseCacheService();
|
||||
|
||||
const source = hot('a', { a: testSelfLink });
|
||||
const source = hot('a', {a: testSelfLink});
|
||||
const result = source.pipe(getResponseFromSelflink(responseCacheService));
|
||||
const expected = cold('a', { a: new ResponseCacheEntry()});
|
||||
const expected = cold('a', {a: new ResponseCacheEntry()});
|
||||
|
||||
expect(result).toBeObservable(expected)
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
|
||||
it('should use the responseCacheService to fetch the response by the request\'s link', () => {
|
||||
responseCacheService = getMockResponseCacheService();
|
||||
|
||||
const source = hot('a', { a: testSelfLink });
|
||||
const source = hot('a', {a: testSelfLink});
|
||||
scheduler.schedule(() => source.pipe(getResponseFromSelflink(responseCacheService)).subscribe());
|
||||
scheduler.flush();
|
||||
|
||||
expect(responseCacheService.get).toHaveBeenCalledWith(testSelfLink)
|
||||
expect(responseCacheService.get).toHaveBeenCalledWith(testSelfLink);
|
||||
});
|
||||
|
||||
it('shouldn\'t return anything if there is no response matching the request\'s link', () => {
|
||||
responseCacheService = getMockResponseCacheService(undefined, cold('a', { a: undefined }));
|
||||
responseCacheService = getMockResponseCacheService(undefined, cold('a', {a: undefined}));
|
||||
|
||||
const source = hot('a', { a: testSelfLink });
|
||||
const source = hot('a', {a: testSelfLink});
|
||||
const result = source.pipe(getResponseFromSelflink(responseCacheService));
|
||||
const expected = cold('-');
|
||||
|
||||
expect(result).toBeObservable(expected)
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,7 +113,7 @@ describe('Core Module - RxJS Operators', () => {
|
||||
const result = source.pipe(filterSuccessfulResponses());
|
||||
const expected = cold('a--d-', testRCEs);
|
||||
|
||||
expect(result).toBeObservable(expected)
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -121,7 +126,7 @@ describe('Core Module - RxJS Operators', () => {
|
||||
d: testRCEs.d.response.resourceSelfLinks
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected)
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -129,24 +134,61 @@ describe('Core Module - RxJS Operators', () => {
|
||||
it('should call requestService.configure with the source request', () => {
|
||||
requestService = getMockRequestService();
|
||||
const testRequest = new GetRequest('6b789e31-f026-4ff8-8993-4eb3b730c841', testSelfLink);
|
||||
const source = hot('a', { a: testRequest });
|
||||
const source = hot('a', {a: testRequest});
|
||||
scheduler.schedule(() => source.pipe(configureRequest(requestService)).subscribe());
|
||||
scheduler.flush();
|
||||
|
||||
expect(requestService.configure).toHaveBeenCalledWith(testRequest)
|
||||
expect(requestService.configure).toHaveBeenCalledWith(testRequest);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRemoteDataPayload', () => {
|
||||
it('should return the payload of the source RemoteData', () => {
|
||||
const testRD = { a: { payload: 'a' } };
|
||||
const testRD = {a: {payload: 'a'}};
|
||||
const source = hot('a', testRD);
|
||||
const result = source.pipe(getRemoteDataPayload());
|
||||
const expected = cold('a', {
|
||||
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')));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
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);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user