mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[835] Auto-save in new Item Submission form breaks the form
Notifications are enable only for manual submission savings.
This commit is contained in:
@@ -9,6 +9,7 @@ export class SubmissionServiceStub {
|
|||||||
dispatchDeposit = jasmine.createSpy('dispatchDeposit');
|
dispatchDeposit = jasmine.createSpy('dispatchDeposit');
|
||||||
dispatchDiscard = jasmine.createSpy('dispatchDiscard');
|
dispatchDiscard = jasmine.createSpy('dispatchDiscard');
|
||||||
dispatchSave = jasmine.createSpy('dispatchSave');
|
dispatchSave = jasmine.createSpy('dispatchSave');
|
||||||
|
dispatchManualSave = jasmine.createSpy('dispatchManualSave');
|
||||||
dispatchSaveForLater = jasmine.createSpy('dispatchSaveForLater');
|
dispatchSaveForLater = jasmine.createSpy('dispatchSaveForLater');
|
||||||
dispatchSaveSection = jasmine.createSpy('dispatchSaveSection');
|
dispatchSaveSection = jasmine.createSpy('dispatchSaveSection');
|
||||||
getActiveSectionId = jasmine.createSpy('getActiveSectionId');
|
getActiveSectionId = jasmine.createSpy('getActiveSectionId');
|
||||||
|
@@ -164,12 +164,12 @@ describe('SubmissionFormFooterComponent Component', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call dispatchSave on save', () => {
|
it('should call dispatchManualSave on save', () => {
|
||||||
|
|
||||||
comp.save(null);
|
comp.save(null);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(submissionServiceStub.dispatchSave).toHaveBeenCalledWith(submissionId);
|
expect(submissionServiceStub.dispatchManualSave).toHaveBeenCalledWith(submissionId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call dispatchSaveForLater on save for later', () => {
|
it('should call dispatchSaveForLater on save for later', () => {
|
||||||
|
@@ -80,7 +80,7 @@ export class SubmissionFormFooterComponent implements OnChanges {
|
|||||||
* Dispatch a submission save action
|
* Dispatch a submission save action
|
||||||
*/
|
*/
|
||||||
save(event) {
|
save(event) {
|
||||||
this.submissionService.dispatchSave(this.submissionId);
|
this.submissionService.dispatchManualSave(this.submissionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -368,6 +368,7 @@ export class SaveSubmissionFormAction implements Action {
|
|||||||
type = SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM;
|
type = SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM;
|
||||||
payload: {
|
payload: {
|
||||||
submissionId: string;
|
submissionId: string;
|
||||||
|
isManual?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -376,8 +377,8 @@ export class SaveSubmissionFormAction implements Action {
|
|||||||
* @param submissionId
|
* @param submissionId
|
||||||
* the submission's ID
|
* the submission's ID
|
||||||
*/
|
*/
|
||||||
constructor(submissionId: string) {
|
constructor(submissionId: string, isManual: boolean = false) {
|
||||||
this.payload = { submissionId };
|
this.payload = { submissionId, isManual };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -211,6 +211,52 @@ describe('SubmissionObjectEffects test suite', () => {
|
|||||||
expect(submissionObjectEffects.saveSubmission$).toBeObservable(expected);
|
expect(submissionObjectEffects.saveSubmission$).toBeObservable(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should enable notifications if is manual', () => {
|
||||||
|
actions = hot('--a-', {
|
||||||
|
a: {
|
||||||
|
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM,
|
||||||
|
payload: {
|
||||||
|
submissionId: submissionId,
|
||||||
|
isManual: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
submissionJsonPatchOperationsServiceStub.jsonPatchByResourceType.and.returnValue(observableOf(mockSubmissionRestResponse));
|
||||||
|
const expected = cold('--b-', {
|
||||||
|
b: new SaveSubmissionFormSuccessAction(
|
||||||
|
submissionId,
|
||||||
|
mockSubmissionRestResponse as any,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(submissionObjectEffects.saveSubmission$).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should disable notifications if is not manual', () => {
|
||||||
|
actions = hot('--a-', {
|
||||||
|
a: {
|
||||||
|
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM,
|
||||||
|
payload: {
|
||||||
|
submissionId: submissionId,
|
||||||
|
isManual: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
submissionJsonPatchOperationsServiceStub.jsonPatchByResourceType.and.returnValue(observableOf(mockSubmissionRestResponse));
|
||||||
|
const expected = cold('--b-', {
|
||||||
|
b: new SaveSubmissionFormSuccessAction(
|
||||||
|
submissionId,
|
||||||
|
mockSubmissionRestResponse as any,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(submissionObjectEffects.saveSubmission$).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return a SAVE_SUBMISSION_FORM_ERROR action on error', () => {
|
it('should return a SAVE_SUBMISSION_FORM_ERROR action on error', () => {
|
||||||
actions = hot('--a-', {
|
actions = hot('--a-', {
|
||||||
a: {
|
a: {
|
||||||
|
@@ -132,7 +132,7 @@ export class SubmissionObjectEffects {
|
|||||||
this.submissionService.getSubmissionObjectLinkName(),
|
this.submissionService.getSubmissionObjectLinkName(),
|
||||||
action.payload.submissionId,
|
action.payload.submissionId,
|
||||||
'sections').pipe(
|
'sections').pipe(
|
||||||
map((response: SubmissionObject[]) => new SaveSubmissionFormSuccessAction(action.payload.submissionId, response)),
|
map((response: SubmissionObject[]) => new SaveSubmissionFormSuccessAction(action.payload.submissionId, response, action.payload.isManual)),
|
||||||
catchError(() => observableOf(new SaveSubmissionFormErrorAction(action.payload.submissionId))));
|
catchError(() => observableOf(new SaveSubmissionFormErrorAction(action.payload.submissionId))));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@@ -494,6 +494,15 @@ describe('SubmissionService test suite', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('dispatchManualSave', () => {
|
||||||
|
it('should dispatch a new SaveSubmissionFormAction', () => {
|
||||||
|
service.dispatchManualSave(submissionId,);
|
||||||
|
const expected = new SaveSubmissionFormAction(submissionId, true);
|
||||||
|
|
||||||
|
expect((service as any).store.dispatch).toHaveBeenCalledWith(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('dispatchSaveForLater', () => {
|
describe('dispatchSaveForLater', () => {
|
||||||
it('should dispatch a new SaveForLaterSubmissionFormAction', () => {
|
it('should dispatch a new SaveForLaterSubmissionFormAction', () => {
|
||||||
service.dispatchSaveForLater(submissionId,);
|
service.dispatchSaveForLater(submissionId,);
|
||||||
|
@@ -204,6 +204,20 @@ export class SubmissionService {
|
|||||||
this.store.dispatch(new DiscardSubmissionAction(submissionId));
|
this.store.dispatch(new DiscardSubmissionAction(submissionId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch a new [SaveSubmissionFormAction]
|
||||||
|
*
|
||||||
|
* @param submissionId
|
||||||
|
* The submission id
|
||||||
|
*/
|
||||||
|
dispatchManualSave(submissionId) {
|
||||||
|
this.getSubmissionSaveProcessingStatus(submissionId).pipe(
|
||||||
|
find((isPending: boolean) => !isPending)
|
||||||
|
).subscribe(() => {
|
||||||
|
this.store.dispatch(new SaveSubmissionFormAction(submissionId, true));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch a new [SaveSubmissionFormAction]
|
* Dispatch a new [SaveSubmissionFormAction]
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user