summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/run/run-report-form-fields/run-report-form-fields.component.spec.ts
blob: 54df7d82b675d533df46bae658d3830257a9100e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import {FormsModule} from '@angular/forms';
import { RunReportFormFieldsComponent } from './run-report-form-fields.component';
import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
import {MatDatepickerModule} from '@angular/material/datepicker'; 
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { RunService } from '../run.service';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import { of } from 'rxjs';

describe('RunReportFormFieldsComponent', () => {
  let component: RunReportFormFieldsComponent;
  let fixture: ComponentFixture<RunReportFormFieldsComponent>;
  let formfield =[{"validationType":1},{},{}] ;
  let runService: RunService;
  let environment = [
    {
      baseUrl: 'just for testing'
    }
  ];
  var responseFormFieldGroups={"formFieldGroupsJSON":'{"Indrijeet":"kumar"}'};
  var respObj={"formFieldList":{"value1":"value1"}};

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
      imports: [FormsModule, MatDatepickerModule, HttpClientTestingModule, RouterTestingModule],
      declarations: [ RunReportFormFieldsComponent ],
      providers: [RunService]
    })
    .compileComponents();
    runService = TestBed.get(RunService);
     spyOn(runService, 'getDefinitionPageDetails').and.returnValue(Observable.of(environment));
     spyOn(runService, 'refreshFormFields').and.returnValue(Observable.of(environment));
     
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(RunReportFormFieldsComponent);
    component = fixture.componentInstance;
     component.formFieldList = formfield;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should test convertDate method', () => {
      component.convertDate("test");
  });

  it('should test getQueryString methods', () => {
    component.directCallQueryParams = 'abc';    
    component.getQueryString();
    expect(component.getQueryString()).toEqual(component.directCallQueryParams);

    component.directCallQueryParams = "";    
    component.getQueryString();
    expect(component.getQueryString()).toEqual(component.queryString);
  });

  it('should test showError method', () => {
      component.showError('test');
      expect(component.errorMessage).toEqual('test'['errormessage']);
      expect(component.stackTrace).toEqual('test'['stacktrace']);
      expect(component.error).toEqual(true);
      expect(component.showSpinner).toEqual(false);
  });

  it('should test showLabelFn method', () => {
    component.showLabelFn();
    expect(component.showLabel).toEqual(component.showLabel);
  });

  it('should test editReport method', () => {
        component.editReport("test");
  });

   it('should test runReport method', () => {
      component.iSDashboardReport = "test";
      component.formFieldList.length = 1;
       component.runReport();

      expect(component.hitCnt).toBe(component.hitCnt++);
      expect(component.reportMode).toBe("FormField");
      let spy = spyOn(component, 'generateQueryString');
      component.generateQueryString();
      expect(component.generateQueryString).toHaveBeenCalled();
      expect(component.showSpinner).toBe(false);

      component.iSDashboardReport = "test";
      component.formFieldList.length = 0;
       component.runReport();

       expect(component.reportMode).toBe("Regular");

       component.iSDashboardReport = "Dashboard";
       component.runReport();
       expect(component.showSpinner).toBe(false);
       expect(component.navigateToRun).toBe(true);


   });

   it('should test ngDoCheck method', () =>{
        component.formFieldList != undefined;
        component.oldGroupSelectValue = "test";
        component.groupSelectValue = "testing";
       // component.toggleFormFieldRenderArr.length = 1;
        spyOn(component, 'ngDoCheck').and.callThrough();
        component.ngDoCheck();
        expect(component.ngDoCheck).toHaveBeenCalled();
        expect(component.oldGroupSelectValue).toBe(component.groupSelectValue);
   });

   it('should test generateQueryString method',() => {
      component.generateQueryString();
   })     

   it('should test ngOnInit method', () => {
    spyOn(component, 'ngOnInit').and.callThrough();
        component.ngOnInit();
        expect(component.ngOnInit).toHaveBeenCalled();
  });

  it('should test fetchAndPopulateFormFields method', () => {
    component.formFieldGroupObjList=[{"formFieldList":"formFieldList"}]
    spyOn(runService, 'getFormFieldGroupsData').and.returnValue(Observable.of(responseFormFieldGroups));
    component.fetchAndPopulateFormFields(respObj,"value2");
 });

});