mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #2647 from mspalti/access-conditions
File edit component updated to work for forms without access conditions.
This commit is contained in:
@@ -80,6 +80,9 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
const fileData: any = mockUploadFiles[0];
|
||||
const pathCombiner = new JsonPatchOperationPathCombiner('sections', sectionId, 'files', fileIndex);
|
||||
|
||||
let noAccessConditionsMock = Object.assign({}, mockFileFormData);
|
||||
delete noAccessConditionsMock.accessConditions;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
@@ -299,6 +302,28 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
|
||||
}));
|
||||
|
||||
it('should update Bitstream data properly when access options are omitted', fakeAsync(() => {
|
||||
compAsAny.formRef = {formGroup: null};
|
||||
compAsAny.fileData = fileData;
|
||||
compAsAny.pathCombiner = pathCombiner;
|
||||
formService.validateAllFormFields.and.callFake(() => null);
|
||||
formService.isValid.and.returnValue(of(true));
|
||||
formService.getFormData.and.returnValue(of(noAccessConditionsMock));
|
||||
const response = [
|
||||
Object.assign(mockSubmissionObject, {
|
||||
sections: {
|
||||
upload: {
|
||||
files: mockUploadFiles
|
||||
}
|
||||
}
|
||||
})
|
||||
];
|
||||
operationsService.jsonPatchByResourceID.and.returnValue(of(response));
|
||||
comp.saveBitstreamData();
|
||||
tick();
|
||||
expect(uploadService.updateFileData).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should not save Bitstream File data properly when form is not valid', fakeAsync(() => {
|
||||
compAsAny.formRef = {formGroup: null};
|
||||
compAsAny.pathCombiner = pathCombiner;
|
||||
|
@@ -416,7 +416,9 @@ export class SubmissionSectionUploadFileEditComponent
|
||||
this.operationsBuilder.remove(this.pathCombiner.getPath(path));
|
||||
});
|
||||
const accessConditionsToSave = [];
|
||||
if (formData.hasOwnProperty('accessConditions')) {
|
||||
formData.accessConditions
|
||||
.filter((accessConditions) => isNotNull(accessConditions))
|
||||
.map((accessConditions) => accessConditions.accessConditionGroup)
|
||||
.filter((accessCondition) => isNotEmpty(accessCondition))
|
||||
.forEach((accessCondition) => {
|
||||
@@ -465,7 +467,7 @@ export class SubmissionSectionUploadFileEditComponent
|
||||
accessConditionsToSave.push(currentAccessCondition);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
if (isNotEmpty(accessConditionsToSave)) {
|
||||
this.operationsBuilder.add(this.pathCombiner.getPath('accessConditions'), accessConditionsToSave, true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user