summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/run/run-report/run-report.component.spec.ts
blob: e147642124ab5ab69066404e74807891ee585c84 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatSortModule } from '@angular/material/sort';
import { MatTableModule, MatTableDataSource } from '@angular/material/table';

import { RunReportComponent, PeriodicElement } from './run-report.component';
import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SimpleChange, SimpleChanges } from '@angular/core';
import { MatMenuModule } from '@angular/material';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { RunService } from '../run.service';
import 'rxjs/add/observable/empty';
import 'rxjs/add/observable/of';
import { Observable } from 'rxjs';

describe('RunReportComponent', () => {
  let component: RunReportComponent;
  let fixture: ComponentFixture<RunReportComponent>;
  const displayedColumnsArr1 = [];
  const DashboardReportObj1 = [];
  const trigger = ["a","b"];
  let change : SimpleChanges;
  let runService : RunService;
  let options1 = {};
  let dashboard; 
  let dashboard2; 
  let responseformfield = 1;
  let environment = [
    {
      baseUrl: 'just a link'
    }
  ]


  beforeEach(async(() => {
    TestBed.configureTestingModule({
      schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
      declarations: [ RunReportComponent ],
      imports: [
        NoopAnimationsModule,
        MatPaginatorModule,
        MatSortModule,
        MatTableModule,
        MatMenuModule,
        HttpClientTestingModule,
        RouterTestingModule
      ],
      providers: [RunService]
    }).compileComponents();
    runService = TestBed.get(RunService);
    //spyOn(runService, 'getReportDataWithFormFields').and.returnValue(Observable.of(environment));
    //spyOn(runService, 'getReportData').and.returnValue(Observable.of(environment));
    spyOn(runService, 'downloadReportExcel').and.returnValue(Observable.of(environment));
  }));

  beforeEach(() => {
    //dashboard = {"item":{"hasContent":{"name":"rupi","id":"check#check"}}};
    fixture = TestBed.createComponent(RunReportComponent);
    runService = TestBed.get(RunService);
    component = fixture.componentInstance;
    component.DashboardReportObj = DashboardReportObj1;
    component.displayedColumnsArr = displayedColumnsArr1;
    component.TriggerFFArr = trigger;
    component.options = options1;
    component.dashboard = dashboard; 
    component.responseFormFieldListLength = responseformfield;
    //fixture.detectChanges();
  });

  it('should compile', () => {
      expect(component).toBeTruthy(); 
  });
 
  it('should test the ngOnChanges second If condition', () => {    
    component.queryString = "test"
    component.runButtonHitCnt = 1;
    component.initialQueryString = "abc";
    component.initCounter = 4;
    component.hitCnt = 2;
    component.ngOnChanges(change);

    expect(component.runButtonHitCnt).toEqual(component.hitCnt);
    expect(component.initialQueryString).toEqual("test");
    spyOn(component, 'initialProcesses');
    spyOn(component, 'afterViewInitialProcesses');
    component.initialProcesses();
    component.afterViewInitialProcesses();

    expect(component.initialProcesses).toHaveBeenCalled();
    expect(component.afterViewInitialProcesses).toHaveBeenCalled();
});

  it('should test afterViewInitialProcesses method', () => {
      component.DashboardReportObj.length = 0;
      component.reportMode = "Regular";
      component.initCnt = 0;
      component.afterViewInitialProcesses();

      expect(component.showMoreVert).toEqual(false);
      expect(component.displayedColumnsArr).toEqual(new Array());
      expect(component.displayedRowObj).toEqual(new Array());
      expect(component.displayedColumns).toEqual(new Array());
      expect(component.formFieldList).toEqual(new Array());
      expect(component.showSpinner).toEqual(true);
      expect(component.isReady).toEqual(false);
      expect(component.NEWdisplayedColumns).toEqual(new Array());
  });

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

  it('should test linkToReport', () => {
        component.linkToReport("test", "abc");
  })

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

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


  it('should test applyFilter method', () => {
      let filterValue = "test"
      component.applyFilter(filterValue);
      expect(component.dataSource.filter).toEqual(filterValue.trim().toLowerCase());
  });

   it('should test the ngOnChanges first If condition', () => {   
    change = {};
        component.reportMode !== "Regular"
        component.initCnt = 1;
        component.TriggerFFArr.length = 0;
        component.ngOnChanges(change);
        expect(component.showMoreVert).toEqual(false);
        expect(component.initCnt).toEqual(1);
        expect(component.showDashboardReport).toEqual(false);
        expect(component.displayedRowObj).toEqual(new Array());
        expect(component.displayedColumns).toEqual(new Array());
        expect(component.formFieldList).toEqual(new Array());
        expect(component.showSpinner).toEqual(true);
        expect(component.NEWdisplayedColumns).toEqual(new Array());
        expect(component.isReady).toEqual(false);
  });

   it('should test initialProcess method', () => {
      component.DashboardReportObj.length = 1;
      component.initialProcesses();
  });

  // it('should test postFetchingReportDataFn method', () => {
  //     let response: any;
  //     component.postFetchingReportDataFn(response);
  // })

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

  // it('should test postFetchingReportDataFn method', () => {
  //   let obj: any;
  //     component.postFetchingReportDataFn(obj);
  // })
  
});