import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import {FormsModule} from '@angular/forms'; import { RunReportFormFieldsComponent } from './run-report-form-fields.component'; import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core'; import {MatDatepickerModule} from '@angular/material/datepicker'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { RunService } from '../run.service'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/of'; import { HttpCacheService } from 'src/app/shared/services/cache.service'; describe('RunReportFormFieldsComponent', () => { let component: RunReportFormFieldsComponent; let fixture: ComponentFixture; let formfield =[{"validationType":1},{},{}] ; let runService: RunService; let formFieldGroupObjList: {}[] = []; let environment = [ { baseUrl: 'just for testing' } ] beforeEach(async(() => { TestBed.configureTestingModule({ schemas: [CUSTOM_ELEMENTS_SCHEMA], imports: [FormsModule, MatDatepickerModule, HttpClientTestingModule, RouterTestingModule], declarations: [ RunReportFormFieldsComponent ], providers: [RunService,HttpCacheService] }) .compileComponents(); runService = TestBed.get(RunService); spyOn(runService, 'getDefinitionPageDetails').and.returnValue(Observable.of(environment)); spyOn(runService, 'refreshFormFields').and.returnValue(Observable.of(environment)); spyOn(runService, 'getFormFieldGroupsData').and.returnValue(Observable.of(environment)); })); beforeEach(() => { fixture = TestBed.createComponent(RunReportFormFieldsComponent); component = fixture.componentInstance; component.formFieldList = formfield; component.formFieldGroupObjList = formFieldGroupObjList; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); it('should test convertDate method', () => { component.convertDate("test"); }); it('should test getQueryString methods', () => { component.directCallQueryParams = 'abc'; component.getQueryString(); expect(component.getQueryString()).toEqual(component.directCallQueryParams); component.directCallQueryParams = ""; component.getQueryString(); expect(component.getQueryString()).toEqual(component.queryString); }); it('should test showError method', () => { component.showError('test'); expect(component.errorMessage).toEqual('test'['errormessage']); expect(component.stackTrace).toEqual('test'['stacktrace']); expect(component.error).toEqual(true); expect(component.showSpinner).toEqual(false); }); it('should test showLabelFn method', () => { component.showLabelFn(); expect(component.showLabel).toEqual(component.showLabel); }); it('should test runReport method', () => { component.iSDashboardReport = "Dashboard"; component.formFieldList.length = 1; component.runReport(); expect(component.hitCnt).toBe(component.hitCnt++); expect(component.reportMode).toBe('') let spy = spyOn(component, 'generateQueryString'); component.generateQueryString(); expect(component.generateQueryString).toHaveBeenCalled(); expect(component.showSpinner).toBe(false); component.iSDashboardReport = "Dashboard"; component.formFieldList.length = 0; component.runReport(); expect(component.reportMode).toBe(''); component.iSDashboardReport = "Dashboard"; component.runReport(); expect(component.showSpinner).toBe(false); expect(component.navigateToRun).toBe(true); }); it('should test ngDoCheck method', () =>{ component.formFieldList != undefined; component.oldGroupSelectValue = "test"; component.groupSelectValue = "testing"; spyOn(component, 'ngDoCheck').and.callThrough(); component.ngDoCheck(); expect(component.ngDoCheck).toHaveBeenCalled(); expect(component.oldGroupSelectValue).toBe(component.groupSelectValue); }); it('should test generateQueryString method',() => { component.generateQueryString(); }) it('should test ngOnInit method', () => { spyOn(component, 'ngOnInit').and.callThrough(); component.ngOnInit(); expect(component.ngOnInit).toHaveBeenCalled(); }); });