From 993ce1ab16004c14621acea93acaac7865add34a Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 27 Mar 2024 13:27:44 +0100 Subject: [PATCH 1/4] 113500: Fix for warning on first describe step --- .../sections/form/section-form.component.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/app/submission/sections/form/section-form.component.ts b/src/app/submission/sections/form/section-form.component.ts index 2a07f7e3f1..477a263edd 100644 --- a/src/app/submission/sections/form/section-form.component.ts +++ b/src/app/submission/sections/form/section-form.component.ts @@ -192,7 +192,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { this.submissionObject = submissionObject; this.isSectionReadonly = isSectionReadOnly; // Is the first loading so init form - this.initForm(sectionData); + this.initForm(sectionData, this.sectionData.errorsToShow, this.sectionData.serverValidationErrors); this.sectionData.data = sectionData; this.subscriptions(); this.isLoading = false; @@ -296,7 +296,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { * @param sectionData * the section data retrieved from the server */ - initForm(sectionData: WorkspaceitemSectionFormObject): void { + initForm(sectionData: WorkspaceitemSectionFormObject, errorsToShow: SubmissionSectionError[], serverValidationErrors: SubmissionSectionError[]): void { try { this.formModel = this.formBuilderService.modelFromConfiguration( this.submissionId, @@ -307,7 +307,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { this.isSectionReadonly ); const sectionMetadata = this.sectionService.computeSectionConfiguredMetadata(this.formConfig); - this.sectionService.updateSectionData(this.submissionId, this.sectionData.id, sectionData, this.sectionData.errorsToShow, this.sectionData.serverValidationErrors, sectionMetadata); + this.sectionService.updateSectionData(this.submissionId, this.sectionData.id, sectionData, errorsToShow, serverValidationErrors, sectionMetadata); } catch (e) { const msg: string = this.translate.instant('error.submission.sections.init-form-error') + e.toString(); const sectionError: SubmissionSectionError = { @@ -327,7 +327,10 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { * @param errors * the section errors retrieved from the server */ - updateForm(sectionData: WorkspaceitemSectionFormObject, errors: SubmissionSectionError[]): void { + updateForm(sectionState: SubmissionSectionObject): void { + + const sectionData = sectionState.data as WorkspaceitemSectionFormObject; + const errors = sectionState.errorsToShow if (isNotEmpty(sectionData) && !isEqual(sectionData, this.sectionData.data)) { this.sectionData.data = sectionData; @@ -335,7 +338,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { this.isUpdating = true; this.formModel = null; this.cdr.detectChanges(); - this.initForm(sectionData); + this.initForm(sectionData, errors, sectionState.serverValidationErrors); this.checksForErrors(errors); this.isUpdating = false; this.cdr.detectChanges(); @@ -389,7 +392,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { .subscribe((sectionState: SubmissionSectionObject) => { this.fieldsOnTheirWayToBeRemoved = new Map(); this.sectionMetadata = sectionState.metadata; - this.updateForm(sectionState.data as WorkspaceitemSectionFormObject, sectionState.errorsToShow); + this.updateForm(sectionState); }) ); } From 4e0046022ba8921a71a1ed9b59059a1e3c1ac1d8 Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 27 Mar 2024 14:07:55 +0100 Subject: [PATCH 2/4] 113500: Fixed tests after bugfix --- .../form/section-form.component.spec.ts | 23 +++++++++++-------- .../sections/form/section-form.component.ts | 6 ++--- 2 files changed, 16 insertions(+), 13 deletions(-) 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 4fbf324edf..bce665b444 100644 --- a/src/app/submission/sections/form/section-form.component.spec.ts +++ b/src/app/submission/sections/form/section-form.component.spec.ts @@ -261,7 +261,7 @@ describe('SubmissionSectionFormComponent test suite', () => { expect(comp.sectionData.errorsToShow).toEqual([]); expect(comp.sectionData.data).toEqual(sectionData); expect(comp.isLoading).toBeFalsy(); - expect(comp.initForm).toHaveBeenCalledWith(sectionData); + expect(comp.initForm).toHaveBeenCalledWith(sectionData, [], []); expect(comp.subscriptions).toHaveBeenCalled(); }); @@ -269,7 +269,7 @@ describe('SubmissionSectionFormComponent test suite', () => { formBuilderService.modelFromConfiguration.and.returnValue(testFormModel); const sectionData = {}; - comp.initForm(sectionData); + comp.initForm(sectionData, [], []); expect(comp.formModel).toEqual(testFormModel); @@ -284,7 +284,7 @@ describe('SubmissionSectionFormComponent test suite', () => { path: '/sections/' + sectionObject.id }; - comp.initForm(sectionData); + comp.initForm(sectionData, [], []); expect(comp.formModel).toBeUndefined(); expect(sectionsServiceStub.setSectionError).toHaveBeenCalledWith(submissionId, sectionObject.id, sectionError); @@ -443,7 +443,7 @@ describe('SubmissionSectionFormComponent test suite', () => { compAsAny.formData = {}; compAsAny.sectionMetadata = ['dc.title']; - comp.updateForm(sectionData, sectionError); + comp.updateForm({data: sectionData, errorsToShow: sectionError} as any); expect(comp.isUpdating).toBeFalsy(); expect(comp.initForm).toHaveBeenCalled(); @@ -455,15 +455,19 @@ describe('SubmissionSectionFormComponent test suite', () => { it('should update form error properly', () => { spyOn(comp, 'initForm'); spyOn(comp, 'checksForErrors'); - const sectionData: any = { + const sectionData = { 'dc.title': [new FormFieldMetadataValueObject('test')] }; + const sectionState = { + data: sectionData, + errorsToShow: [{path: '/test', message: 'test'}], + } as any; comp.sectionData.data = {}; comp.sectionData.errorsToShow = []; compAsAny.formData = sectionData; compAsAny.sectionMetadata = ['dc.title']; - comp.updateForm(sectionData, parsedSectionErrors); + comp.updateForm(sectionState); expect(comp.initForm).not.toHaveBeenCalled(); expect(comp.checksForErrors).toHaveBeenCalled(); @@ -474,8 +478,9 @@ describe('SubmissionSectionFormComponent test suite', () => { spyOn(comp, 'initForm'); spyOn(comp, 'checksForErrors'); const sectionData: any = {}; + const sectionErrors: any = [{ path: '/test', message: 'test'}]; - comp.updateForm(sectionData, parsedSectionErrors); + comp.updateForm({data: sectionData, errorsToShow: sectionErrors} as any); expect(comp.initForm).not.toHaveBeenCalled(); expect(comp.checksForErrors).toHaveBeenCalled(); @@ -541,7 +546,7 @@ describe('SubmissionSectionFormComponent test suite', () => { const sectionState = { data: sectionData, errorsToShow: parsedSectionErrors - }; + } as any; formService.getFormData.and.returnValue(observableOf(formData)); sectionsServiceStub.getSectionState.and.returnValue(observableOf(sectionState)); @@ -550,7 +555,7 @@ describe('SubmissionSectionFormComponent test suite', () => { expect(compAsAny.subs.length).toBe(2); expect(compAsAny.formData).toEqual(formData); - expect(comp.updateForm).toHaveBeenCalledWith(sectionState.data, sectionState.errorsToShow); + expect(comp.updateForm).toHaveBeenCalledWith(sectionState); }); diff --git a/src/app/submission/sections/form/section-form.component.ts b/src/app/submission/sections/form/section-form.component.ts index 477a263edd..8e12f81097 100644 --- a/src/app/submission/sections/form/section-form.component.ts +++ b/src/app/submission/sections/form/section-form.component.ts @@ -322,10 +322,8 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { /** * Update form model * - * @param sectionData - * the section data retrieved from the server - * @param errors - * the section errors retrieved from the server + * @param sectionState + * the section state retrieved from the server */ updateForm(sectionState: SubmissionSectionObject): void { From 722bd6f7f5e2b7240b6d038d83342c1c15ebae57 Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 27 Mar 2024 14:15:20 +0100 Subject: [PATCH 3/4] 113500: Fixed lint error --- src/app/submission/sections/form/section-form.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/submission/sections/form/section-form.component.ts b/src/app/submission/sections/form/section-form.component.ts index 8e12f81097..4cbb97fd1f 100644 --- a/src/app/submission/sections/form/section-form.component.ts +++ b/src/app/submission/sections/form/section-form.component.ts @@ -328,7 +328,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { updateForm(sectionState: SubmissionSectionObject): void { const sectionData = sectionState.data as WorkspaceitemSectionFormObject; - const errors = sectionState.errorsToShow + const errors = sectionState.errorsToShow; if (isNotEmpty(sectionData) && !isEqual(sectionData, this.sectionData.data)) { this.sectionData.data = sectionData; From 903af2ccdb065eb24a638904f295a0d66a4b05a7 Mon Sep 17 00:00:00 2001 From: lotte Date: Mon, 8 Apr 2024 10:40:45 +0200 Subject: [PATCH 4/4] 113500: Fixed lint issues --- .../sections/form/section-form.component.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 1b96348a69..efd410713f 100644 --- a/src/app/submission/sections/form/section-form.component.spec.ts +++ b/src/app/submission/sections/form/section-form.component.spec.ts @@ -464,7 +464,7 @@ describe('SubmissionSectionFormComponent test suite', () => { compAsAny.formData = {}; compAsAny.sectionMetadata = ['dc.title']; - comp.updateForm({data: sectionData, errorsToShow: sectionError} as any); + comp.updateForm({ data: sectionData, errorsToShow: sectionError } as any); expect(comp.isUpdating).toBeFalsy(); expect(comp.initForm).toHaveBeenCalled(); @@ -481,7 +481,7 @@ describe('SubmissionSectionFormComponent test suite', () => { }; const sectionState = { data: sectionData, - errorsToShow: [{path: '/test', message: 'test'}], + errorsToShow: [{ path: '/test', message: 'test' }], } as any; comp.sectionData.data = {}; comp.sectionData.errorsToShow = []; @@ -499,9 +499,9 @@ describe('SubmissionSectionFormComponent test suite', () => { spyOn(comp, 'initForm'); spyOn(comp, 'checksForErrors'); const sectionData: any = {}; - const sectionErrors: any = [{ path: '/test', message: 'test'}]; + const sectionErrors: any = [{ path: '/test', message: 'test' }]; - comp.updateForm({data: sectionData, errorsToShow: sectionErrors} as any); + comp.updateForm({ data: sectionData, errorsToShow: sectionErrors } as any); expect(comp.initForm).not.toHaveBeenCalled(); expect(comp.checksForErrors).toHaveBeenCalled();