Skip to content

Commit d29d3ca

Browse files
authored
Merge pull request DSpace#2905 from atmire/w2p-113500_submission-describe-warning_contribution
Fix for submission describe warning contribution bug
2 parents 39d2a75 + 903af2c commit d29d3ca

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

src/app/submission/sections/form/section-form.component.spec.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,15 @@ describe('SubmissionSectionFormComponent test suite', () => {
282282
expect(comp.sectionData.errorsToShow).toEqual([]);
283283
expect(comp.sectionData.data).toEqual(sectionData);
284284
expect(comp.isLoading).toBeFalsy();
285-
expect(comp.initForm).toHaveBeenCalledWith(sectionData);
285+
expect(comp.initForm).toHaveBeenCalledWith(sectionData, [], []);
286286
expect(comp.subscriptions).toHaveBeenCalled();
287287
});
288288

289289
it('should init form model properly', () => {
290290
formBuilderService.modelFromConfiguration.and.returnValue(testFormModel);
291291
const sectionData = {};
292292

293-
comp.initForm(sectionData);
293+
comp.initForm(sectionData, [], []);
294294

295295
expect(comp.formModel).toEqual(testFormModel);
296296

@@ -305,7 +305,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
305305
path: '/sections/' + sectionObject.id,
306306
};
307307

308-
comp.initForm(sectionData);
308+
comp.initForm(sectionData, [], []);
309309

310310
expect(comp.formModel).toBeUndefined();
311311
expect(sectionsServiceStub.setSectionError).toHaveBeenCalledWith(submissionId, sectionObject.id, sectionError);
@@ -464,7 +464,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
464464
compAsAny.formData = {};
465465
compAsAny.sectionMetadata = ['dc.title'];
466466

467-
comp.updateForm(sectionData, sectionError);
467+
comp.updateForm({ data: sectionData, errorsToShow: sectionError } as any);
468468

469469
expect(comp.isUpdating).toBeFalsy();
470470
expect(comp.initForm).toHaveBeenCalled();
@@ -476,15 +476,19 @@ describe('SubmissionSectionFormComponent test suite', () => {
476476
it('should update form error properly', () => {
477477
spyOn(comp, 'initForm');
478478
spyOn(comp, 'checksForErrors');
479-
const sectionData: any = {
479+
const sectionData = {
480480
'dc.title': [new FormFieldMetadataValueObject('test')],
481481
};
482+
const sectionState = {
483+
data: sectionData,
484+
errorsToShow: [{ path: '/test', message: 'test' }],
485+
} as any;
482486
comp.sectionData.data = {};
483487
comp.sectionData.errorsToShow = [];
484488
compAsAny.formData = sectionData;
485489
compAsAny.sectionMetadata = ['dc.title'];
486490

487-
comp.updateForm(sectionData, parsedSectionErrors);
491+
comp.updateForm(sectionState);
488492

489493
expect(comp.initForm).not.toHaveBeenCalled();
490494
expect(comp.checksForErrors).toHaveBeenCalled();
@@ -495,8 +499,9 @@ describe('SubmissionSectionFormComponent test suite', () => {
495499
spyOn(comp, 'initForm');
496500
spyOn(comp, 'checksForErrors');
497501
const sectionData: any = {};
502+
const sectionErrors: any = [{ path: '/test', message: 'test' }];
498503

499-
comp.updateForm(sectionData, parsedSectionErrors);
504+
comp.updateForm({ data: sectionData, errorsToShow: sectionErrors } as any);
500505

501506
expect(comp.initForm).not.toHaveBeenCalled();
502507
expect(comp.checksForErrors).toHaveBeenCalled();
@@ -562,7 +567,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
562567
const sectionState = {
563568
data: sectionData,
564569
errorsToShow: parsedSectionErrors,
565-
};
570+
} as any;
566571

567572
formService.getFormData.and.returnValue(observableOf(formData));
568573
sectionsServiceStub.getSectionState.and.returnValue(observableOf(sectionState));
@@ -571,7 +576,7 @@ describe('SubmissionSectionFormComponent test suite', () => {
571576

572577
expect(compAsAny.subs.length).toBe(2);
573578
expect(compAsAny.formData).toEqual(formData);
574-
expect(comp.updateForm).toHaveBeenCalledWith(sectionState.data, sectionState.errorsToShow);
579+
expect(comp.updateForm).toHaveBeenCalledWith(sectionState);
575580

576581
});
577582

src/app/submission/sections/form/section-form.component.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
224224
this.submissionObject = submissionObject;
225225
this.isSectionReadonly = isSectionReadOnly;
226226
// Is the first loading so init form
227-
this.initForm(sectionData);
227+
this.initForm(sectionData, this.sectionData.errorsToShow, this.sectionData.serverValidationErrors);
228228
this.sectionData.data = sectionData;
229229
this.subscriptions();
230230
this.isLoading = false;
@@ -328,7 +328,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
328328
* @param sectionData
329329
* the section data retrieved from the server
330330
*/
331-
initForm(sectionData: WorkspaceitemSectionFormObject): void {
331+
initForm(sectionData: WorkspaceitemSectionFormObject, errorsToShow: SubmissionSectionError[], serverValidationErrors: SubmissionSectionError[]): void {
332332
try {
333333
this.formModel = this.formBuilderService.modelFromConfiguration(
334334
this.submissionId,
@@ -339,7 +339,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
339339
this.isSectionReadonly,
340340
);
341341
const sectionMetadata = this.sectionService.computeSectionConfiguredMetadata(this.formConfig);
342-
this.sectionService.updateSectionData(this.submissionId, this.sectionData.id, sectionData, this.sectionData.errorsToShow, this.sectionData.serverValidationErrors, sectionMetadata);
342+
this.sectionService.updateSectionData(this.submissionId, this.sectionData.id, sectionData, errorsToShow, serverValidationErrors, sectionMetadata);
343343
} catch (e) {
344344
const msg: string = this.translate.instant('error.submission.sections.init-form-error') + e.toString();
345345
const sectionError: SubmissionSectionError = {
@@ -356,20 +356,21 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
356356
/**
357357
* Update form model
358358
*
359-
* @param sectionData
360-
* the section data retrieved from the server
361-
* @param errors
362-
* the section errors retrieved from the server
359+
* @param sectionState
360+
* the section state retrieved from the server
363361
*/
364-
updateForm(sectionData: WorkspaceitemSectionFormObject, errors: SubmissionSectionError[]): void {
362+
updateForm(sectionState: SubmissionSectionObject): void {
363+
364+
const sectionData = sectionState.data as WorkspaceitemSectionFormObject;
365+
const errors = sectionState.errorsToShow;
365366

366367
if (isNotEmpty(sectionData) && !isEqual(sectionData, this.sectionData.data)) {
367368
this.sectionData.data = sectionData;
368369
if (this.hasMetadataEnrichment(sectionData)) {
369370
this.isUpdating = true;
370371
this.formModel = null;
371372
this.cdr.detectChanges();
372-
this.initForm(sectionData);
373+
this.initForm(sectionData, errors, sectionState.serverValidationErrors);
373374
this.checksForErrors(errors);
374375
this.isUpdating = false;
375376
this.cdr.detectChanges();
@@ -423,7 +424,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent {
423424
.subscribe((sectionState: SubmissionSectionObject) => {
424425
this.fieldsOnTheirWayToBeRemoved = new Map();
425426
this.sectionMetadata = sectionState.metadata;
426-
this.updateForm(sectionState.data as WorkspaceitemSectionFormObject, sectionState.errorsToShow);
427+
this.updateForm(sectionState);
427428
}),
428429
);
429430
}

0 commit comments

Comments
 (0)