Skip to content

Commit 85e773f

Browse files
[DSC-2010] fix and improve tests om submission sections
1 parent 539b1f5 commit 85e773f

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/app/submission/objects/submission-objects.effects.spec.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,67 @@ describe('SubmissionObjectEffects test suite', () => {
734734
// expect(notificationsServiceStub.success).toHaveBeenCalled();
735735
});
736736

737+
it('should handle sections without errorsToShow property gracefully', () => {
738+
const stateWithMissingErrorsToShow = {
739+
826: {
740+
...submissionState['826'],
741+
sections: {
742+
...submissionState['826'].sections,
743+
'sectionWithoutErrors': {
744+
sectionType: 'custom',
745+
enabled: true,
746+
data: {},
747+
} as any,
748+
},
749+
},
750+
};
751+
752+
store.nextState({
753+
submission: {
754+
objects: stateWithMissingErrorsToShow,
755+
},
756+
} as any);
757+
758+
const response = [Object.assign({}, mockSubmissionRestResponse[0], {
759+
sections: mockSectionsData,
760+
})];
761+
actions = hot('--a-', {
762+
a: {
763+
type: SubmissionObjectActionTypes.SAVE_SUBMISSION_FORM_SUCCESS,
764+
payload: {
765+
submissionId: submissionId,
766+
submissionObject: response,
767+
},
768+
},
769+
});
770+
771+
const expected = cold('--(bcd)-', {
772+
b: new UpdateSectionDataAction(
773+
submissionId,
774+
'traditionalpageone',
775+
mockSectionsData.traditionalpageone as any,
776+
[],
777+
[],
778+
),
779+
c: new UpdateSectionDataAction(
780+
submissionId,
781+
'license',
782+
mockSectionsData.license as any,
783+
[],
784+
[],
785+
),
786+
d: new UpdateSectionDataAction(
787+
submissionId,
788+
'upload',
789+
mockSectionsData.upload as any,
790+
[],
791+
[],
792+
),
793+
});
794+
795+
expect(submissionObjectEffects.saveSubmissionSuccess$).toBeObservable(expected);
796+
});
797+
737798
});
738799

739800
describe('saveSubmissionSectionSuccess$', () => {

src/app/submission/objects/submission-objects.effects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ export class SubmissionObjectEffects {
540540
}
541541

542542
const sections: WorkspaceitemSectionsObject = (item.sections && isNotEmpty(item.sections)) ? item.sections : {};
543-
const sectionsKeys = union(Object.keys(sections), Object.keys(currentState.sections).filter(key => currentState.sections[key].errorsToShow.length > 0), Object.keys(errorsList));
543+
const sectionsKeys = union(Object.keys(sections), Object.keys(currentState.sections).filter(key => currentState.sections[key].errorsToShow?.length > 0), Object.keys(errorsList));
544544

545545
for (const sectionId of sectionsKeys) {
546546
const sectionErrors = errorsList[sectionId] || [];

0 commit comments

Comments
 (0)