[CST-3088] fix ProcessFormComponent test

This commit is contained in:
Giuseppe Digilio
2020-07-16 14:35:57 +02:00
parent c33a63aa90
commit c7ef818454

View File

@@ -1,4 +1,4 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
@@ -14,6 +14,8 @@ import { NotificationsServiceStub } from '../../shared/testing/notifications-ser
import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock'; import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
import { RequestService } from '../../core/data/request.service'; import { RequestService } from '../../core/data/request.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { TestScheduler } from 'rxjs/testing';
import { getTestScheduler } from 'jasmine-marbles';
describe('ProcessFormComponent', () => { describe('ProcessFormComponent', () => {
let component: ProcessFormComponent; let component: ProcessFormComponent;
@@ -21,6 +23,9 @@ describe('ProcessFormComponent', () => {
let scriptService; let scriptService;
let parameterValues; let parameterValues;
let script; let script;
let scheduler: TestScheduler;
let requestService: RequestService;
let router: Router;
function init() { function init() {
const param1 = new ScriptParameter(); const param1 = new ScriptParameter();
@@ -41,10 +46,18 @@ describe('ProcessFormComponent', () => {
} }
}) })
} }
) );
requestService = jasmine.createSpyObj('requestService', {
removeByHrefSubstring: jasmine.createSpy('removeByHrefSubstring')
});
router = jasmine.createSpyObj('requestService', {
navigateByUrl: jasmine.createSpy('navigateByUrl')
});
} }
beforeEach(async(() => { beforeEach(() => {
init(); init();
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
@@ -59,15 +72,16 @@ describe('ProcessFormComponent', () => {
providers: [ providers: [
{ provide: ScriptDataService, useValue: scriptService }, { provide: ScriptDataService, useValue: scriptService },
{ provide: NotificationsService, useClass: NotificationsServiceStub }, { provide: NotificationsService, useClass: NotificationsServiceStub },
{ provide: RequestService, useValue: jasmine.createSpyObj('requestService', ['removeBySubstring']) }, { provide: RequestService, useValue: requestService },
{ provide: Router, useValue: {} }, { provide: Router, useValue: router },
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}) })
.compileComponents(); .compileComponents();
})); });
beforeEach(() => { beforeEach(() => {
scheduler = getTestScheduler();
fixture = TestBed.createComponent(ProcessFormComponent); fixture = TestBed.createComponent(ProcessFormComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
component.parameters = parameterValues; component.parameters = parameterValues;
@@ -75,13 +89,15 @@ describe('ProcessFormComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should create', (done) => { it('should create', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
done();
}); });
it('should call invoke on the scriptService on submit', () => { it('should call invoke on the scriptService on submit', (done) => {
component.submitForm({ controls: {} } as any); scheduler.schedule(() => component.submitForm({ controls: {} } as any));
scheduler.flush();
expect(scriptService.invoke).toHaveBeenCalled(); expect(scriptService.invoke).toHaveBeenCalled();
done();
}); });
}); });