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';
11 import { of } from 'rxjs';
13 describe('RunReportFormFieldsComponent', () => {
14 let component: RunReportFormFieldsComponent;
15 let fixture: ComponentFixture<RunReportFormFieldsComponent>;
16 let formfield =[{"validationType":1},{},{}] ;
17 let runService: RunService;
20 baseUrl: 'just for testing'
23 var responseFormFieldGroups={"formFieldGroupsJSON":'{"Indrijeet":"kumar"}'};
24 var respObj={"formFieldList":{"value1":"value1"}};
26 beforeEach(async(() => {
27 TestBed.configureTestingModule({
28 schemas: [CUSTOM_ELEMENTS_SCHEMA],
29 imports: [FormsModule, MatDatepickerModule, HttpClientTestingModule, RouterTestingModule],
30 declarations: [ RunReportFormFieldsComponent ],
31 providers: [RunService]
34 runService = TestBed.get(RunService);
35 spyOn(runService, 'getDefinitionPageDetails').and.returnValue(Observable.of(environment));
36 spyOn(runService, 'refreshFormFields').and.returnValue(Observable.of(environment));
41 fixture = TestBed.createComponent(RunReportFormFieldsComponent);
42 component = fixture.componentInstance;
43 component.formFieldList = formfield;
44 fixture.detectChanges();
47 it('should create', () => {
48 expect(component).toBeTruthy();
51 it('should test convertDate method', () => {
52 component.convertDate("test");
55 it('should test getQueryString methods', () => {
56 component.directCallQueryParams = 'abc';
57 component.getQueryString();
58 expect(component.getQueryString()).toEqual(component.directCallQueryParams);
60 component.directCallQueryParams = "";
61 component.getQueryString();
62 expect(component.getQueryString()).toEqual(component.queryString);
65 it('should test showError method', () => {
66 component.showError('test');
67 expect(component.errorMessage).toEqual('test'['errormessage']);
68 expect(component.stackTrace).toEqual('test'['stacktrace']);
69 expect(component.error).toEqual(true);
70 expect(component.showSpinner).toEqual(false);
73 it('should test showLabelFn method', () => {
74 component.showLabelFn();
75 expect(component.showLabel).toEqual(component.showLabel);
78 it('should test editReport method', () => {
79 component.editReport("test");
82 it('should test runReport method', () => {
83 component.iSDashboardReport = "test";
84 component.formFieldList.length = 1;
85 component.runReport();
87 expect(component.hitCnt).toBe(component.hitCnt++);
88 expect(component.reportMode).toBe("FormField");
89 let spy = spyOn(component, 'generateQueryString');
90 component.generateQueryString();
91 expect(component.generateQueryString).toHaveBeenCalled();
92 expect(component.showSpinner).toBe(false);
94 component.iSDashboardReport = "test";
95 component.formFieldList.length = 0;
96 component.runReport();
98 expect(component.reportMode).toBe("Regular");
100 component.iSDashboardReport = "Dashboard";
101 component.runReport();
102 expect(component.showSpinner).toBe(false);
103 expect(component.navigateToRun).toBe(true);
108 it('should test ngDoCheck method', () =>{
109 component.formFieldList != undefined;
110 component.oldGroupSelectValue = "test";
111 component.groupSelectValue = "testing";
112 // component.toggleFormFieldRenderArr.length = 1;
113 spyOn(component, 'ngDoCheck').and.callThrough();
114 component.ngDoCheck();
115 expect(component.ngDoCheck).toHaveBeenCalled();
116 expect(component.oldGroupSelectValue).toBe(component.groupSelectValue);
119 it('should test generateQueryString method',() => {
120 component.generateQueryString();
123 it('should test ngOnInit method', () => {
124 spyOn(component, 'ngOnInit').and.callThrough();
125 component.ngOnInit();
126 expect(component.ngOnInit).toHaveBeenCalled();
129 it('should test fetchAndPopulateFormFields method', () => {
130 component.formFieldGroupObjList=[{"formFieldList":"formFieldList"}]
131 spyOn(runService, 'getFormFieldGroupsData').and.returnValue(Observable.of(responseFormFieldGroups));
132 component.fetchAndPopulateFormFields(respObj,"value2");