From c7ef818454c9c6cf671c3f5b310619ff75365b44 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Thu, 16 Jul 2020 14:35:57 +0200 Subject: [PATCH] [CST-3088] fix ProcessFormComponent test --- .../form/process-form.component.spec.ts | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/app/process-page/form/process-form.component.spec.ts b/src/app/process-page/form/process-form.component.spec.ts index d32405d8bf..97423c8617 100644 --- a/src/app/process-page/form/process-form.component.spec.ts +++ b/src/app/process-page/form/process-form.component.spec.ts @@ -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 { 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 { RequestService } from '../../core/data/request.service'; import { Router } from '@angular/router'; +import { TestScheduler } from 'rxjs/testing'; +import { getTestScheduler } from 'jasmine-marbles'; describe('ProcessFormComponent', () => { let component: ProcessFormComponent; @@ -21,6 +23,9 @@ describe('ProcessFormComponent', () => { let scriptService; let parameterValues; let script; + let scheduler: TestScheduler; + let requestService: RequestService; + let router: Router; function init() { 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(); TestBed.configureTestingModule({ imports: [ @@ -59,15 +72,16 @@ describe('ProcessFormComponent', () => { providers: [ { provide: ScriptDataService, useValue: scriptService }, { provide: NotificationsService, useClass: NotificationsServiceStub }, - { provide: RequestService, useValue: jasmine.createSpyObj('requestService', ['removeBySubstring']) }, - { provide: Router, useValue: {} }, + { provide: RequestService, useValue: requestService }, + { provide: Router, useValue: router }, ], schemas: [NO_ERRORS_SCHEMA] }) .compileComponents(); - })); + }); beforeEach(() => { + scheduler = getTestScheduler(); fixture = TestBed.createComponent(ProcessFormComponent); component = fixture.componentInstance; component.parameters = parameterValues; @@ -75,13 +89,15 @@ describe('ProcessFormComponent', () => { fixture.detectChanges(); }); - it('should create', (done) => { + it('should create', () => { expect(component).toBeTruthy(); - done(); }); - it('should call invoke on the scriptService on submit', () => { - component.submitForm({ controls: {} } as any); + it('should call invoke on the scriptService on submit', (done) => { + scheduler.schedule(() => component.submitForm({ controls: {} } as any)); + scheduler.flush(); + expect(scriptService.invoke).toHaveBeenCalled(); + done(); }); });