mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-11 12:03:03 +00:00
[835] Auto-save in new Item Submission form breaks the form
Notifications are disabled for submission section savings.
This commit is contained in:
@@ -57,9 +57,9 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
let actions: Observable<any>;
|
||||
let store: StoreMock<AppState>;
|
||||
|
||||
const notificationsServiceStub = new NotificationsServiceStub();
|
||||
const submissionServiceStub = new SubmissionServiceStub();
|
||||
const submissionJsonPatchOperationsServiceStub = new SubmissionJsonPatchOperationsServiceStub();
|
||||
let notificationsServiceStub;
|
||||
let submissionServiceStub;
|
||||
let submissionJsonPatchOperationsServiceStub;
|
||||
const collectionId: string = mockSubmissionCollectionId;
|
||||
const submissionId: string = mockSubmissionId;
|
||||
const submissionDefinitionResponse: any = mockSubmissionDefinitionResponse;
|
||||
@@ -68,6 +68,11 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
const submissionState: any = Object.assign({}, mockSubmissionState);
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
notificationsServiceStub = new NotificationsServiceStub();
|
||||
submissionServiceStub = new SubmissionServiceStub();
|
||||
submissionJsonPatchOperationsServiceStub = new SubmissionJsonPatchOperationsServiceStub();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
StoreModule.forRoot({}, storeModuleConfig),
|
||||
@@ -471,6 +476,202 @@ describe('SubmissionObjectEffects test suite', () => {
|
||||
|
||||
});
|
||||
|
||||
describe('saveSubmissionSectionSuccess$', () => {
|
||||
|
||||
it('should return a UPDATE_SECTION_DATA action for each updated section', () => {
|
||||
store.nextState({
|
||||
submission: {
|
||||
objects: submissionState
|
||||
}
|
||||
} as any);
|
||||
|
||||
const response = [Object.assign({}, mockSubmissionRestResponse[0], {
|
||||
sections: mockSectionsData,
|
||||
errors: mockSectionsErrors
|
||||
})];
|
||||
actions = hot('--a-', {
|
||||
a: {
|
||||
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS,
|
||||
payload: {
|
||||
submissionId: submissionId,
|
||||
submissionObject: response
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const errorsList = parseSectionErrors(mockSectionsErrors);
|
||||
const expected = cold('--(bcd)-', {
|
||||
b: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'traditionalpageone',
|
||||
mockSectionsData.traditionalpageone as any,
|
||||
errorsList.traditionalpageone || []
|
||||
),
|
||||
c: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'license',
|
||||
mockSectionsData.license as any,
|
||||
errorsList.license || []
|
||||
),
|
||||
d: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'upload',
|
||||
mockSectionsData.upload as any,
|
||||
errorsList.upload || []
|
||||
),
|
||||
});
|
||||
|
||||
expect(submissionObjectEffects.saveSubmissionSectionSuccess$).toBeObservable(expected);
|
||||
|
||||
});
|
||||
|
||||
it('should not display a success notification', () => {
|
||||
store.nextState({
|
||||
submission: {
|
||||
objects: submissionState
|
||||
}
|
||||
} as any);
|
||||
|
||||
const response = [Object.assign({}, mockSubmissionRestResponse[0], {
|
||||
sections: mockSectionsData
|
||||
})];
|
||||
actions = hot('--a-', {
|
||||
a: {
|
||||
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS,
|
||||
payload: {
|
||||
submissionId: submissionId,
|
||||
submissionObject: response
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const expected = cold('--(bcd)-', {
|
||||
b: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'traditionalpageone',
|
||||
mockSectionsData.traditionalpageone as any,
|
||||
[]
|
||||
),
|
||||
c: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'license',
|
||||
mockSectionsData.license as any,
|
||||
[]
|
||||
),
|
||||
d: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'upload',
|
||||
mockSectionsData.upload as any,
|
||||
[]
|
||||
),
|
||||
});
|
||||
|
||||
expect(submissionObjectEffects.saveSubmissionSectionSuccess$).toBeObservable(expected);
|
||||
expect(notificationsServiceStub.success).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not display a warning notification when there are errors', () => {
|
||||
store.nextState({
|
||||
submission: {
|
||||
objects: submissionState
|
||||
}
|
||||
} as any);
|
||||
|
||||
const response = [Object.assign({}, mockSubmissionRestResponse[0], {
|
||||
sections: mockSectionsData,
|
||||
errors: mockSectionsErrors
|
||||
})];
|
||||
actions = hot('--a-', {
|
||||
a: {
|
||||
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS,
|
||||
payload: {
|
||||
submissionId: submissionId,
|
||||
submissionObject: response
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const errorsList = parseSectionErrors(mockSectionsErrors);
|
||||
const expected = cold('--(bcd)-', {
|
||||
b: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'traditionalpageone',
|
||||
mockSectionsData.traditionalpageone as any,
|
||||
errorsList.traditionalpageone || []
|
||||
),
|
||||
c: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'license',
|
||||
mockSectionsData.license as any,
|
||||
errorsList.license || []
|
||||
),
|
||||
d: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'upload',
|
||||
mockSectionsData.upload as any,
|
||||
errorsList.upload || []
|
||||
),
|
||||
});
|
||||
|
||||
expect(submissionObjectEffects.saveSubmissionSectionSuccess$).toBeObservable(expected);
|
||||
expect(notificationsServiceStub.warning).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should detect new sections but not notify for it', () => {
|
||||
store.nextState({
|
||||
submission: {
|
||||
objects: submissionState
|
||||
}
|
||||
} as any);
|
||||
|
||||
const response = [Object.assign({}, mockSubmissionRestResponse[0], {
|
||||
sections: mockSectionsDataTwo,
|
||||
errors: mockSectionsErrors
|
||||
})];
|
||||
actions = hot('--a-', {
|
||||
a: {
|
||||
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS,
|
||||
payload: {
|
||||
submissionId: submissionId,
|
||||
submissionObject: response
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const errorsList = parseSectionErrors(mockSectionsErrors);
|
||||
const expected = cold('--(bcde)-', {
|
||||
b: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'traditionalpageone',
|
||||
mockSectionsDataTwo.traditionalpageone as any,
|
||||
errorsList.traditionalpageone || []
|
||||
),
|
||||
c: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'traditionalpagetwo',
|
||||
mockSectionsDataTwo.traditionalpagetwo as any,
|
||||
errorsList.traditionalpagetwo || []
|
||||
),
|
||||
d: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'license',
|
||||
mockSectionsDataTwo.license as any,
|
||||
errorsList.license || []
|
||||
),
|
||||
e: new UpdateSectionDataAction(
|
||||
submissionId,
|
||||
'upload',
|
||||
mockSectionsDataTwo.upload as any,
|
||||
errorsList.upload || []
|
||||
),
|
||||
});
|
||||
|
||||
expect(submissionObjectEffects.saveSubmissionSectionSuccess$).toBeObservable(expected);
|
||||
expect(submissionServiceStub.notifyNewSection).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('saveSection$', () => {
|
||||
it('should return a SAVE_SUBMISSION_SECTION_FORM_SUCCESS action on success', () => {
|
||||
actions = hot('--a-', {
|
||||
|
@@ -154,13 +154,25 @@ export class SubmissionObjectEffects {
|
||||
* Call parseSaveResponse and dispatch actions
|
||||
*/
|
||||
@Effect() saveSubmissionSuccess$ = this.actions$.pipe(
|
||||
ofType(SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM_SUCCESS, SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS),
|
||||
ofType(SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM_SUCCESS),
|
||||
withLatestFrom(this.store$),
|
||||
map(([action, currentState]: [SaveSubmissionFormSuccessAction | SaveSubmissionSectionFormSuccessAction, any]) => {
|
||||
map(([action, currentState]: [SaveSubmissionFormSuccessAction, any]) => {
|
||||
return this.parseSaveResponse((currentState.submission as SubmissionState).objects[action.payload.submissionId], action.payload.submissionObject, action.payload.submissionId, action.payload.notify);
|
||||
}),
|
||||
mergeMap((actions) => observableFrom(actions)));
|
||||
|
||||
/**
|
||||
* Call parseSaveResponse and dispatch actions.
|
||||
* Notification system is forced to be disabled.
|
||||
*/
|
||||
@Effect() saveSubmissionSectionSuccess$ = this.actions$.pipe(
|
||||
ofType(SubmissionObjectActionTypes.SAVE_SUBMISSION_SECTION_FORM_SUCCESS),
|
||||
withLatestFrom(this.store$),
|
||||
map(([action, currentState]: [SaveSubmissionSectionFormSuccessAction, any]) => {
|
||||
return this.parseSaveResponse((currentState.submission as SubmissionState).objects[action.payload.submissionId], action.payload.submissionObject, action.payload.submissionId, false);
|
||||
}),
|
||||
mergeMap((actions) => observableFrom(actions)));
|
||||
|
||||
/**
|
||||
* Dispatch a [SaveSubmissionSectionFormSuccessAction] or a [SaveSubmissionSectionFormErrorAction] on error
|
||||
*/
|
||||
|
Reference in New Issue
Block a user