diff --git a/src/app/shared/mocks/mock-submission.ts b/src/app/shared/mocks/mock-submission.ts index 922e6ad02d..805612c758 100644 --- a/src/app/shared/mocks/mock-submission.ts +++ b/src/app/shared/mocks/mock-submission.ts @@ -1325,7 +1325,7 @@ export const mockUploadConfigResponse = { }, self: 'https://rest.api/dspace-spring-rest/api/config/submissionforms/bitstream-metadata' }, - required: false, + required: true, maxSize: 536870912, name: 'upload', type: 'submissionupload', @@ -1336,6 +1336,9 @@ export const mockUploadConfigResponse = { self: 'https://rest.api/dspace-spring-rest/api/config/submissionuploads/upload' }; +export const mockUploadConfigResponseNotRequired = mockUploadConfigResponse; +mockUploadConfigResponseNotRequired.required = false; + export const mockAccessConditionOptions = [ { name: 'openaccess', diff --git a/src/app/submission/sections/upload/section-upload.component.spec.ts b/src/app/submission/sections/upload/section-upload.component.spec.ts index fd9f88d939..58ad12ddc9 100644 --- a/src/app/submission/sections/upload/section-upload.component.spec.ts +++ b/src/app/submission/sections/upload/section-upload.component.spec.ts @@ -18,6 +18,7 @@ import { mockSubmissionId, mockSubmissionState, mockUploadConfigResponse, + mockUploadConfigResponseNotRequired, mockUploadFiles } from '../../../shared/mocks/mock-submission'; import { BrowserModule } from '@angular/platform-browser'; @@ -215,6 +216,7 @@ describe('SubmissionSectionUploadComponent test suite', () => { expect(comp.collectionName).toBe(mockCollection.name); expect(comp.availableAccessConditionOptions.length).toBe(4); expect(comp.availableAccessConditionOptions).toEqual(mockUploadConfigResponse.accessConditionOptions as any); + expect(comp.required).toBe(true); expect(compAsAny.subs.length).toBe(2); expect(compAsAny.availableGroups.size).toBe(2); expect(compAsAny.availableGroups).toEqual(expectedGroupsMap); @@ -254,6 +256,7 @@ describe('SubmissionSectionUploadComponent test suite', () => { expect(comp.collectionName).toBe(mockCollection.name); expect(comp.availableAccessConditionOptions.length).toBe(4); expect(comp.availableAccessConditionOptions).toEqual(mockUploadConfigResponse.accessConditionOptions as any); + expect(comp.required).toBe(true); expect(compAsAny.subs.length).toBe(2); expect(compAsAny.availableGroups.size).toBe(2); expect(compAsAny.availableGroups).toEqual(expectedGroupsMap); @@ -263,17 +266,41 @@ describe('SubmissionSectionUploadComponent test suite', () => { }); - it('should the properly section status', () => { + it('should properly read the section status', () => { bitstreamService.getUploadedFileList.and.returnValue(hot('-a-b', { a: [], b: mockUploadFiles })); + expect(comp.required).toBe(true); + expect(compAsAny.getSectionStatus()).toBeObservable(cold('-c-d', { c: false, d: true })); }); + + it('should properly read the section status when required is false', () => { + uploadsConfigService.getConfigByHref.and.returnValue(observableOf( + new ConfigData(new PageInfo(), mockUploadConfigResponseNotRequired as any) + )); + + bitstreamService.getUploadedFileList.and.returnValue(observableOf(mockUploadFiles)); + + comp.onSectionInit(); + + bitstreamService.getUploadedFileList.and.returnValue(hot('-a-b', { + a: [], + b: mockUploadFiles + })); + + expect(comp.required).toBe(false); + + expect(compAsAny.getSectionStatus()).toBeObservable(cold('-c-d', { + c: true, + d: true + })); + }); }); }); diff --git a/src/app/submission/sections/upload/section-upload.component.ts b/src/app/submission/sections/upload/section-upload.component.ts index 9dbd1079f4..24bb658d71 100644 --- a/src/app/submission/sections/upload/section-upload.component.ts +++ b/src/app/submission/sections/upload/section-upload.component.ts @@ -104,6 +104,12 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent { */ protected availableGroups: Map; // Groups for any policy + /** + * Is the upload required + * @type {boolean} + */ + public required: boolean; + /** * Array to track all subscriptions and unsubscribe them onDestroy * @type {Array} @@ -172,6 +178,7 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent { }), flatMap(() => config$), flatMap((config: SubmissionUploadsModel) => { + this.required = config.required; this.availableAccessConditionOptions = isNotEmpty(config.accessConditionOptions) ? config.accessConditionOptions : []; this.collectionPolicyType = this.availableAccessConditionOptions.length > 0 @@ -273,8 +280,11 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent { * the section status */ protected getSectionStatus(): Observable { + // if not mandatory, always true + // if mandatory, at least one file is required return this.bitstreamService.getUploadedFileList(this.submissionId, this.sectionData.id).pipe( - map((fileList: any[]) => (isNotUndefined(fileList) && fileList.length > 0))); + map((fileList: any[]) => + (!this.required || (isNotUndefined(fileList) && fileList.length > 0)))); } /**