Merge pull request #2905 from atmire/w2p-113500_submission-describe-warning_contribution

Fix for submission describe warning contribution bug
This commit is contained in:
Tim Donohue
2024-04-12 12:20:33 -05:00
committed by GitHub
2 changed files with 25 additions and 19 deletions

View File

@@ -282,7 +282,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
expect(comp.sectionData.errorsToShow).toEqual([]); expect(comp.sectionData.errorsToShow).toEqual([]);
expect(comp.sectionData.data).toEqual(sectionData); expect(comp.sectionData.data).toEqual(sectionData);
expect(comp.isLoading).toBeFalsy(); expect(comp.isLoading).toBeFalsy();
expect(comp.initForm).toHaveBeenCalledWith(sectionData); expect(comp.initForm).toHaveBeenCalledWith(sectionData, [], []);
expect(comp.subscriptions).toHaveBeenCalled(); expect(comp.subscriptions).toHaveBeenCalled();
}); });
@@ -290,7 +290,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
formBuilderService.modelFromConfiguration.and.returnValue(testFormModel); formBuilderService.modelFromConfiguration.and.returnValue(testFormModel);
const sectionData = {}; const sectionData = {};
comp.initForm(sectionData); comp.initForm(sectionData, [], []);
expect(comp.formModel).toEqual(testFormModel); expect(comp.formModel).toEqual(testFormModel);
@@ -305,7 +305,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
path: '/sections/' + sectionObject.id, path: '/sections/' + sectionObject.id,
}; };
comp.initForm(sectionData); comp.initForm(sectionData, [], []);
expect(comp.formModel).toBeUndefined(); expect(comp.formModel).toBeUndefined();
expect(sectionsServiceStub.setSectionError).toHaveBeenCalledWith(submissionId, sectionObject.id, sectionError); expect(sectionsServiceStub.setSectionError).toHaveBeenCalledWith(submissionId, sectionObject.id, sectionError);
@@ -464,7 +464,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
compAsAny.formData = {}; compAsAny.formData = {};
compAsAny.sectionMetadata = ['dc.title']; compAsAny.sectionMetadata = ['dc.title'];
comp.updateForm(sectionData, sectionError); comp.updateForm({ data: sectionData, errorsToShow: sectionError } as any);
expect(comp.isUpdating).toBeFalsy(); expect(comp.isUpdating).toBeFalsy();
expect(comp.initForm).toHaveBeenCalled(); expect(comp.initForm).toHaveBeenCalled();
@@ -476,15 +476,19 @@ describe('SubmissionSectionFormComponent test suite', () => {
it('should update form error properly', () => { it('should update form error properly', () => {
spyOn(comp, 'initForm'); spyOn(comp, 'initForm');
spyOn(comp, 'checksForErrors'); spyOn(comp, 'checksForErrors');
const sectionData: any = { const sectionData = {
'dc.title': [new FormFieldMetadataValueObject('test')], 'dc.title': [new FormFieldMetadataValueObject('test')],
}; };
const sectionState = {
data: sectionData,
errorsToShow: [{ path: '/test', message: 'test' }],
} as any;
comp.sectionData.data = {}; comp.sectionData.data = {};
comp.sectionData.errorsToShow = []; comp.sectionData.errorsToShow = [];
compAsAny.formData = sectionData; compAsAny.formData = sectionData;
compAsAny.sectionMetadata = ['dc.title']; compAsAny.sectionMetadata = ['dc.title'];
comp.updateForm(sectionData, parsedSectionErrors); comp.updateForm(sectionState);
expect(comp.initForm).not.toHaveBeenCalled(); expect(comp.initForm).not.toHaveBeenCalled();
expect(comp.checksForErrors).toHaveBeenCalled(); expect(comp.checksForErrors).toHaveBeenCalled();
@@ -495,8 +499,9 @@ describe('SubmissionSectionFormComponent test suite', () => {
spyOn(comp, 'initForm'); spyOn(comp, 'initForm');
spyOn(comp, 'checksForErrors'); spyOn(comp, 'checksForErrors');
const sectionData: any = {}; 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.initForm).not.toHaveBeenCalled();
expect(comp.checksForErrors).toHaveBeenCalled(); expect(comp.checksForErrors).toHaveBeenCalled();
@@ -562,7 +567,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
const sectionState = { const sectionState = {
data: sectionData, data: sectionData,
errorsToShow: parsedSectionErrors, errorsToShow: parsedSectionErrors,
}; } as any;
formService.getFormData.and.returnValue(observableOf(formData)); formService.getFormData.and.returnValue(observableOf(formData));
sectionsServiceStub.getSectionState.and.returnValue(observableOf(sectionState)); sectionsServiceStub.getSectionState.and.returnValue(observableOf(sectionState));
@@ -571,7 +576,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
expect(compAsAny.subs.length).toBe(2); expect(compAsAny.subs.length).toBe(2);
expect(compAsAny.formData).toEqual(formData); expect(compAsAny.formData).toEqual(formData);
expect(comp.updateForm).toHaveBeenCalledWith(sectionState.data, sectionState.errorsToShow); expect(comp.updateForm).toHaveBeenCalledWith(sectionState);
}); });

View File

@@ -224,7 +224,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
this.submissionObject = submissionObject; this.submissionObject = submissionObject;
this.isSectionReadonly = isSectionReadOnly; this.isSectionReadonly = isSectionReadOnly;
// Is the first loading so init form // Is the first loading so init form
this.initForm(sectionData); this.initForm(sectionData, this.sectionData.errorsToShow, this.sectionData.serverValidationErrors);
this.sectionData.data = sectionData; this.sectionData.data = sectionData;
this.subscriptions(); this.subscriptions();
this.isLoading = false; this.isLoading = false;
@@ -328,7 +328,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
* @param sectionData * @param sectionData
* the section data retrieved from the server * the section data retrieved from the server
*/ */
initForm(sectionData: WorkspaceitemSectionFormObject): void { initForm(sectionData: WorkspaceitemSectionFormObject, errorsToShow: SubmissionSectionError[], serverValidationErrors: SubmissionSectionError[]): void {
try { try {
this.formModel = this.formBuilderService.modelFromConfiguration( this.formModel = this.formBuilderService.modelFromConfiguration(
this.submissionId, this.submissionId,
@@ -339,7 +339,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
this.isSectionReadonly, this.isSectionReadonly,
); );
const sectionMetadata = this.sectionService.computeSectionConfiguredMetadata(this.formConfig); 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) { } catch (e) {
const msg: string = this.translate.instant('error.submission.sections.init-form-error') + e.toString(); const msg: string = this.translate.instant('error.submission.sections.init-form-error') + e.toString();
const sectionError: SubmissionSectionError = { const sectionError: SubmissionSectionError = {
@@ -356,12 +356,13 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
/** /**
* Update form model * Update form model
* *
* @param sectionData * @param sectionState
* the section data retrieved from the server * the section state retrieved from the server
* @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)) { if (isNotEmpty(sectionData) && !isEqual(sectionData, this.sectionData.data)) {
this.sectionData.data = sectionData; this.sectionData.data = sectionData;
@@ -369,7 +370,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
this.isUpdating = true; this.isUpdating = true;
this.formModel = null; this.formModel = null;
this.cdr.detectChanges(); this.cdr.detectChanges();
this.initForm(sectionData); this.initForm(sectionData, errors, sectionState.serverValidationErrors);
this.checksForErrors(errors); this.checksForErrors(errors);
this.isUpdating = false; this.isUpdating = false;
this.cdr.detectChanges(); this.cdr.detectChanges();
@@ -423,7 +424,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
.subscribe((sectionState: SubmissionSectionObject) => { .subscribe((sectionState: SubmissionSectionObject) => {
this.fieldsOnTheirWayToBeRemoved = new Map(); this.fieldsOnTheirWayToBeRemoved = new Map();
this.sectionMetadata = sectionState.metadata; this.sectionMetadata = sectionState.metadata;
this.updateForm(sectionState.data as WorkspaceitemSectionFormObject, sectionState.errorsToShow); this.updateForm(sectionState);
}), }),
); );
} }