[CST-4884] Code cleanup and test improvement

This commit is contained in:
Davide Negretti
2021-11-24 23:39:59 +01:00
parent 27bce0e5bb
commit 7218c450e6
4 changed files with 10 additions and 90 deletions

View File

@@ -8,7 +8,7 @@
<div class="float-left w-75">
<h3>{{fileName}} <span class="text-muted">({{fileData?.sizeBytes | dsFileSize}})</span></h3>
</div>
<div class="float-right w-15" [class.sticky-buttons]="!readMode">
<div class="float-right w-15">
<ng-container>
<ds-file-download-link [cssClasses]="'btn btn-link-focus'" [isBlank]="true" [bitstream]="getBitstream()" [enableRequestACopy]="false">
<i class="fa fa-download fa-2x text-normal" aria-hidden="true"></i>

View File

@@ -1,6 +0,0 @@
.sticky-buttons {
position: sticky;
top: calc(var(--bs-dropdown-item-padding-x) * 3);
z-index: var(--ds-submission-footer-z-index);
background-color: rgba(255, 255, 255, .97);
}

View File

@@ -217,86 +217,20 @@ describe('SubmissionSectionUploadFileComponent test suite', () => {
pathCombiner.subRootElement);
});
/*it('should save Bitstream File data properly when form is valid', fakeAsync(() => {
compAsAny.fileEditComp = TestBed.inject(SubmissionSectionUploadFileEditComponent);
compAsAny.fileEditComp.formRef = {formGroup: null};
compAsAny.fileData = fileData;
compAsAny.pathCombiner = pathCombiner;
const event = new Event('click', null);
spyOn(comp, 'switchMode');
formService.validateAllFormFields.and.callFake(() => null);
formService.isValid.and.returnValue(observableOf(true));
formService.getFormData.and.returnValue(observableOf(mockFileFormData));
it('should open edit modal when edit button is clicked', () => {
spyOn(compAsAny, 'editBitstreamData').and.callThrough();
comp.fileData = fileData;
const response = [
Object.assign(mockSubmissionObject, {
sections: {
upload: {
files: mockUploadFiles
}
}
})
];
operationsService.jsonPatchByResourceID.and.returnValue(observableOf(response));
fixture.detectChanges();
const accessConditionsToSave = [
{ name: 'openaccess' },
{ name: 'lease', endDate: dateToISOFormat('2019-01-16T00:00:00Z') },
{ name: 'embargo', startDate: dateToISOFormat('2019-01-16T00:00:00Z') },
];
comp.saveBitstreamData(event);
tick();
const modalBtn = fixture.debugElement.query(By.css('.fa-edit '));
let path = 'metadata/dc.title';
expect(operationsBuilder.add).toHaveBeenCalledWith(
pathCombiner.getPath(path),
mockFileFormData.metadata['dc.title'],
true
);
modalBtn.nativeElement.click();
fixture.detectChanges();
path = 'metadata/dc.description';
expect(operationsBuilder.add).toHaveBeenCalledWith(
pathCombiner.getPath(path),
mockFileFormData.metadata['dc.description'],
true
);
path = 'accessConditions';
expect(operationsBuilder.add).toHaveBeenCalledWith(
pathCombiner.getPath(path),
accessConditionsToSave,
true
);
expect(comp.switchMode).toHaveBeenCalled();
expect(uploadService.updateFileData).toHaveBeenCalledWith(submissionId, sectionId, mockUploadFiles[0].uuid, mockUploadFiles[0]);
}));*/
/*it('should not save Bitstream File data properly when form is not valid', fakeAsync(() => {
compAsAny.fileEditComp = TestBed.inject(SubmissionSectionUploadFileEditComponent);
compAsAny.fileEditComp.formRef = {formGroup: null};
compAsAny.pathCombiner = pathCombiner;
const event = new Event('click', null);
spyOn(comp, 'switchMode');
formService.validateAllFormFields.and.callFake(() => null);
formService.isValid.and.returnValue(observableOf(false));
expect(comp.switchMode).not.toHaveBeenCalled();
expect(uploadService.updateFileData).not.toHaveBeenCalled();
}));*/
it('should switch read mode', () => {
comp.readMode = false;
comp.switchMode();
expect(comp.readMode).toBeTruthy();
comp.switchMode();
expect(comp.readMode).toBeFalsy();
expect(compAsAny.editBitstreamData).toHaveBeenCalled();
});
});
});

View File

@@ -217,14 +217,6 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit {
});
}
/**
* Switch from edit form to metadata view
*/
public switchMode() {
this.readMode = !this.readMode;
this.cdr.detectChanges();
}
editBitstreamData() {
const options: NgbModalOptions = {