From d8b6e868964dd6e4e16cfbfa5445f1052314f03d Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 27 Mar 2024 14:07:55 +0100 Subject: [PATCH] 113500: Fixed tests after bugfix (cherry picked from commit 4e0046022ba8921a71a1ed9b59059a1e3c1ac1d8) --- .../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 {