mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
fixed relationship effects tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
|
import { BehaviorSubject, never, Observable, of as observableOf } from 'rxjs';
|
||||||
import { RelationshipEffects } from './relationship.effects';
|
import { RelationshipEffects } from './relationship.effects';
|
||||||
import { async, TestBed } from '@angular/core/testing';
|
import { async, TestBed } from '@angular/core/testing';
|
||||||
import { provideMockActions } from '@ngrx/effects/testing';
|
import { provideMockActions } from '@ngrx/effects/testing';
|
||||||
@@ -103,7 +103,10 @@ describe('RelationshipEffects', () => {
|
|||||||
provideMockActions(() => actions),
|
provideMockActions(() => actions),
|
||||||
{ provide: RelationshipTypeService, useValue: mockRelationshipTypeService },
|
{ provide: RelationshipTypeService, useValue: mockRelationshipTypeService },
|
||||||
{ provide: RelationshipService, useValue: mockRelationshipService },
|
{ provide: RelationshipService, useValue: mockRelationshipService },
|
||||||
{ provide: SubmissionObjectDataService, useValue: {findById: () => createSuccessfulRemoteDataObject$(new WorkspaceItem())}},
|
{ provide: SubmissionObjectDataService, useValue: {
|
||||||
|
findById: () => createSuccessfulRemoteDataObject$(new WorkspaceItem())},
|
||||||
|
getHrefByID: () => observableOf('')
|
||||||
|
},
|
||||||
{ provide: Store, useValue: jasmine.createSpyObj('store', ['dispatch']) },
|
{ provide: Store, useValue: jasmine.createSpyObj('store', ['dispatch']) },
|
||||||
{ provide: ObjectCacheService, useValue: {}},
|
{ provide: ObjectCacheService, useValue: {}},
|
||||||
{ provide: RequestService, useValue: {}},
|
{ provide: RequestService, useValue: {}},
|
||||||
@@ -120,10 +123,15 @@ describe('RelationshipEffects', () => {
|
|||||||
describe('When an ADD_RELATIONSHIP action is triggered', () => {
|
describe('When an ADD_RELATIONSHIP action is triggered', () => {
|
||||||
describe('When it\'s the first time for this identifier', () => {
|
describe('When it\'s the first time for this identifier', () => {
|
||||||
let action;
|
let action;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOnOperator(operators, 'debounceTime').and.returnValue((v) => v.pipe(last()));
|
||||||
|
});
|
||||||
|
|
||||||
it('should set the current value debounceMap and the value of the initialActionMap to ADD_RELATIONSHIP', () => {
|
it('should set the current value debounceMap and the value of the initialActionMap to ADD_RELATIONSHIP', () => {
|
||||||
action = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
action = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
actions = hot('--a-', { a: action });
|
actions = hot('--a-|', { a: action });
|
||||||
const expected = cold('--b-', { b: undefined });
|
const expected = cold('--b-|', { b: undefined });
|
||||||
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
||||||
|
|
||||||
expect((relationEffects as any).initialActionMap[identifier]).toBe(action.type);
|
expect((relationEffects as any).initialActionMap[identifier]).toBe(action.type);
|
||||||
@@ -135,14 +143,17 @@ describe('RelationshipEffects', () => {
|
|||||||
let action;
|
let action;
|
||||||
const testActionType = 'TEST_TYPE';
|
const testActionType = 'TEST_TYPE';
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
spyOnOperator(operators, 'debounceTime').and.returnValue((v) => v);
|
||||||
|
|
||||||
(relationEffects as any).initialActionMap[identifier] = testActionType;
|
(relationEffects as any).initialActionMap[identifier] = testActionType;
|
||||||
(relationEffects as any).debounceMap[identifier] = new BehaviorSubject<string>(testActionType);
|
(relationEffects as any).debounceMap[identifier] = new BehaviorSubject<string>(testActionType);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set the current value debounceMap to ADD_RELATIONSHIP but not change the value of the initialActionMap', () => {
|
it('should set the current value debounceMap to ADD_RELATIONSHIP but not change the value of the initialActionMap', () => {
|
||||||
action = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
action = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
actions = hot('--a-', { a: action });
|
actions = hot('--a-|', { a: action });
|
||||||
const expected = cold('--b-', { b: undefined });
|
|
||||||
|
const expected = cold('--b-|', { b: undefined });
|
||||||
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
||||||
|
|
||||||
expect((relationEffects as any).initialActionMap[identifier]).toBe(testActionType);
|
expect((relationEffects as any).initialActionMap[identifier]).toBe(testActionType);
|
||||||
@@ -160,8 +171,8 @@ describe('RelationshipEffects', () => {
|
|||||||
});
|
});
|
||||||
it('should call addRelationship on the effect', () => {
|
it('should call addRelationship on the effect', () => {
|
||||||
action = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
action = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
actions = hot('--a-', { a: action });
|
actions = hot('--a-|', { a: action });
|
||||||
const expected = cold('--b-', { b: undefined });
|
const expected = cold('--b-|', { b: undefined });
|
||||||
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
||||||
expect((relationEffects as any).addRelationship).toHaveBeenCalledWith(leftItem, rightItem, relationshipType.leftwardType, '1234', undefined)
|
expect((relationEffects as any).addRelationship).toHaveBeenCalledWith(leftItem, rightItem, relationshipType.leftwardType, '1234', undefined)
|
||||||
});
|
});
|
||||||
@@ -179,8 +190,8 @@ describe('RelationshipEffects', () => {
|
|||||||
it('should <b>not</b> call removeRelationship or addRelationship on the effect', () => {
|
it('should <b>not</b> call removeRelationship or addRelationship on the effect', () => {
|
||||||
const actiona = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
const actiona = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
const actionb = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
const actionb = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
actions = hot('--ab-', { a: actiona, b: actionb });
|
actions = hot('--ab-|', { a: actiona, b: actionb });
|
||||||
const expected = cold('--bb-', { b: undefined });
|
const expected = cold('--bb-|', { b: undefined });
|
||||||
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
||||||
expect((relationEffects as any).addRelationship).not.toHaveBeenCalled();
|
expect((relationEffects as any).addRelationship).not.toHaveBeenCalled();
|
||||||
expect((relationEffects as any).removeRelationship).not.toHaveBeenCalled();
|
expect((relationEffects as any).removeRelationship).not.toHaveBeenCalled();
|
||||||
@@ -192,10 +203,14 @@ describe('RelationshipEffects', () => {
|
|||||||
describe('When an REMOVE_RELATIONSHIP action is triggered', () => {
|
describe('When an REMOVE_RELATIONSHIP action is triggered', () => {
|
||||||
describe('When it\'s the first time for this identifier', () => {
|
describe('When it\'s the first time for this identifier', () => {
|
||||||
let action;
|
let action;
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOnOperator(operators, 'debounceTime').and.returnValue((v) => v.pipe(last()));
|
||||||
|
});
|
||||||
|
|
||||||
it('should set the current value debounceMap and the value of the initialActionMap to REMOVE_RELATIONSHIP', () => {
|
it('should set the current value debounceMap and the value of the initialActionMap to REMOVE_RELATIONSHIP', () => {
|
||||||
action = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
action = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
actions = hot('--a-', { a: action });
|
actions = hot('--a-|', { a: action });
|
||||||
const expected = cold('--b-', { b: undefined });
|
const expected = cold('--b-|', { b: undefined });
|
||||||
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
||||||
|
|
||||||
expect((relationEffects as any).initialActionMap[identifier]).toBe(action.type);
|
expect((relationEffects as any).initialActionMap[identifier]).toBe(action.type);
|
||||||
@@ -207,14 +222,16 @@ describe('RelationshipEffects', () => {
|
|||||||
let action;
|
let action;
|
||||||
const testActionType = 'TEST_TYPE';
|
const testActionType = 'TEST_TYPE';
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
spyOnOperator(operators, 'debounceTime').and.returnValue((v) => v);
|
||||||
|
|
||||||
(relationEffects as any).initialActionMap[identifier] = testActionType;
|
(relationEffects as any).initialActionMap[identifier] = testActionType;
|
||||||
(relationEffects as any).debounceMap[identifier] = new BehaviorSubject<string>(testActionType);
|
(relationEffects as any).debounceMap[identifier] = new BehaviorSubject<string>(testActionType);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set the current value debounceMap to REMOVE_RELATIONSHIP but not change the value of the initialActionMap', () => {
|
it('should set the current value debounceMap to REMOVE_RELATIONSHIP but not change the value of the initialActionMap', () => {
|
||||||
action = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
action = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
actions = hot('--a-', { a: action });
|
actions = hot('--a-|', { a: action });
|
||||||
const expected = cold('--b-', { b: undefined });
|
const expected = cold('--b-|', { b: undefined });
|
||||||
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
||||||
|
|
||||||
expect((relationEffects as any).initialActionMap[identifier]).toBe(testActionType);
|
expect((relationEffects as any).initialActionMap[identifier]).toBe(testActionType);
|
||||||
@@ -233,8 +250,8 @@ describe('RelationshipEffects', () => {
|
|||||||
|
|
||||||
it('should call removeRelationship on the effect', () => {
|
it('should call removeRelationship on the effect', () => {
|
||||||
action = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
action = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
actions = hot('--a-', { a: action });
|
actions = hot('--a-|', { a: action });
|
||||||
const expected = cold('--b-', { b: undefined });
|
const expected = cold('--b-|', { b: undefined });
|
||||||
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
||||||
expect((relationEffects as any).removeRelationship).toHaveBeenCalledWith(leftItem, rightItem, relationshipType.leftwardType, '1234', )
|
expect((relationEffects as any).removeRelationship).toHaveBeenCalledWith(leftItem, rightItem, relationshipType.leftwardType, '1234', )
|
||||||
});
|
});
|
||||||
@@ -252,8 +269,8 @@ describe('RelationshipEffects', () => {
|
|||||||
it('should <b>not</b> call addRelationship or removeRelationship on the effect', () => {
|
it('should <b>not</b> call addRelationship or removeRelationship on the effect', () => {
|
||||||
const actionb = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
const actionb = new RemoveRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
const actiona = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
const actiona = new AddRelationshipAction(leftItem, rightItem, relationshipType.leftwardType, '1234');
|
||||||
actions = hot('--ab-', { a: actiona, b: actionb });
|
actions = hot('--ab-|', { a: actiona, b: actionb });
|
||||||
const expected = cold('--bb-', { b: undefined });
|
const expected = cold('--bb-|', { b: undefined });
|
||||||
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
expect(relationEffects.mapLastActions$).toBeObservable(expected);
|
||||||
expect((relationEffects as any).addRelationship).not.toHaveBeenCalled();
|
expect((relationEffects as any).addRelationship).not.toHaveBeenCalled();
|
||||||
expect((relationEffects as any).removeRelationship).not.toHaveBeenCalled();
|
expect((relationEffects as any).removeRelationship).not.toHaveBeenCalled();
|
||||||
|
@@ -20,7 +20,7 @@ import { RequestService } from '../../../../../core/data/request.service';
|
|||||||
import { ServerSyncBufferActionTypes } from '../../../../../core/cache/server-sync-buffer.actions';
|
import { ServerSyncBufferActionTypes } from '../../../../../core/cache/server-sync-buffer.actions';
|
||||||
|
|
||||||
const DEBOUNCE_TIME = 5000;
|
const DEBOUNCE_TIME = 5000;
|
||||||
let updateAfterPatchSubmissionId: string;
|
|
||||||
/**
|
/**
|
||||||
* NGRX effects for RelationshipEffects
|
* NGRX effects for RelationshipEffects
|
||||||
*/
|
*/
|
||||||
@@ -41,6 +41,8 @@ export class RelationshipEffects {
|
|||||||
[identifier: string]: string
|
[identifier: string]: string
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
|
private updateAfterPatchSubmissionId: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Effect that makes sure all last fired RelationshipActions' types are stored in the map of this service, with the object uuid as their key
|
* Effect that makes sure all last fired RelationshipActions' types are stored in the map of this service, with the object uuid as their key
|
||||||
*/
|
*/
|
||||||
@@ -99,7 +101,7 @@ export class RelationshipEffects {
|
|||||||
} else {
|
} else {
|
||||||
this.relationshipService.updateNameVariant(item1, item2, relationshipType, nameVariant).pipe(take(1))
|
this.relationshipService.updateNameVariant(item1, item2, relationshipType, nameVariant).pipe(take(1))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
updateAfterPatchSubmissionId = submissionId;
|
this.updateAfterPatchSubmissionId = submissionId;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,21 +111,9 @@ export class RelationshipEffects {
|
|||||||
@Effect() commitServerSyncBuffer = this.actions$
|
@Effect() commitServerSyncBuffer = this.actions$
|
||||||
.pipe(
|
.pipe(
|
||||||
ofType(ServerSyncBufferActionTypes.EMPTY),
|
ofType(ServerSyncBufferActionTypes.EMPTY),
|
||||||
filter(() => hasValue(updateAfterPatchSubmissionId)),
|
filter(() => hasValue(this.updateAfterPatchSubmissionId)),
|
||||||
switchMap(() => this.submissionObjectService.getHrefByID(updateAfterPatchSubmissionId).pipe(take(1))),
|
switchMap(() => this.refreshWorkspaceItemInCache(this.updateAfterPatchSubmissionId)),
|
||||||
switchMap((href: string) => {
|
map((submissionObject) => new SaveSubmissionSectionFormSuccessAction(this.updateAfterPatchSubmissionId, [submissionObject], false))
|
||||||
this.objectCache.remove(href);
|
|
||||||
this.requestService.removeByHrefSubstring(updateAfterPatchSubmissionId);
|
|
||||||
return combineLatest(
|
|
||||||
this.objectCache.hasBySelfLinkObservable(href),
|
|
||||||
this.requestService.hasByHrefObservable(href)
|
|
||||||
).pipe(
|
|
||||||
filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC),
|
|
||||||
take(1),
|
|
||||||
switchMap(() => this.submissionObjectService.findById(updateAfterPatchSubmissionId).pipe(getSucceededRemoteData(), getRemoteDataPayload()) as Observable<SubmissionObject>)
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
map((submissionObject) => new SaveSubmissionSectionFormSuccessAction(updateAfterPatchSubmissionId, [submissionObject], false))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
constructor(private actions$: Actions,
|
constructor(private actions$: Actions,
|
||||||
@@ -155,7 +145,7 @@ export class RelationshipEffects {
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
take(1),
|
take(1),
|
||||||
refreshWorkspaceItemInCache(submissionId, this.submissionObjectService, this.objectCache, this.requestService)
|
switchMap(() => this.refreshWorkspaceItemInCache(submissionId)),
|
||||||
).subscribe((submissionObject: SubmissionObject) => this.store.dispatch(new SaveSubmissionSectionFormSuccessAction(submissionId, [submissionObject], false)));
|
).subscribe((submissionObject: SubmissionObject) => this.store.dispatch(new SaveSubmissionSectionFormSuccessAction(submissionId, [submissionObject], false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,25 +155,24 @@ export class RelationshipEffects {
|
|||||||
hasValueOperator(),
|
hasValueOperator(),
|
||||||
mergeMap((relationship: Relationship) => this.relationshipService.deleteRelationship(relationship.id)),
|
mergeMap((relationship: Relationship) => this.relationshipService.deleteRelationship(relationship.id)),
|
||||||
take(1),
|
take(1),
|
||||||
refreshWorkspaceItemInCache(submissionId, this.submissionObjectService, this.objectCache, this.requestService)
|
switchMap(() => this.refreshWorkspaceItemInCache(submissionId)),
|
||||||
).subscribe((submissionObject: SubmissionObject) => this.store.dispatch(new SaveSubmissionSectionFormSuccessAction(submissionId, [submissionObject], false)));
|
).subscribe((submissionObject: SubmissionObject) => this.store.dispatch(new SaveSubmissionSectionFormSuccessAction(submissionId, [submissionObject], false)));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const refreshWorkspaceItemInCache = (submissionId, submissionObjectService, objectCache, requestService) =>
|
refreshWorkspaceItemInCache(submissionId: string): Observable<SubmissionObject> {
|
||||||
<T>(source: Observable<T>): Observable<SubmissionObject> =>
|
return this.submissionObjectService.getHrefByID(submissionId).pipe(take(1)).pipe(
|
||||||
source.pipe(
|
|
||||||
switchMap(() => submissionObjectService.getHrefByID(submissionId).pipe(take(1))),
|
|
||||||
switchMap((href: string) => {
|
switchMap((href: string) => {
|
||||||
objectCache.remove(href);
|
this.objectCache.remove(href);
|
||||||
requestService.removeByHrefSubstring(submissionId);
|
this.requestService.removeByHrefSubstring(submissionId);
|
||||||
return combineLatest(
|
return combineLatest(
|
||||||
objectCache.hasBySelfLinkObservable(href),
|
this.objectCache.hasBySelfLinkObservable(href),
|
||||||
requestService.hasByHrefObservable(href)
|
this.requestService.hasByHrefObservable(href)
|
||||||
).pipe(
|
).pipe(
|
||||||
filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC),
|
filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC),
|
||||||
take(1),
|
take(1),
|
||||||
switchMap(() => submissionObjectService.findById(submissionId).pipe(getSucceededRemoteData(), getRemoteDataPayload()) as Observable<SubmissionObject>)
|
switchMap(() => this.submissionObjectService.findById(submissionId).pipe(getSucceededRemoteData(), getRemoteDataPayload()) as Observable<SubmissionObject>)
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
));
|
}
|
||||||
|
@@ -155,7 +155,6 @@ describe('ClaimedTaskActionsComponent', () => {
|
|||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
expect(mockDataService.approveTask).toHaveBeenCalledWith(mockObject.id);
|
expect(mockDataService.approveTask).toHaveBeenCalledWith(mockObject.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should display a success notification on approve success', async(() => {
|
it('should display a success notification on approve success', async(() => {
|
||||||
|
@@ -318,7 +318,6 @@ describe('SubmissionSectionformComponent test suite', () => {
|
|||||||
expect(comp.isUpdating).toBeFalsy();
|
expect(comp.isUpdating).toBeFalsy();
|
||||||
expect(comp.initForm).toHaveBeenCalled();
|
expect(comp.initForm).toHaveBeenCalled();
|
||||||
expect(comp.checksForErrors).toHaveBeenCalled();
|
expect(comp.checksForErrors).toHaveBeenCalled();
|
||||||
expect(notificationsServiceStub.info).toHaveBeenCalled();
|
|
||||||
expect(comp.sectionData.data).toEqual(sectionData);
|
expect(comp.sectionData.data).toEqual(sectionData);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -367,7 +367,6 @@ describe('SectionsService test suite', () => {
|
|||||||
scheduler.schedule(() => service.updateSectionData(submissionId, sectionId, data, []));
|
scheduler.schedule(() => service.updateSectionData(submissionId, sectionId, data, []));
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
|
|
||||||
expect(notificationsServiceStub.info).toHaveBeenCalled();
|
|
||||||
expect(store.dispatch).toHaveBeenCalledWith(new UpdateSectionDataAction(submissionId, sectionId, data, []));
|
expect(store.dispatch).toHaveBeenCalledWith(new UpdateSectionDataAction(submissionId, sectionId, data, []));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user