mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
Merge remote-tracking branch 'origin/main' into #1206
# Conflicts: # src/app/submission/form/submission-upload-files/submission-upload-files.component.spec.ts # src/app/submission/form/submission-upload-files/submission-upload-files.component.ts
This commit is contained in:
@@ -83,7 +83,6 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
||||
const html = `
|
||||
<ds-submission-upload-files [submissionId]="submissionId"
|
||||
[collectionId]="collectionId"
|
||||
[sectionId]="'upload'"
|
||||
[uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files>`;
|
||||
|
||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||
@@ -108,11 +107,11 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
||||
compAsAny = comp;
|
||||
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
||||
sectionsServiceStub = TestBed.inject(SectionsService as any);
|
||||
sectionsServiceStub.isSectionTypeAvailable.and.returnValue(observableOf(true));
|
||||
notificationsServiceStub = TestBed.inject(NotificationsService as any);
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
comp.submissionId = submissionId;
|
||||
comp.collectionId = collectionId;
|
||||
comp.sectionId = 'upload';
|
||||
comp.uploadFilesOptions = Object.assign(new UploaderOptions(),{
|
||||
url: '',
|
||||
authToken: null,
|
||||
@@ -133,7 +132,7 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
||||
});
|
||||
|
||||
it('should init uploadEnabled properly', () => {
|
||||
sectionsServiceStub.isSectionAvailable.and.returnValue(hot('-a-b', {
|
||||
sectionsServiceStub.isSectionTypeAvailable.and.returnValue(hot('-a-b', {
|
||||
a: false,
|
||||
b: true
|
||||
}));
|
||||
@@ -149,55 +148,56 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
||||
expect(compAsAny.uploadEnabled).toBeObservable(expected);
|
||||
});
|
||||
|
||||
it('should show a success notification and call updateSectionData on upload complete', () => {
|
||||
|
||||
const expectedErrors: any = mockUploadResponse1ParsedErrors;
|
||||
compAsAny.uploadEnabled = observableOf(true);
|
||||
fixture.detectChanges();
|
||||
|
||||
comp.onCompleteItem(Object.assign({}, uploadRestResponse, { sections: mockSectionsData }));
|
||||
|
||||
Object.keys(mockSectionsData).forEach((sectionId) => {
|
||||
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
||||
submissionId,
|
||||
sectionId,
|
||||
mockSectionsData[sectionId],
|
||||
expectedErrors[sectionId],
|
||||
expectedErrors[sectionId]
|
||||
);
|
||||
describe('on upload complete', () => {
|
||||
beforeEach(() => {
|
||||
sectionsServiceStub.isSectionType.and.callFake((_, sectionId, __) => observableOf(sectionId === 'upload'));
|
||||
compAsAny.uploadEnabled = observableOf(true);
|
||||
});
|
||||
|
||||
expect(notificationsServiceStub.success).toHaveBeenCalled();
|
||||
it('should show a success notification and call updateSectionData if successful', () => {
|
||||
const expectedErrors: any = mockUploadResponse1ParsedErrors;
|
||||
fixture.detectChanges();
|
||||
|
||||
});
|
||||
comp.onCompleteItem(Object.assign({}, uploadRestResponse, { sections: mockSectionsData }));
|
||||
|
||||
it('should show an error notification and call updateSectionData on upload complete', () => {
|
||||
|
||||
const responseErrors = mockUploadResponse2Errors;
|
||||
|
||||
const expectedErrors: any = mockUploadResponse2ParsedErrors;
|
||||
compAsAny.uploadEnabled = observableOf(true);
|
||||
fixture.detectChanges();
|
||||
|
||||
comp.onCompleteItem(Object.assign({}, uploadRestResponse, {
|
||||
sections: mockSectionsData,
|
||||
errors: responseErrors.errors
|
||||
}));
|
||||
|
||||
Object.keys(mockSectionsData).forEach((sectionId) => {
|
||||
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
||||
submissionId,
|
||||
sectionId,
|
||||
mockSectionsData[sectionId],
|
||||
Object.keys(mockSectionsData).forEach((sectionId) => {
|
||||
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
||||
submissionId,
|
||||
sectionId,
|
||||
mockSectionsData[sectionId],
|
||||
expectedErrors[sectionId],
|
||||
expectedErrors[sectionId]
|
||||
);
|
||||
expectedErrors[sectionId]
|
||||
);
|
||||
});
|
||||
|
||||
expect(notificationsServiceStub.success).toHaveBeenCalled();
|
||||
|
||||
});
|
||||
|
||||
expect(notificationsServiceStub.success).not.toHaveBeenCalled();
|
||||
it('should show an error notification and call updateSectionData if unsuccessful', () => {
|
||||
const responseErrors = mockUploadResponse2Errors;
|
||||
const expectedErrors: any = mockUploadResponse2ParsedErrors;
|
||||
fixture.detectChanges();
|
||||
|
||||
comp.onCompleteItem(Object.assign({}, uploadRestResponse, {
|
||||
sections: mockSectionsData,
|
||||
errors: responseErrors.errors
|
||||
}));
|
||||
|
||||
Object.keys(mockSectionsData).forEach((sectionId) => {
|
||||
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
||||
submissionId,
|
||||
sectionId,
|
||||
mockSectionsData[sectionId],
|
||||
expectedErrors[sectionId],
|
||||
expectedErrors[sectionId]
|
||||
);
|
||||
});
|
||||
|
||||
expect(notificationsServiceStub.success).not.toHaveBeenCalled();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -210,7 +210,6 @@ class TestComponent {
|
||||
|
||||
submissionId = mockSubmissionId;
|
||||
collectionId = mockSubmissionCollectionId;
|
||||
sectionId = 'upload';
|
||||
uploadFilesOptions = Object.assign(new UploaderOptions(), {
|
||||
url: '',
|
||||
authToken: null,
|
||||
|
@@ -2,7 +2,7 @@ import { Component, Input, OnChanges } from '@angular/core';
|
||||
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Observable, of as observableOf, Subscription } from 'rxjs';
|
||||
import { first } from 'rxjs/operators';
|
||||
import { first, take } from 'rxjs/operators';
|
||||
|
||||
import { SectionsService } from '../../sections/sections.service';
|
||||
import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
||||
@@ -13,6 +13,7 @@ import { UploaderOptions } from '../../../shared/uploader/uploader-options.model
|
||||
import parseSectionErrors from '../../utils/parseSectionErrors';
|
||||
import { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service';
|
||||
import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model';
|
||||
import { SectionsType } from '../../sections/sections-type';
|
||||
|
||||
/**
|
||||
* This component represents the drop zone that provides to add files to the submission.
|
||||
@@ -35,12 +36,6 @@ export class SubmissionUploadFilesComponent implements OnChanges {
|
||||
*/
|
||||
@Input() submissionId: string;
|
||||
|
||||
/**
|
||||
* The upload section id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() sectionId: string;
|
||||
|
||||
/**
|
||||
* The uploader configuration options
|
||||
* @type {UploaderOptions}
|
||||
@@ -110,7 +105,7 @@ export class SubmissionUploadFilesComponent implements OnChanges {
|
||||
* Check if upload functionality is enabled
|
||||
*/
|
||||
ngOnChanges() {
|
||||
this.uploadEnabled = this.sectionService.isSectionAvailable(this.submissionId, this.sectionId);
|
||||
this.uploadEnabled = this.sectionService.isSectionTypeAvailable(this.submissionId, SectionsType.Upload);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,14 +131,18 @@ export class SubmissionUploadFilesComponent implements OnChanges {
|
||||
.forEach((sectionId) => {
|
||||
const sectionData = normalizeSectionData(sections[sectionId]);
|
||||
const sectionErrors = errorsList[sectionId];
|
||||
if (sectionId === 'upload') {
|
||||
// Look for errors on upload
|
||||
if ((isEmpty(sectionErrors))) {
|
||||
this.notificationsService.success(null, this.translate.get('submission.sections.upload.upload-successful'));
|
||||
} else {
|
||||
this.notificationsService.error(null, this.translate.get('submission.sections.upload.upload-failed'));
|
||||
}
|
||||
}
|
||||
this.sectionService.isSectionType(this.submissionId, sectionId, SectionsType.Upload)
|
||||
.pipe(take(1))
|
||||
.subscribe((isUpload) => {
|
||||
if (isUpload) {
|
||||
// Look for errors on upload
|
||||
if ((isEmpty(sectionErrors))) {
|
||||
this.notificationsService.success(null, this.translate.get('submission.sections.upload.upload-successful'));
|
||||
} else {
|
||||
this.notificationsService.error(null, this.translate.get('submission.sections.upload.upload-failed'));
|
||||
}
|
||||
}
|
||||
});
|
||||
this.sectionService.updateSectionData(this.submissionId, sectionId, sectionData, sectionErrors, sectionErrors);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user