0e1d326dfa22c6f309b9be203566d3aedec66fe9
[portal/sdk.git] /
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';
12
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;
19   let environment = [
20     {
21       baseUrl: 'just for testing'
22     }
23   ];
24   var responseDefPage={
25                        "reportName":"reportName",
26                       "reportType":"reportType",
27                         }
28     
29   var responseFormFieldGroups={"formFieldGroupsJSON":'{"Indrijeet":"kumar"}'};
30   var respObj={"formFieldList":{"value1":"value1"}};
31
32   beforeEach(async(() => {
33     TestBed.configureTestingModule({
34       schemas: [CUSTOM_ELEMENTS_SCHEMA],
35       imports: [
36                 FormsModule, 
37                 MatDatepickerModule, 
38                 HttpClientTestingModule, 
39                 RouterTestingModule
40               ],
41       declarations: [ RunReportFormFieldsComponent ],
42       providers: [RunService]
43     })
44     .compileComponents();
45     runService = TestBed.get(RunService);
46      spyOn(runService, 'refreshFormFields').and.returnValue(Observable.of(environment));   
47   }));
48
49   beforeEach(() => {
50     fixture = TestBed.createComponent(RunReportFormFieldsComponent);
51     component = fixture.componentInstance;
52      component.formFieldList = formfield;
53     fixture.detectChanges();
54     activatedRoute=TestBed.get(ActivatedRoute);
55   });
56
57   it('should create', () => {
58     expect(component).toBeTruthy();
59   });
60
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));
68     component.ngOnInit();
69   })
70  
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"
77                 }
78     spyOn(runService,'getDefinitionPageDetails').and.returnValue(Observable.of(responseDefPage));
79     spyOn(runService,'getReportData').and.returnValue(Observable.of(response));
80     component.ngOnInit();
81   })
82
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));
89     component.ngOnInit();
90   })
91
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));
96     component.ngOnInit();
97   })
98
99  describe('should test the else part under subscribe in ngOnInit method',()=>{
100
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"}',
108       "formFieldList":""
109     };
110     spyOn(runService,'getDefinitionPageDetails').and.returnValue(Observable.of(responseDefPage));
111     spyOn(runService,'getReportData').and.returnValue(Observable.of(response));
112     component.ngOnInit();
113   })
114 })
115
116 })
117   
118   it('should test ngOnInit method', () => {
119         spyOn(component, 'ngOnInit').and.callThrough();
120         component.ngOnInit();
121         expect(component.ngOnInit).toHaveBeenCalled();
122   });
123
124   it('should test convertDate method', () => {
125       component.convertDate("test");
126   });
127
128   it('should test getQueryString methods', () => {
129     component.directCallQueryParams = 'abc';    
130     component.getQueryString();
131     expect(component.getQueryString()).toEqual(component.directCallQueryParams);
132
133     component.directCallQueryParams = "";    
134     component.getQueryString();
135     expect(component.getQueryString()).toEqual(component.queryString);
136   });
137
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);
144   });
145
146   it('should test showLabelFn method', () => {
147     component.showLabelFn();
148     expect(component.showLabel).toEqual(component.showLabel);
149   });
150
151   it('should test editReport method', () => {
152         component.editReport("test");
153   });
154
155    it('should test runReport method', () => {
156       component.iSDashboardReport = "test";
157       component.formFieldList.length = 1;
158        component.runReport();
159
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);
166
167       component.iSDashboardReport = "test";
168       component.formFieldList.length = 0;
169        component.runReport();
170
171        expect(component.reportMode).toBe("Regular");
172
173        component.iSDashboardReport = "Dashboard";
174        component.runReport();
175        expect(component.showSpinner).toBe(false);
176        expect(component.navigateToRun).toBe(true);
177
178
179    });
180
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);
190    });
191
192    it('should test generateQueryString method',() => {
193       component.generateQueryString();
194    })     
195
196
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");
201  });
202
203 });