mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
Merge remote-tracking branch 'remotes/origin/master' into submission
# Conflicts: # package.json # src/app/+admin/admin-registries/metadata-schema/metadata-schema.component.spec.ts # src/app/+search-page/search-service/search.service.spec.ts # src/app/app.module.ts # src/app/core/auth/auth.interceptor.ts # src/app/core/cache/response-cache.service.spec.ts # src/app/core/data/browse-response-parsing.service.spec.ts # src/app/core/data/data.service.spec.ts # src/app/core/data/request.service.spec.ts # src/app/core/data/request.service.ts # src/app/core/dspace-rest-v2/dspace-rest-v2.service.ts # src/app/core/integration/integration.service.ts # src/app/core/metadata/metadata.service.spec.ts # src/app/core/registry/registry.service.spec.ts # src/app/core/shared/collection.model.ts # src/app/core/shared/item.model.ts # src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.component.spec.ts # src/app/shared/form/builder/ds-dynamic-form-ui/models/dynamic-group/dynamic-group.components.ts # src/app/shared/form/builder/ds-dynamic-form-ui/models/list/dynamic-list.component.ts # src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.spec.ts # src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.ts # src/app/shared/form/builder/ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.component.ts # src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts # src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.ts # src/app/shared/form/builder/ds-dynamic-form-ui/models/typeahead/dynamic-typeahead.component.ts # src/app/shared/form/builder/form-builder.service.spec.ts # src/app/shared/form/form.service.spec.ts # src/app/shared/notifications/notification/notification.component.spec.ts # src/app/shared/services/route.service.spec.ts # src/app/shared/services/route.service.ts # src/app/shared/shared.module.ts # yarn.lock
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { Store } from '@ngrx/store';
|
||||
import { cold, hot } from 'jasmine-marbles';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/of'
|
||||
import * as ngrx from '@ngrx/store';
|
||||
import { ActionsSubject, Store } from '@ngrx/store';
|
||||
import { cold, getTestScheduler, hot } from 'jasmine-marbles';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { getMockObjectCacheService } from '../../shared/mocks/mock-object-cache.service';
|
||||
import { getMockResponseCacheService } from '../../shared/mocks/mock-response-cache.service';
|
||||
import { getMockStore } from '../../shared/mocks/mock-store';
|
||||
import { defaultUUID, getMockUUIDService } from '../../shared/mocks/mock-uuid.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { ResponseCacheService } from '../cache/response-cache.service';
|
||||
@@ -18,11 +17,15 @@ import {
|
||||
OptionsRequest,
|
||||
PatchRequest,
|
||||
PostRequest,
|
||||
PutRequest, RestRequest
|
||||
PutRequest,
|
||||
RestRequest
|
||||
} from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
||||
|
||||
describe('RequestService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
let service: RequestService;
|
||||
let serviceAsAny: any;
|
||||
let objectCache: ObjectCacheService;
|
||||
@@ -39,19 +42,26 @@ describe('RequestService', () => {
|
||||
const testOptionsRequest = new OptionsRequest(testUUID, testHref);
|
||||
const testHeadRequest = new HeadRequest(testUUID, testHref);
|
||||
const testPatchRequest = new PatchRequest(testUUID, testHref);
|
||||
|
||||
let selectSpy;
|
||||
beforeEach(() => {
|
||||
scheduler = getTestScheduler();
|
||||
|
||||
objectCache = getMockObjectCacheService();
|
||||
(objectCache.hasBySelfLink as any).and.returnValue(false);
|
||||
|
||||
responseCache = getMockResponseCacheService();
|
||||
(responseCache.has as any).and.returnValue(false);
|
||||
(responseCache.get as any).and.returnValue(Observable.of(undefined));
|
||||
(responseCache.get as any).and.returnValue(observableOf(undefined));
|
||||
|
||||
uuidService = getMockUUIDService();
|
||||
|
||||
store = getMockStore<CoreState>();
|
||||
(store.select as any).and.returnValue(Observable.of(undefined));
|
||||
store = new Store<CoreState>(new BehaviorSubject({}), new ActionsSubject(), null);
|
||||
selectSpy = spyOnProperty(ngrx, 'select')
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => cold('a', { a: undefined });
|
||||
};
|
||||
});
|
||||
|
||||
service = new RequestService(
|
||||
objectCache,
|
||||
@@ -74,7 +84,7 @@ describe('RequestService', () => {
|
||||
describe('isPending', () => {
|
||||
describe('before the request is configured', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getByHref').and.returnValue(Observable.of(undefined));
|
||||
spyOn(service, 'getByHref').and.returnValue(observableOf(undefined));
|
||||
});
|
||||
|
||||
it('should return false', () => {
|
||||
@@ -87,7 +97,7 @@ describe('RequestService', () => {
|
||||
|
||||
describe('when the request has been configured but hasn\'t reached the store yet', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getByHref').and.returnValue(Observable.of(undefined));
|
||||
spyOn(service, 'getByHref').and.returnValue(observableOf(undefined));
|
||||
serviceAsAny.requestsOnTheirWayToTheStore = [testHref];
|
||||
});
|
||||
|
||||
@@ -101,7 +111,7 @@ describe('RequestService', () => {
|
||||
|
||||
describe('when the request has reached the store, before the server responds', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getByHref').and.returnValue(Observable.of({
|
||||
spyOn(service, 'getByHref').and.returnValue(observableOf({
|
||||
completed: false
|
||||
}))
|
||||
});
|
||||
@@ -116,7 +126,7 @@ describe('RequestService', () => {
|
||||
|
||||
describe('after the server responds', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getByHref').and.returnValues(Observable.of({
|
||||
spyOn(service, 'getByHref').and.returnValues(observableOf({
|
||||
completed: true
|
||||
}));
|
||||
});
|
||||
@@ -134,11 +144,15 @@ describe('RequestService', () => {
|
||||
describe('getByUUID', () => {
|
||||
describe('if the request with the specified UUID exists in the store', () => {
|
||||
beforeEach(() => {
|
||||
(store.select as any).and.returnValues(hot('a', {
|
||||
a: {
|
||||
completed: true
|
||||
}
|
||||
}));
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => hot('a', {
|
||||
a: {
|
||||
completed: true
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an Observable of the RequestEntry', () => {
|
||||
@@ -155,9 +169,11 @@ describe('RequestService', () => {
|
||||
|
||||
describe('if the request with the specified UUID doesn\'t exist in the store', () => {
|
||||
beforeEach(() => {
|
||||
(store.select as any).and.returnValues(hot('a', {
|
||||
a: undefined
|
||||
}));
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => hot('a', { a: undefined });
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an Observable of undefined', () => {
|
||||
@@ -175,9 +191,11 @@ describe('RequestService', () => {
|
||||
describe('getByHref', () => {
|
||||
describe('when the request with the specified href exists in the store', () => {
|
||||
beforeEach(() => {
|
||||
(store.select as any).and.returnValues(hot('a', {
|
||||
a: testUUID
|
||||
}));
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => hot('a', { a: testUUID });
|
||||
};
|
||||
});
|
||||
spyOn(service, 'getByUUID').and.returnValue(cold('b', {
|
||||
b: {
|
||||
completed: true
|
||||
@@ -199,9 +217,11 @@ describe('RequestService', () => {
|
||||
|
||||
describe('when the request with the specified href doesn\'t exist in the store', () => {
|
||||
beforeEach(() => {
|
||||
(store.select as any).and.returnValues(hot('a', {
|
||||
a: undefined
|
||||
}));
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => hot('a', { a: undefined });
|
||||
};
|
||||
});
|
||||
spyOn(service, 'getByUUID').and.returnValue(cold('b', {
|
||||
b: undefined
|
||||
}));
|
||||
@@ -242,7 +262,8 @@ describe('RequestService', () => {
|
||||
});
|
||||
|
||||
it('should dispatch the request', () => {
|
||||
service.configure(request);
|
||||
scheduler.schedule(() => service.configure(request));
|
||||
scheduler.flush();
|
||||
expect(serviceAsAny.dispatchRequest).toHaveBeenCalledWith(request);
|
||||
});
|
||||
});
|
||||
@@ -302,7 +323,7 @@ describe('RequestService', () => {
|
||||
|
||||
describe('and it\'s a DSOSuccessResponse', () => {
|
||||
beforeEach(() => {
|
||||
(responseCache.get as any).and.returnValues(Observable.of({
|
||||
(responseCache.get as any).and.returnValues(observableOf({
|
||||
response: {
|
||||
isSuccessful: true,
|
||||
resourceSelfLinks: [
|
||||
@@ -335,7 +356,7 @@ describe('RequestService', () => {
|
||||
beforeEach(() => {
|
||||
(objectCache.hasBySelfLink as any).and.returnValues(false);
|
||||
(responseCache.has as any).and.returnValues(true);
|
||||
(responseCache.get as any).and.returnValues(Observable.of({
|
||||
(responseCache.get as any).and.returnValues(observableOf({
|
||||
response: {
|
||||
isSuccessful: true
|
||||
}
|
||||
@@ -377,6 +398,10 @@ describe('RequestService', () => {
|
||||
});
|
||||
|
||||
describe('dispatchRequest', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(store, 'dispatch');
|
||||
});
|
||||
|
||||
it('should dispatch a RequestConfigureAction', () => {
|
||||
const request = testGetRequest;
|
||||
serviceAsAny.dispatchRequest(request);
|
||||
@@ -431,7 +456,7 @@ describe('RequestService', () => {
|
||||
|
||||
describe('when the request is added to the store', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getByHref').and.returnValue(Observable.of({
|
||||
spyOn(service, 'getByHref').and.returnValue(observableOf({
|
||||
request,
|
||||
requestPending: false,
|
||||
responsePending: true,
|
||||
@@ -440,6 +465,11 @@ describe('RequestService', () => {
|
||||
});
|
||||
|
||||
it('should stop tracking the request', () => {
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => observableOf({ request });
|
||||
};
|
||||
});
|
||||
serviceAsAny.trackRequestsOnTheirWayToTheStore(request);
|
||||
expect(service.getByHref).toHaveBeenCalledWith(request.href);
|
||||
expect(serviceAsAny.requestsOnTheirWayToTheStore.includes(request.href)).toBeFalsy();
|
||||
|
Reference in New Issue
Block a user