mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Update unit tests
This commit is contained in:
@@ -10,6 +10,8 @@ export class SectionsServiceStub {
|
|||||||
isSectionEnabled = jasmine.createSpy('isSectionEnabled');
|
isSectionEnabled = jasmine.createSpy('isSectionEnabled');
|
||||||
isSectionReadOnly = jasmine.createSpy('isSectionReadOnly');
|
isSectionReadOnly = jasmine.createSpy('isSectionReadOnly');
|
||||||
isSectionAvailable = jasmine.createSpy('isSectionAvailable');
|
isSectionAvailable = jasmine.createSpy('isSectionAvailable');
|
||||||
|
isSectionTypeAvailable = jasmine.createSpy('isSectionTypeAvailable');
|
||||||
|
isSectionType = jasmine.createSpy('isSectionType');
|
||||||
addSection = jasmine.createSpy('addSection');
|
addSection = jasmine.createSpy('addSection');
|
||||||
removeSection = jasmine.createSpy('removeSection');
|
removeSection = jasmine.createSpy('removeSection');
|
||||||
updateSectionData = jasmine.createSpy('updateSectionData');
|
updateSectionData = jasmine.createSpy('updateSectionData');
|
||||||
|
@@ -120,7 +120,7 @@ describe('SubmissionFormCollectionComponent Component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const sectionsService: any = jasmine.createSpyObj('sectionsService', {
|
const sectionsService: any = jasmine.createSpyObj('sectionsService', {
|
||||||
isSectionAvailable: of(true)
|
isSectionTypeAvailable: of(true)
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
|
@@ -83,7 +83,6 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
|||||||
const html = `
|
const html = `
|
||||||
<ds-submission-upload-files [submissionId]="submissionId"
|
<ds-submission-upload-files [submissionId]="submissionId"
|
||||||
[collectionId]="collectionId"
|
[collectionId]="collectionId"
|
||||||
[sectionId]="'upload'"
|
|
||||||
[uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files>`;
|
[uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files>`;
|
||||||
|
|
||||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||||
@@ -108,11 +107,11 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
|||||||
compAsAny = comp;
|
compAsAny = comp;
|
||||||
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
||||||
sectionsServiceStub = TestBed.inject(SectionsService as any);
|
sectionsServiceStub = TestBed.inject(SectionsService as any);
|
||||||
|
sectionsServiceStub.isSectionTypeAvailable.and.returnValue(observableOf(true));
|
||||||
notificationsServiceStub = TestBed.inject(NotificationsService as any);
|
notificationsServiceStub = TestBed.inject(NotificationsService as any);
|
||||||
translateService = TestBed.inject(TranslateService);
|
translateService = TestBed.inject(TranslateService);
|
||||||
comp.submissionId = submissionId;
|
comp.submissionId = submissionId;
|
||||||
comp.collectionId = collectionId;
|
comp.collectionId = collectionId;
|
||||||
comp.sectionId = 'upload';
|
|
||||||
comp.uploadFilesOptions = Object.assign(new UploaderOptions(),{
|
comp.uploadFilesOptions = Object.assign(new UploaderOptions(),{
|
||||||
url: '',
|
url: '',
|
||||||
authToken: null,
|
authToken: null,
|
||||||
@@ -133,7 +132,7 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init uploadEnabled properly', () => {
|
it('should init uploadEnabled properly', () => {
|
||||||
sectionsServiceStub.isSectionAvailable.and.returnValue(hot('-a-b', {
|
sectionsServiceStub.isSectionTypeAvailable.and.returnValue(hot('-a-b', {
|
||||||
a: false,
|
a: false,
|
||||||
b: true
|
b: true
|
||||||
}));
|
}));
|
||||||
@@ -149,53 +148,56 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
|||||||
expect(compAsAny.uploadEnabled).toBeObservable(expected);
|
expect(compAsAny.uploadEnabled).toBeObservable(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show a success notification and call updateSectionData on upload complete', () => {
|
describe('on upload complete', () => {
|
||||||
|
beforeEach(() => {
|
||||||
const expectedErrors: any = mockUploadResponse1ParsedErrors;
|
sectionsServiceStub.isSectionType.and.callFake((submissionId, sectionId, sectionType) => {
|
||||||
compAsAny.uploadEnabled = observableOf(true);
|
return observableOf(sectionId === 'upload')
|
||||||
fixture.detectChanges();
|
});
|
||||||
|
compAsAny.uploadEnabled = observableOf(true);
|
||||||
comp.onCompleteItem(Object.assign({}, uploadRestResponse, { sections: mockSectionsData }));
|
|
||||||
|
|
||||||
Object.keys(mockSectionsData).forEach((sectionId) => {
|
|
||||||
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
|
||||||
submissionId,
|
|
||||||
sectionId,
|
|
||||||
mockSectionsData[sectionId],
|
|
||||||
expectedErrors[sectionId]
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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', () => {
|
Object.keys(mockSectionsData).forEach((sectionId) => {
|
||||||
|
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
||||||
|
submissionId,
|
||||||
|
sectionId,
|
||||||
|
mockSectionsData[sectionId],
|
||||||
|
expectedErrors[sectionId]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const responseErrors = mockUploadResponse2Errors;
|
expect(notificationsServiceStub.success).toHaveBeenCalled();
|
||||||
|
|
||||||
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],
|
|
||||||
expectedErrors[sectionId]
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(notificationsServiceStub.success).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -208,7 +210,6 @@ class TestComponent {
|
|||||||
|
|
||||||
submissionId = mockSubmissionId;
|
submissionId = mockSubmissionId;
|
||||||
collectionId = mockSubmissionCollectionId;
|
collectionId = mockSubmissionCollectionId;
|
||||||
sectionId = 'upload';
|
|
||||||
uploadFilesOptions = Object.assign(new UploaderOptions(), {
|
uploadFilesOptions = Object.assign(new UploaderOptions(), {
|
||||||
url: '',
|
url: '',
|
||||||
authToken: null,
|
authToken: null,
|
||||||
|
Reference in New Issue
Block a user