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');
isSectionReadOnly = jasmine.createSpy('isSectionReadOnly');
isSectionAvailable = jasmine.createSpy('isSectionAvailable');
isSectionTypeAvailable = jasmine.createSpy('isSectionTypeAvailable');
isSectionType = jasmine.createSpy('isSectionType');
addSection = jasmine.createSpy('addSection');
removeSection = jasmine.createSpy('removeSection');
updateSectionData = jasmine.createSpy('updateSectionData');

View File

@@ -120,7 +120,7 @@ describe('SubmissionFormCollectionComponent Component', () => {
});
const sectionsService: any = jasmine.createSpyObj('sectionsService', {
isSectionAvailable: of(true)
isSectionTypeAvailable: of(true)
});
beforeEach(waitForAsync(() => {

View File

@@ -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,10 +148,16 @@ describe('SubmissionUploadFilesComponent Component', () => {
expect(compAsAny.uploadEnabled).toBeObservable(expected);
});
it('should show a success notification and call updateSectionData on upload complete', () => {
const expectedErrors: any = mockUploadResponse1ParsedErrors;
describe('on upload complete', () => {
beforeEach(() => {
sectionsServiceStub.isSectionType.and.callFake((submissionId, sectionId, sectionType) => {
return observableOf(sectionId === 'upload')
});
compAsAny.uploadEnabled = observableOf(true);
});
it('should show a success notification and call updateSectionData if successful', () => {
const expectedErrors: any = mockUploadResponse1ParsedErrors;
fixture.detectChanges();
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 expectedErrors: any = mockUploadResponse2ParsedErrors;
compAsAny.uploadEnabled = observableOf(true);
fixture.detectChanges();
comp.onCompleteItem(Object.assign({}, uploadRestResponse, {
@@ -195,7 +197,7 @@ describe('SubmissionUploadFilesComponent Component', () => {
expect(notificationsServiceStub.success).not.toHaveBeenCalled();
});
});
});
});
@@ -208,7 +210,6 @@ class TestComponent {
submissionId = mockSubmissionId;
collectionId = mockSubmissionCollectionId;
sectionId = 'upload';
uploadFilesOptions = Object.assign(new UploaderOptions(), {
url: '',
authToken: null,