From 0acaa3e57fb7bbdb0f634be8fbc9983ab338b575 Mon Sep 17 00:00:00 2001 From: Alessandro Martelli Date: Mon, 23 Nov 2020 12:58:16 +0100 Subject: [PATCH] [835] Auto-save in new Item Submission form breaks the form Section metadata dispatched to the store and retrieved in subscription. Added test case for hasMetadataEnrichment. --- .../sections/form/section-form.component.spec.ts | 9 +++++++++ .../submission/sections/form/section-form.component.ts | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/app/submission/sections/form/section-form.component.spec.ts b/src/app/submission/sections/form/section-form.component.spec.ts index 7a62628d02..d649f985ca 100644 --- a/src/app/submission/sections/form/section-form.component.spec.ts +++ b/src/app/submission/sections/form/section-form.component.spec.ts @@ -301,6 +301,15 @@ describe('SubmissionSectionformComponent test suite', () => { expect(comp.hasMetadataEnrichment(newSectionData)).toBeFalsy(); }); + it('should return false when metadata has Metadata Enrichment but not belonging to sectionMetadata', () => { + const newSectionData = { + 'dc.title': [new FormFieldMetadataValueObject('test')] + }; + compAsAny.formData = newSectionData; + compAsAny.sectionMetadata = []; + expect(comp.hasMetadataEnrichment(newSectionData)).toBeFalsy(); + }); + it('should update form properly', () => { spyOn(comp, 'initForm'); spyOn(comp, 'checksForErrors'); diff --git a/src/app/submission/sections/form/section-form.component.ts b/src/app/submission/sections/form/section-form.component.ts index c5d9999da5..02907df16a 100644 --- a/src/app/submission/sections/form/section-form.component.ts +++ b/src/app/submission/sections/form/section-form.component.ts @@ -283,7 +283,8 @@ export class SubmissionSectionformComponent extends SectionModelComponent { sectionData, this.submissionService.getSubmissionScope() ); - this.sectionMetadata = this.sectionService.computeSectionConfiguredMetadata(this.formConfig); + const sectionMetadata = this.sectionService.computeSectionConfiguredMetadata(this.formConfig); + this.sectionService.updateSectionData(this.submissionId, this.sectionData.id, sectionData, [], sectionMetadata); } catch (e) { const msg: string = this.translate.instant('error.submission.sections.init-form-error') + e.toString(); @@ -365,6 +366,7 @@ export class SubmissionSectionformComponent extends SectionModelComponent { distinctUntilChanged()) .subscribe((sectionState: SubmissionSectionObject) => { this.fieldsOnTheirWayToBeRemoved = new Map(); + this.sectionMetadata = sectionState.metadata; this.updateForm(sectionState.data as WorkspaceitemSectionFormObject, sectionState.errors); }) )