a1906c85a923d2231bd095c1b0b15ad803ee7ffc
[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, 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';
12
13 describe('RunReportFormFieldsComponent', () => {
14   let component: RunReportFormFieldsComponent;
15   let fixture: ComponentFixture<RunReportFormFieldsComponent>;
16   let formfield =[{"validationType":1},{},{}] ;
17   let runService: RunService;
18   let environment = [
19     {
20       baseUrl: 'just for testing'
21     }
22   ]
23
24   beforeEach(async(() => {
25     TestBed.configureTestingModule({
26       schemas: [CUSTOM_ELEMENTS_SCHEMA],
27       imports: [FormsModule, MatDatepickerModule, HttpClientTestingModule, RouterTestingModule],
28       declarations: [ RunReportFormFieldsComponent ],
29       providers: [RunService]
30     })
31     .compileComponents();
32     runService = TestBed.get(RunService);
33     // spyOn(runService, 'getReportData').and.returnValue(Observable.of(environment));
34     // spyOn(runService, 'getReportDataWithFormFields').and.returnValue(Observable.of(environment));
35      spyOn(runService, 'getDefinitionPageDetails').and.returnValue(Observable.of(environment));
36      spyOn(runService, 'refreshFormFields').and.returnValue(Observable.of(environment));
37     // spyOn(runService, 'downloadReportExcel').and.returnValue(Observable.of(environment));
38      spyOn(runService, 'getFormFieldGroupsData').and.returnValue(Observable.of(environment));
39   }));
40
41   beforeEach(() => {
42     fixture = TestBed.createComponent(RunReportFormFieldsComponent);
43     component = fixture.componentInstance;
44      component.formFieldList = formfield;
45     fixture.detectChanges();
46   });
47
48   it('should create', () => {
49     expect(component).toBeTruthy();
50   });
51
52   it('should test convertDate method', () => {
53       component.convertDate("test");
54   });
55
56   it('should test getQueryString methods', () => {
57     component.directCallQueryParams = 'abc';    
58     component.getQueryString();
59     expect(component.getQueryString()).toEqual(component.directCallQueryParams);
60
61     component.directCallQueryParams = "";    
62     component.getQueryString();
63     expect(component.getQueryString()).toEqual(component.queryString);
64   });
65
66   it('should test showError method', () => {
67       component.showError('test');
68       expect(component.errorMessage).toEqual('test'['errormessage']);
69       expect(component.stackTrace).toEqual('test'['stacktrace']);
70       expect(component.error).toEqual(true);
71       expect(component.showSpinner).toEqual(false);
72   });
73
74   it('should test showLabelFn method', () => {
75     component.showLabelFn();
76     expect(component.showLabel).toEqual(component.showLabel);
77   });
78
79   it('should test editReport method', () => {
80         component.editReport("test");
81   });
82
83    it('should test runReport method', () => {
84       component.iSDashboardReport = "test";
85       component.formFieldList.length = 1;
86        component.runReport();
87
88       expect(component.hitCnt).toBe(component.hitCnt++);
89       expect(component.reportMode).toBe("FormField");
90       let spy = spyOn(component, 'generateQueryString');
91       component.generateQueryString();
92       expect(component.generateQueryString).toHaveBeenCalled();
93       expect(component.showSpinner).toBe(false);
94
95       component.iSDashboardReport = "test";
96       component.formFieldList.length = 0;
97        component.runReport();
98
99        expect(component.reportMode).toBe("Regular");
100
101        component.iSDashboardReport = "Dashboard";
102        component.runReport();
103        expect(component.showSpinner).toBe(false);
104        expect(component.navigateToRun).toBe(true);
105
106
107    });
108
109    it('should test ngDoCheck method', () =>{
110         component.formFieldList != undefined;
111         component.oldGroupSelectValue = "test";
112         component.groupSelectValue = "testing";
113        // component.toggleFormFieldRenderArr.length = 1;
114         spyOn(component, 'ngDoCheck').and.callThrough();
115         component.ngDoCheck();
116         expect(component.ngDoCheck).toHaveBeenCalled();
117         expect(component.oldGroupSelectValue).toBe(component.groupSelectValue);
118    });
119
120    it('should test generateQueryString method',() => {
121       component.generateQueryString();
122    })     
123
124    it('should test ngOnInit method', () => {
125     spyOn(component, 'ngOnInit').and.callThrough();
126         component.ngOnInit();
127         expect(component.ngOnInit).toHaveBeenCalled();
128   });
129
130 //   it('should test fetchAndPopulateFormFields method', () => {
131 //     spyOn(component, 'fetchAndPopulateFormFields').and.callThrough();
132 //     component.formFieldGroupObjList =  null;
133 //       component.fetchAndPopulateFormFields(1, "test");
134 //       expect(component.fetchAndPopulateFormFields).toHaveBeenCalled();
135 //  });
136
137 });