Update unit tests

This commit is contained in:
Yura Bondarenko
2021-06-18 12:33:01 +02:00
parent 32003a72fd
commit 72e97ca6b4
3 changed files with 45 additions and 42 deletions

View File

@@ -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');

View File

@@ -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(() => {

View File

@@ -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,10 +148,16 @@ 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) => {
return observableOf(sectionId === 'upload')
});
compAsAny.uploadEnabled = observableOf(true); compAsAny.uploadEnabled = observableOf(true);
});
it('should show a success notification and call updateSectionData if successful', () => {
const expectedErrors: any = mockUploadResponse1ParsedErrors;
fixture.detectChanges(); fixture.detectChanges();
comp.onCompleteItem(Object.assign({}, uploadRestResponse, { sections: mockSectionsData })); comp.onCompleteItem(Object.assign({}, uploadRestResponse, { sections: mockSectionsData }));
@@ -170,12 +175,9 @@ describe('SubmissionUploadFilesComponent Component', () => {
}); });
it('should show an error notification and call updateSectionData on upload complete', () => { it('should show an error notification and call updateSectionData if unsuccessful', () => {
const responseErrors = mockUploadResponse2Errors; const responseErrors = mockUploadResponse2Errors;
const expectedErrors: any = mockUploadResponse2ParsedErrors; const expectedErrors: any = mockUploadResponse2ParsedErrors;
compAsAny.uploadEnabled = observableOf(true);
fixture.detectChanges(); fixture.detectChanges();
comp.onCompleteItem(Object.assign({}, uploadRestResponse, { comp.onCompleteItem(Object.assign({}, uploadRestResponse, {
@@ -195,7 +197,7 @@ describe('SubmissionUploadFilesComponent Component', () => {
expect(notificationsServiceStub.success).not.toHaveBeenCalled(); 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,