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'
24 beforeEach(async(() => {
25 TestBed.configureTestingModule({
26 schemas: [CUSTOM_ELEMENTS_SCHEMA],
27 imports: [FormsModule, MatDatepickerModule, HttpClientTestingModule, RouterTestingModule],
28 declarations: [ RunReportFormFieldsComponent ],
29 providers: [RunService]
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));
42 fixture = TestBed.createComponent(RunReportFormFieldsComponent);
43 component = fixture.componentInstance;
44 component.formFieldList = formfield;
45 fixture.detectChanges();
48 it('should create', () => {
49 expect(component).toBeTruthy();
52 it('should test convertDate method', () => {
53 component.convertDate("test");
56 it('should test getQueryString methods', () => {
57 component.directCallQueryParams = 'abc';
58 component.getQueryString();
59 expect(component.getQueryString()).toEqual(component.directCallQueryParams);
61 component.directCallQueryParams = "";
62 component.getQueryString();
63 expect(component.getQueryString()).toEqual(component.queryString);
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);
74 it('should test showLabelFn method', () => {
75 component.showLabelFn();
76 expect(component.showLabel).toEqual(component.showLabel);
79 it('should test editReport method', () => {
80 component.editReport("test");
83 it('should test runReport method', () => {
84 component.iSDashboardReport = "test";
85 component.formFieldList.length = 1;
86 component.runReport();
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);
95 component.iSDashboardReport = "test";
96 component.formFieldList.length = 0;
97 component.runReport();
99 expect(component.reportMode).toBe("Regular");
101 component.iSDashboardReport = "Dashboard";
102 component.runReport();
103 expect(component.showSpinner).toBe(false);
104 expect(component.navigateToRun).toBe(true);
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);
120 it('should test generateQueryString method',() => {
121 component.generateQueryString();
124 it('should test ngOnInit method', () => {
125 spyOn(component, 'ngOnInit').and.callThrough();
126 component.ngOnInit();
127 expect(component.ngOnInit).toHaveBeenCalled();
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();