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} 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 { ActivatedRoute } from '@angular/router';
13 describe('RunReportFormFieldsComponent', () => {
14 let component: RunReportFormFieldsComponent;
15 let fixture: ComponentFixture<RunReportFormFieldsComponent>;
16 let formfield =[{"validationType":1},{},{}] ;
17 let runService: RunService;
18 let activatedRoute:ActivatedRoute;
21 baseUrl: 'just for testing'
25 "reportName":"reportName",
26 "reportType":"reportType",
29 var responseFormFieldGroups={"formFieldGroupsJSON":'{"Indrijeet":"kumar"}'};
30 var respObj={"formFieldList":{"value1":"value1"}};
32 beforeEach(async(() => {
33 TestBed.configureTestingModule({
34 schemas: [CUSTOM_ELEMENTS_SCHEMA],
38 HttpClientTestingModule,
41 declarations: [ RunReportFormFieldsComponent ],
42 providers: [RunService]
45 runService = TestBed.get(RunService);
46 spyOn(runService, 'refreshFormFields').and.returnValue(Observable.of(environment));
50 fixture = TestBed.createComponent(RunReportFormFieldsComponent);
51 component = fixture.componentInstance;
52 component.formFieldList = formfield;
53 fixture.detectChanges();
54 activatedRoute=TestBed.get(ActivatedRoute);
57 it('should create', () => {
58 expect(component).toBeTruthy();
61 describe('should test subscribe method in ngOnInit method',()=>{
62 it('should test first if condition inside the subscribe',()=>{
63 component.reportId="reportId";
64 component.calledWithFormFields=false;
65 var response={"errormessage":true};
66 spyOn(runService,'getDefinitionPageDetails').and.returnValue(Observable.of(responseDefPage));
67 spyOn(runService,'getReportData').and.returnValue(Observable.of(response));
71 it('should test first if inside first if condition inside the subscribe',()=>{
72 component.reportId="reportId";
73 component.calledWithFormFields=false;
74 var response={"errormessage":false,
75 "reportName":"reportName",
76 "formFieldList":"formFieldList"
78 spyOn(runService,'getDefinitionPageDetails').and.returnValue(Observable.of(responseDefPage));
79 spyOn(runService,'getReportData').and.returnValue(Observable.of(response));
83 it('should test else part line 101',()=>{
84 component.reportId="reportId";
85 component.calledWithFormFields=false;
86 var response={"errormessage":false,"reportName":"reportName","formFieldList":""}
87 spyOn(runService,'getDefinitionPageDetails').and.returnValue(Observable.of(responseDefPage));
88 spyOn(runService,'getReportData').and.returnValue(Observable.of(response));
92 it('should test the else part line 111',()=>{
93 component.reportId="reportId";
94 component.calledWithFormFields=true;
95 spyOn(runService,'getDefinitionPageDetails').and.returnValue(Observable.of(responseDefPage));
99 describe('should test the else part under subscribe in ngOnInit method',()=>{
101 it('should test the else part 142',()=>{
102 component.reportId="reportId";
103 var response={"errormessage":false,"formFieldList":"formFieldList"};
104 var responseDefPage={
105 "reportName":"reportName",
106 "reportType":"Dashboard",
107 "dashboardLayoutJSON":'{"data":"dat"}',
110 spyOn(runService,'getDefinitionPageDetails').and.returnValue(Observable.of(responseDefPage));
111 spyOn(runService,'getReportData').and.returnValue(Observable.of(response));
112 component.ngOnInit();
118 it('should test ngOnInit method', () => {
119 spyOn(component, 'ngOnInit').and.callThrough();
120 component.ngOnInit();
121 expect(component.ngOnInit).toHaveBeenCalled();
124 it('should test convertDate method', () => {
125 component.convertDate("test");
128 it('should test getQueryString methods', () => {
129 component.directCallQueryParams = 'abc';
130 component.getQueryString();
131 expect(component.getQueryString()).toEqual(component.directCallQueryParams);
133 component.directCallQueryParams = "";
134 component.getQueryString();
135 expect(component.getQueryString()).toEqual(component.queryString);
138 it('should test showError method', () => {
139 component.showError('test');
140 expect(component.errorMessage).toEqual('test'['errormessage']);
141 expect(component.stackTrace).toEqual('test'['stacktrace']);
142 expect(component.error).toEqual(true);
143 expect(component.showSpinner).toEqual(false);
146 it('should test showLabelFn method', () => {
147 component.showLabelFn();
148 expect(component.showLabel).toEqual(component.showLabel);
151 it('should test editReport method', () => {
152 component.editReport("test");
155 it('should test runReport method', () => {
156 component.iSDashboardReport = "test";
157 component.formFieldList.length = 1;
158 component.runReport();
160 expect(component.hitCnt).toBe(component.hitCnt++);
161 expect(component.reportMode).toBe("FormField");
162 let spy = spyOn(component, 'generateQueryString');
163 component.generateQueryString();
164 expect(component.generateQueryString).toHaveBeenCalled();
165 expect(component.showSpinner).toBe(false);
167 component.iSDashboardReport = "test";
168 component.formFieldList.length = 0;
169 component.runReport();
171 expect(component.reportMode).toBe("Regular");
173 component.iSDashboardReport = "Dashboard";
174 component.runReport();
175 expect(component.showSpinner).toBe(false);
176 expect(component.navigateToRun).toBe(true);
181 it('should test ngDoCheck method', () =>{
182 component.formFieldList != undefined;
183 component.oldGroupSelectValue = "test";
184 component.groupSelectValue = "testing";
185 // component.toggleFormFieldRenderArr.length = 1;
186 spyOn(component, 'ngDoCheck').and.callThrough();
187 component.ngDoCheck();
188 expect(component.ngDoCheck).toHaveBeenCalled();
189 expect(component.oldGroupSelectValue).toBe(component.groupSelectValue);
192 it('should test generateQueryString method',() => {
193 component.generateQueryString();
197 it('should test fetchAndPopulateFormFields method', () => {
198 component.formFieldGroupObjList=[{"formFieldList":"formFieldList"}]
199 spyOn(runService, 'getFormFieldGroupsData').and.returnValue(Observable.of(responseFormFieldGroups));
200 component.fetchAndPopulateFormFields(respObj,"value2");