Commits

Michael Spalti authored and github-actions[bot] committed 381254a16e5
File edit component updated to work for forms without access conditions.

Fixed unit test Fixed accidental reformatting (cherry picked from commit 6fff475a5a0a8a2a234b114307e3df897400da60)
No tags

src/app/submission/sections/upload/file/edit/section-upload-file-edit.component.spec.ts

Modified
73 73 const sectionId = 'upload';
74 74 const collectionId = mockSubmissionCollectionId;
75 75 const availableAccessConditionOptions = mockUploadConfigResponse.accessConditionOptions;
76 76 const collectionPolicyType = POLICY_DEFAULT_WITH_LIST;
77 77 const configMetadataForm: any = mockUploadConfigResponseMetadata;
78 78 const fileIndex = '0';
79 79 const fileId = '123456-test-upload';
80 80 const fileData: any = mockUploadFiles[0];
81 81 const pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionId, 'files', fileIndex);
82 82
83 + let noAccessConditionsMock = Object.assign({}, mockFileFormData);
84 + delete noAccessConditionsMock.accessConditions;
85 +
83 86 beforeEach(waitForAsync(() => {
84 87 TestBed.configureTestingModule({
85 88 imports: [
86 89 BrowserModule,
87 90 CommonModule,
88 91 FormsModule,
89 92 ReactiveFormsModule,
90 93 TranslateModule.forRoot()
91 94 ],
92 95 declarations: [
292 295 expect(operationsBuilder.add).toHaveBeenCalledWith(
293 296 pathCombiner.getPath(path),
294 297 accessConditionsToSave,
295 298 true
296 299 );
297 300
298 301 expect(uploadService.updateFileData).toHaveBeenCalledWith(submissionId, sectionId, mockUploadFiles[0].uuid, mockUploadFiles[0]);
299 302
300 303 }));
301 304
305 + it('should update Bitstream data properly when access options are omitted', fakeAsync(() => {
306 + compAsAny.formRef = {formGroup: null};
307 + compAsAny.fileData = fileData;
308 + compAsAny.pathCombiner = pathCombiner;
309 + formService.validateAllFormFields.and.callFake(() => null);
310 + formService.isValid.and.returnValue(of(true));
311 + formService.getFormData.and.returnValue(of(noAccessConditionsMock));
312 + const response = [
313 + Object.assign(mockSubmissionObject, {
314 + sections: {
315 + upload: {
316 + files: mockUploadFiles
317 + }
318 + }
319 + })
320 + ];
321 + operationsService.jsonPatchByResourceID.and.returnValue(of(response));
322 + comp.saveBitstreamData();
323 + tick();
324 + expect(uploadService.updateFileData).toHaveBeenCalled();
325 + }));
326 +
302 327 it('should not save Bitstream File data properly when form is not valid', fakeAsync(() => {
303 328 compAsAny.formRef = {formGroup: null};
304 329 compAsAny.pathCombiner = pathCombiner;
305 330 formService.validateAllFormFields.and.callFake(() => null);
306 331 formService.isValid.and.returnValue(of(false));
307 332 comp.saveBitstreamData();
308 333 tick();
309 334
310 335 expect(uploadService.updateFileData).not.toHaveBeenCalled();
311 336

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut