640128ce4e3ed123f09244bbef852d41b2a82bad
[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
12 describe('RunReportFormFieldsComponent', () => {
13   let component: RunReportFormFieldsComponent;
14   let fixture: ComponentFixture<RunReportFormFieldsComponent>;
15   let formfield =[{"validationType":1},{},{}] ;
16   let runService: RunService;
17   let formFieldGroupObjList: {}[] = [];
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, 'getDefinitionPageDetails').and.returnValue(Observable.of(environment));
34      spyOn(runService, 'refreshFormFields').and.returnValue(Observable.of(environment));
35      spyOn(runService, 'getFormFieldGroupsData').and.returnValue(Observable.of(environment));
36   }));
37
38   beforeEach(() => {
39     fixture = TestBed.createComponent(RunReportFormFieldsComponent);
40     component = fixture.componentInstance;
41     component.formFieldList = formfield;
42     component.formFieldGroupObjList = formFieldGroupObjList;
43     fixture.detectChanges();
44   });
45
46   it('should create', () => {
47     expect(component).toBeTruthy();
48   });
49
50   it('should test convertDate method', () => {
51       component.convertDate("test");
52   });
53
54   it('should test getQueryString methods', () => {
55     component.directCallQueryParams = 'abc';    
56     component.getQueryString();
57     expect(component.getQueryString()).toEqual(component.directCallQueryParams);
58
59     component.directCallQueryParams = "";    
60     component.getQueryString();
61     expect(component.getQueryString()).toEqual(component.queryString);
62   });
63
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);
70   });
71
72   it('should test showLabelFn method', () => {
73     component.showLabelFn();
74     expect(component.showLabel).toEqual(component.showLabel);
75   });
76
77   it('should test runReport method', () => {
78       component.iSDashboardReport = "Dashboard";
79       component.formFieldList.length = 1;
80       component.runReport();
81
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);
88
89       component.iSDashboardReport = "Dashboard";
90       component.formFieldList.length = 0;
91       component.runReport();
92
93        expect(component.reportMode).toBe('');
94
95        component.iSDashboardReport = "Dashboard";
96        component.runReport();
97        expect(component.showSpinner).toBe(false);
98        expect(component.navigateToRun).toBe(true);
99
100
101    });
102
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);
111    });
112
113    it('should test generateQueryString method',() => {
114       component.generateQueryString();
115    })     
116
117    it('should test ngOnInit method', () => {
118     spyOn(component, 'ngOnInit').and.callThrough();
119         component.ngOnInit();
120         expect(component.ngOnInit).toHaveBeenCalled();
121   });
122
123 });