mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
fixed tests in relaitonship service
This commit is contained in:
@@ -11,11 +11,11 @@ import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
||||
import { Item } from '../shared/item.model';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { PageInfo } from '../shared/page-info.model';
|
||||
import { DeleteRequest } from './request.models';
|
||||
import { DeleteRequest, FindListOptions } from './request.models';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/testing/utils';
|
||||
import { fakeAsync, tick } from '@angular/core/testing';
|
||||
import { createSuccessfulRemoteDataObject$, spyOnOperator } from '../../shared/testing/utils';
|
||||
import * as ItemRelationshipsUtils from '../../+item-page/simple/item-types/shared/item-relationships-utils';
|
||||
|
||||
describe('RelationshipService', () => {
|
||||
let service: RelationshipService;
|
||||
@@ -45,7 +45,7 @@ describe('RelationshipService', () => {
|
||||
relationshipType: observableOf(new RemoteData(false, false, true, undefined, relationshipType))
|
||||
});
|
||||
|
||||
const relationships = [ relationship1, relationship2 ];
|
||||
const relationships = [relationship1, relationship2];
|
||||
|
||||
const item = Object.assign(new Item(), {
|
||||
self: 'fake-item-url/publication',
|
||||
@@ -74,7 +74,8 @@ describe('RelationshipService', () => {
|
||||
const rdbService = getMockRemoteDataBuildService(undefined, buildList$);
|
||||
const objectCache = Object.assign({
|
||||
/* tslint:disable:no-empty */
|
||||
remove: () => {},
|
||||
remove: () => {
|
||||
},
|
||||
hasBySelfLinkObservable: () => observableOf(false)
|
||||
/* tslint:enable:no-empty */
|
||||
}) as ObjectCacheService;
|
||||
@@ -107,9 +108,6 @@ describe('RelationshipService', () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.clock().uninstall();
|
||||
jasmine.clock().install();
|
||||
|
||||
requestService = getMockRequestService(getRequestEntry$(true));
|
||||
service = initTestService();
|
||||
});
|
||||
@@ -129,8 +127,8 @@ describe('RelationshipService', () => {
|
||||
it('should clear the cache of the related items', () => {
|
||||
expect(objectCache.remove).toHaveBeenCalledWith(relatedItem1.self);
|
||||
expect(objectCache.remove).toHaveBeenCalledWith(item.self);
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(relatedItem1.self);
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(item.self);
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(relatedItem1.uuid);
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(item.uuid);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -142,22 +140,55 @@ describe('RelationshipService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRelatedItems', () => {
|
||||
it('should return the related items', () => {
|
||||
service.getRelatedItems(item).subscribe((result) => {
|
||||
expect(result).toEqual(relatedItems);
|
||||
describe('getRelatedItemsByLabel', () => {
|
||||
let relationsList;
|
||||
let mockItem;
|
||||
let mockLabel;
|
||||
let mockOptions;
|
||||
|
||||
beforeEach(() => {
|
||||
relationsList = new PaginatedList(new PageInfo({
|
||||
elementsPerPage: relationships.length,
|
||||
totalElements: relationships.length,
|
||||
currentPage: 1,
|
||||
totalPages: 1
|
||||
}), relationships);
|
||||
mockItem = { uuid: 'someid' } as Item;
|
||||
mockLabel = 'label';
|
||||
mockOptions = { label: 'options' } as FindListOptions;
|
||||
|
||||
const rd$ = createSuccessfulRemoteDataObject$(relationsList);
|
||||
spyOn(service, 'getItemRelationshipsByLabel').and.returnValue(rd$);
|
||||
|
||||
spyOnOperator(ItemRelationshipsUtils, 'paginatedRelationsToItems').and.returnValue((v) => v);
|
||||
});
|
||||
|
||||
it('should call getItemRelationshipsByLabel with the correct params', (done) => {
|
||||
service.getRelatedItemsByLabel(
|
||||
mockItem,
|
||||
mockLabel,
|
||||
mockOptions
|
||||
).subscribe((result) => {
|
||||
expect(service.getItemRelationshipsByLabel).toHaveBeenCalledWith(
|
||||
mockItem,
|
||||
mockLabel,
|
||||
mockOptions,
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRelatedItemsByLabel', () => {
|
||||
it('should return the related items by label', () => {
|
||||
service.getRelatedItemsByLabel(item, relationshipType.rightwardType).subscribe((result) => {
|
||||
expect(result.payload.page).toEqual(relatedItems);
|
||||
it('should use the paginatedRelationsToItems operator', (done) => {
|
||||
service.getRelatedItemsByLabel(
|
||||
mockItem,
|
||||
mockLabel,
|
||||
mockOptions
|
||||
).subscribe((result) => {
|
||||
expect(ItemRelationshipsUtils.paginatedRelationsToItems).toHaveBeenCalledWith(mockItem.uuid);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
function getRemotedataObservable(obj: any): Observable<RemoteData<any>> {
|
||||
|
@@ -21,7 +21,6 @@ import {
|
||||
RollbacktPatchOperationsAction,
|
||||
StartTransactionPatchOperationsAction
|
||||
} from './json-patch-operations.actions';
|
||||
import { MockStore } from '../../shared/testing/mock-store';
|
||||
import { RequestEntry } from '../data/request.reducer';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
@@ -98,27 +97,22 @@ describe('JsonPatchOperationsService test suite', () => {
|
||||
|
||||
}
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
StoreModule.forRoot({}),
|
||||
],
|
||||
providers: [
|
||||
{ provide: Store, useClass: MockStore }
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
function getStore() {
|
||||
return jasmine.createSpyObj('store', {
|
||||
dispatch: {},
|
||||
select: observableOf(mockState['json/patch'][testJsonPatchResourceType]),
|
||||
pipe: observableOf(true)
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
store = TestBed.get(Store);
|
||||
store = getStore();
|
||||
requestService = getMockRequestService(getRequestEntry$(true));
|
||||
rdbService = getMockRemoteDataBuildService();
|
||||
scheduler = getTestScheduler();
|
||||
halService = new HALEndpointServiceStub(resourceEndpointURL);
|
||||
service = initTestService();
|
||||
|
||||
spyOn(store, 'select').and.returnValue(observableOf(mockState['json/patch'][testJsonPatchResourceType]));
|
||||
spyOn(store, 'dispatch').and.callThrough();
|
||||
spyOn(Date.prototype, 'getTime').and.callFake(() => {
|
||||
return timestamp;
|
||||
});
|
||||
@@ -163,7 +157,7 @@ describe('JsonPatchOperationsService test suite', () => {
|
||||
|
||||
describe('when request is not successful', () => {
|
||||
beforeEach(() => {
|
||||
store = TestBed.get(Store);
|
||||
store = getStore();
|
||||
requestService = getMockRequestService(getRequestEntry$(false));
|
||||
rdbService = getMockRemoteDataBuildService();
|
||||
scheduler = getTestScheduler();
|
||||
@@ -226,7 +220,7 @@ describe('JsonPatchOperationsService test suite', () => {
|
||||
|
||||
describe('when request is not successful', () => {
|
||||
beforeEach(() => {
|
||||
store = TestBed.get(Store);
|
||||
store = getStore();
|
||||
requestService = getMockRequestService(getRequestEntry$(false));
|
||||
rdbService = getMockRemoteDataBuildService();
|
||||
scheduler = getTestScheduler();
|
||||
|
@@ -7,12 +7,14 @@ import { SubmissionObjectDataService } from './submission-object-data.service';
|
||||
import { SubmissionScopeType } from './submission-scope-type';
|
||||
import { WorkflowItemDataService } from './workflowitem-data.service';
|
||||
import { WorkspaceitemDataService } from './workspaceitem-data.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
|
||||
describe('SubmissionObjectDataService', () => {
|
||||
let service: SubmissionObjectDataService;
|
||||
let submissionService: SubmissionService;
|
||||
let workspaceitemDataService: WorkspaceitemDataService;
|
||||
let workflowItemDataService: WorkflowItemDataService;
|
||||
let halService: HALEndpointService;
|
||||
|
||||
const submissionId = '1234';
|
||||
const wsiResult = 'wsiResult' as any;
|
||||
@@ -25,6 +27,9 @@ describe('SubmissionObjectDataService', () => {
|
||||
workflowItemDataService = jasmine.createSpyObj('WorkflowItemDataService', {
|
||||
findById: wfiResult
|
||||
});
|
||||
halService = jasmine.createSpyObj('HALEndpointService', {
|
||||
getEndpoint: '/workspaceItem'
|
||||
});
|
||||
});
|
||||
|
||||
describe('findById', () => {
|
||||
@@ -32,7 +37,7 @@ describe('SubmissionObjectDataService', () => {
|
||||
submissionService = jasmine.createSpyObj('SubmissionService', {
|
||||
getSubmissionScope: {}
|
||||
});
|
||||
service = new SubmissionObjectDataService(workspaceitemDataService, workflowItemDataService, submissionService);
|
||||
service = new SubmissionObjectDataService(workspaceitemDataService, workflowItemDataService, submissionService, halService);
|
||||
service.findById(submissionId);
|
||||
expect(submissionService.getSubmissionScope).toHaveBeenCalled();
|
||||
});
|
||||
@@ -42,7 +47,7 @@ describe('SubmissionObjectDataService', () => {
|
||||
submissionService = jasmine.createSpyObj('SubmissionService', {
|
||||
getSubmissionScope: SubmissionScopeType.WorkspaceItem
|
||||
});
|
||||
service = new SubmissionObjectDataService(workspaceitemDataService, workflowItemDataService, submissionService);
|
||||
service = new SubmissionObjectDataService(workspaceitemDataService, workflowItemDataService, submissionService, halService);
|
||||
});
|
||||
|
||||
it('should forward the result of WorkspaceitemDataService.findById()', () => {
|
||||
@@ -57,7 +62,7 @@ describe('SubmissionObjectDataService', () => {
|
||||
submissionService = jasmine.createSpyObj('SubmissionService', {
|
||||
getSubmissionScope: SubmissionScopeType.WorkflowItem
|
||||
});
|
||||
service = new SubmissionObjectDataService(workspaceitemDataService, workflowItemDataService, submissionService);
|
||||
service = new SubmissionObjectDataService(workspaceitemDataService, workflowItemDataService, submissionService, halService);
|
||||
});
|
||||
|
||||
it('should forward the result of WorkflowItemDataService.findById()', () => {
|
||||
@@ -72,7 +77,7 @@ describe('SubmissionObjectDataService', () => {
|
||||
submissionService = jasmine.createSpyObj('SubmissionService', {
|
||||
getSubmissionScope: 'Something else'
|
||||
});
|
||||
service = new SubmissionObjectDataService(workspaceitemDataService, workflowItemDataService, submissionService);
|
||||
service = new SubmissionObjectDataService(workspaceitemDataService, workflowItemDataService, submissionService, halService);
|
||||
});
|
||||
|
||||
it('shouldn\'t call any data service methods', () => {
|
||||
|
@@ -20,7 +20,7 @@ import { WorkspaceItem } from './models/workspaceitem.model';
|
||||
@Injectable()
|
||||
export class WorkspaceitemDataService extends DataService<WorkspaceItem> {
|
||||
protected linkPath = 'workspaceitems';
|
||||
protected responseMsToLive = 10 * 1000;
|
||||
// protected responseMsToLive = 10 * 1000;
|
||||
|
||||
constructor(
|
||||
protected comparator: DSOChangeAnalyzer<WorkspaceItem>,
|
||||
|
@@ -46,6 +46,9 @@ import { FormRowModel } from '../../../core/config/models/config-submission-form
|
||||
import { WorkspaceitemDataService } from '../../../core/submission/workspaceitem-data.service';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model';
|
||||
import { SubmissionObjectDataService } from '../../../core/submission/submission-object-data.service';
|
||||
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
|
||||
function getMockSubmissionFormsConfigService(): SubmissionFormsConfigService {
|
||||
return jasmine.createSpyObj('FormOperationsService', {
|
||||
@@ -178,11 +181,13 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
{ provide: SectionsService, useClass: SectionsServiceStub },
|
||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||
{ provide: ObjectCacheService, useValue: { remove: () => {/*do nothing*/}, hasBySelfLinkObservable: () => observableOf(false) } },
|
||||
{ provide: RequestService, useValue: { removeByHrefSubstring: () => {/*do nothing*/}, hasByHrefObservable: () => observableOf(false) } },
|
||||
{ provide: GLOBAL_CONFIG, useValue: envConfig },
|
||||
{ provide: 'collectionIdProvider', useValue: collectionId },
|
||||
{ provide: 'sectionDataProvider', useValue: sectionObject },
|
||||
{ provide: 'submissionIdProvider', useValue: submissionId },
|
||||
{ provide: WorkspaceitemDataService, useValue: {findById: () => observableOf(new RemoteData(false, false, true, null, new WorkspaceItem()))}},
|
||||
{ provide: SubmissionObjectDataService, useValue: { getHrefByID: () => observableOf('testUrl'), findById: () => observableOf(new RemoteData(false, false, true, null, new WorkspaceItem())) } },
|
||||
ChangeDetectorRef,
|
||||
SubmissionSectionformComponent
|
||||
],
|
||||
@@ -255,7 +260,6 @@ describe('SubmissionSectionformComponent test suite', () => {
|
||||
expect(comp.isLoading).toBeFalsy();
|
||||
expect(comp.initForm).toHaveBeenCalledWith(sectionData);
|
||||
expect(comp.subscriptions).toHaveBeenCalled();
|
||||
|
||||
});
|
||||
|
||||
it('should init form model properly', () => {
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { ChangeDetectorRef, Component, Inject, ViewChild } from '@angular/core';
|
||||
import { DynamicFormControlEvent, DynamicFormControlModel } from '@ng-dynamic-forms/core';
|
||||
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { distinctUntilChanged, filter, find, flatMap, map, take, tap } from 'rxjs/operators';
|
||||
import { combineLatest, Observable, Subscription } from 'rxjs';
|
||||
import { distinctUntilChanged, filter, find, flatMap, map, switchMap, take, tap } from 'rxjs/operators';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
@@ -34,8 +34,11 @@ import { WorkspaceitemSectionFormObject } from '../../../core/submission/models/
|
||||
import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model';
|
||||
import { WorkspaceitemDataService } from '../../../core/submission/workspaceitem-data.service';
|
||||
import { combineLatest as combineLatestObservable } from 'rxjs';
|
||||
import { getSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { getRemoteDataPayload, getSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import { SubmissionObject } from '../../../core/submission/models/submission-object.model';
|
||||
import { SubmissionObjectDataService } from '../../../core/submission/submission-object-data.service';
|
||||
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
|
||||
/**
|
||||
* This component represents a section that contains a Form.
|
||||
@@ -126,6 +129,9 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
* @param {SectionsService} sectionService
|
||||
* @param {SubmissionService} submissionService
|
||||
* @param {TranslateService} translate
|
||||
* @param {SubmissionObjectDataService} submissionObjectService
|
||||
* @param {ObjectCacheService} objectCache
|
||||
* @param {RequestService} requestService
|
||||
* @param {GlobalConfig} EnvConfig
|
||||
* @param {string} injectedCollectionId
|
||||
* @param {SectionDataObject} injectedSectionData
|
||||
@@ -140,7 +146,9 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
protected sectionService: SectionsService,
|
||||
protected submissionService: SubmissionService,
|
||||
protected translate: TranslateService,
|
||||
protected workspaceItemDataService: WorkspaceitemDataService,
|
||||
protected submissionObjectService: SubmissionObjectDataService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected requestService: RequestService,
|
||||
@Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig,
|
||||
@Inject('collectionIdProvider') public injectedCollectionId: string,
|
||||
@Inject('sectionDataProvider') public injectedSectionData: SectionDataObject,
|
||||
@@ -160,7 +168,20 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
|
||||
flatMap(() =>
|
||||
combineLatestObservable(
|
||||
this.sectionService.getSectionData(this.submissionId, this.sectionData.id),
|
||||
this.workspaceItemDataService.findById(this.submissionId).pipe(getSucceededRemoteData(), map((wsiRD: RemoteData<WorkspaceItem>) => wsiRD.payload))
|
||||
this.submissionObjectService.getHrefByID(this.submissionId).pipe(take(1)).pipe(
|
||||
switchMap((href: string) => {
|
||||
this.objectCache.remove(href);
|
||||
this.requestService.removeByHrefSubstring(this.submissionId);
|
||||
return combineLatest(
|
||||
this.objectCache.hasBySelfLinkObservable(href),
|
||||
this.requestService.hasByHrefObservable(href)
|
||||
).pipe(
|
||||
filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC),
|
||||
take(1),
|
||||
switchMap(() => this.submissionObjectService.findById(this.submissionId).pipe(getSucceededRemoteData(), getRemoteDataPayload()) as Observable<SubmissionObject>)
|
||||
)
|
||||
})
|
||||
)
|
||||
)),
|
||||
take(1))
|
||||
.subscribe(([sectionData, workspaceItem]: [WorkspaceitemSectionFormObject, WorkspaceItem]) => {
|
||||
|
Reference in New Issue
Block a user