1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 import {FormsModule} from '@angular/forms';
3 import { RunReportFormFieldsComponent } from './run-report-form-fields.component';
4 import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
5 import {MatDatepickerModule} from '@angular/material/datepicker';
6 import { HttpClientTestingModule } from '@angular/common/http/testing';
7 import { RouterTestingModule } from '@angular/router/testing';
8 import { RunService } from '../run.service';
9 import { Observable } from 'rxjs/Observable';
10 import 'rxjs/add/observable/of';
12 describe('RunReportFormFieldsComponent', () => {
13 let component: RunReportFormFieldsComponent;
14 let fixture: ComponentFixture<RunReportFormFieldsComponent>;
15 let formfield =[{"validationType":1},{},{}] ;
16 let runService: RunService;
17 let formFieldGroupObjList: {}[] = [];
20 baseUrl: 'just for testing'
24 beforeEach(async(() => {
25 TestBed.configureTestingModule({
26 schemas: [CUSTOM_ELEMENTS_SCHEMA],
27 imports: [FormsModule, MatDatepickerModule, HttpClientTestingModule, RouterTestingModule],
28 declarations: [ RunReportFormFieldsComponent ],
29 providers: [RunService]
32 runService = TestBed.get(RunService);
33 spyOn(runService, 'getDefinitionPageDetails').and.returnValue(Observable.of(environment));
34 spyOn(runService, 'refreshFormFields').and.returnValue(Observable.of(environment));
35 spyOn(runService, 'getFormFieldGroupsData').and.returnValue(Observable.of(environment));
39 fixture = TestBed.createComponent(RunReportFormFieldsComponent);
40 component = fixture.componentInstance;
41 component.formFieldList = formfield;
42 component.formFieldGroupObjList = formFieldGroupObjList;
43 fixture.detectChanges();
46 it('should create', () => {
47 expect(component).toBeTruthy();
50 it('should test convertDate method', () => {
51 component.convertDate("test");
54 it('should test getQueryString methods', () => {
55 component.directCallQueryParams = 'abc';
56 component.getQueryString();
57 expect(component.getQueryString()).toEqual(component.directCallQueryParams);
59 component.directCallQueryParams = "";
60 component.getQueryString();
61 expect(component.getQueryString()).toEqual(component.queryString);
64 it('should test showError method', () => {
65 component.showError('test');
66 expect(component.errorMessage).toEqual('test'['errormessage']);
67 expect(component.stackTrace).toEqual('test'['stacktrace']);
68 expect(component.error).toEqual(true);
69 expect(component.showSpinner).toEqual(false);
72 it('should test showLabelFn method', () => {
73 component.showLabelFn();
74 expect(component.showLabel).toEqual(component.showLabel);
77 it('should test runReport method', () => {
78 component.iSDashboardReport = "Dashboard";
79 component.formFieldList.length = 1;
80 component.runReport();
82 expect(component.hitCnt).toBe(component.hitCnt++);
83 expect(component.reportMode).toBe('')
84 let spy = spyOn(component, 'generateQueryString');
85 component.generateQueryString();
86 expect(component.generateQueryString).toHaveBeenCalled();
87 expect(component.showSpinner).toBe(false);
89 component.iSDashboardReport = "Dashboard";
90 component.formFieldList.length = 0;
91 component.runReport();
93 expect(component.reportMode).toBe('');
95 component.iSDashboardReport = "Dashboard";
96 component.runReport();
97 expect(component.showSpinner).toBe(false);
98 expect(component.navigateToRun).toBe(true);
103 it('should test ngDoCheck method', () =>{
104 component.formFieldList != undefined;
105 component.oldGroupSelectValue = "test";
106 component.groupSelectValue = "testing";
107 spyOn(component, 'ngDoCheck').and.callThrough();
108 component.ngDoCheck();
109 expect(component.ngDoCheck).toHaveBeenCalled();
110 expect(component.oldGroupSelectValue).toBe(component.groupSelectValue);
113 it('should test generateQueryString method',() => {
114 component.generateQueryString();
117 it('should test ngOnInit method', () => {
118 spyOn(component, 'ngOnInit').and.callThrough();
119 component.ngOnInit();
120 expect(component.ngOnInit).toHaveBeenCalled();