2aeac4a24b250888168639895004db4680f9b02e
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3 import { MatPaginatorModule } from '@angular/material/paginator';
4 import { MatSortModule } from '@angular/material/sort';
5 import { MatTableModule} from '@angular/material/table';
6
7 import { RunReportComponent} from './run-report.component';
8 import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SimpleChanges } from '@angular/core';
9 import { MatMenuModule } from '@angular/material';
10 import { HttpClientTestingModule } from '@angular/common/http/testing';
11 import { RouterTestingModule } from '@angular/router/testing';
12 import { RunService } from '../run.service';
13 import 'rxjs/add/observable/empty';
14 import 'rxjs/add/observable/of';
15 import { Observable } from 'rxjs';
16
17 describe('RunReportComponent', () => {
18   let component: RunReportComponent;
19   let fixture: ComponentFixture<RunReportComponent>;
20   const displayedColumnsArr1 = [];
21   const DashboardReportObj1 = [];
22   const trigger = ["a","b"];
23   let change : SimpleChanges;
24   let runService : RunService;
25   let options1 = {};
26   let dashboard; 
27   let responseformfield = 1;
28   let environment = [
29     {
30       baseUrl: 'just a link'
31     }
32   ];
33
34
35   beforeEach(async(() => {
36     TestBed.configureTestingModule({
37       schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
38       declarations: [ RunReportComponent ],
39       imports: [
40         NoopAnimationsModule,
41         MatPaginatorModule,
42         MatSortModule,
43         MatTableModule,
44         MatMenuModule,
45         HttpClientTestingModule,
46         RouterTestingModule
47       ],
48       providers: [RunService]
49     }).compileComponents();
50     runService = TestBed.get(RunService);
51     spyOn(runService, 'downloadReportExcel').and.returnValue(Observable.of(environment));
52   }));
53
54   beforeEach(() => {
55     fixture = TestBed.createComponent(RunReportComponent);
56     runService = TestBed.get(RunService);
57     component = fixture.componentInstance;
58     component.DashboardReportObj = DashboardReportObj1;
59     component.displayedColumnsArr = displayedColumnsArr1;
60     component.TriggerFFArr = trigger;
61     component.options = options1;
62     component.dashboard = dashboard; 
63     component.responseFormFieldListLength = responseformfield;
64     fixture.detectChanges();
65   });
66
67   it('should compile', () => {
68       expect(component).toBeTruthy(); 
69   });
70  
71   it('should test the ngOnChanges second If condition', () => {    
72     component.queryString = "test"
73     component.runButtonHitCnt = 1;
74     component.initialQueryString = "abc";
75     component.initCounter = 4;
76     component.hitCnt = 2;
77     component.ngOnChanges(change);
78
79     expect(component.runButtonHitCnt).toEqual(component.hitCnt);
80     expect(component.initialQueryString).toEqual("test");
81     spyOn(component, 'initialProcesses');
82     spyOn(component, 'afterViewInitialProcesses');
83     component.initialProcesses();
84     component.afterViewInitialProcesses();
85
86     expect(component.initialProcesses).toHaveBeenCalled();
87     expect(component.afterViewInitialProcesses).toHaveBeenCalled();
88 });
89
90   it('should test afterViewInitialProcesses method', () => {
91       component.DashboardReportObj.length = 0;
92       component.reportMode = "Regular";
93       component.initCnt = 0;
94       component.afterViewInitialProcesses();
95
96       expect(component.showMoreVert).toEqual(false);
97       expect(component.displayedColumnsArr).toEqual(new Array());
98       expect(component.displayedRowObj).toEqual(new Array());
99       expect(component.displayedColumns).toEqual(new Array());
100       expect(component.formFieldList).toEqual(new Array());
101       expect(component.showSpinner).toEqual(true);
102       expect(component.isReady).toEqual(false);
103       expect(component.NEWdisplayedColumns).toEqual(new Array());
104   });
105
106
107   it('should test showError method', () => {
108        let errmsg = "errormessage";
109        let stcktrace = "stacktrace";
110       component.showError("test");
111        expect(component.errorMessage).toEqual("test"[errmsg]);
112        expect(component.stackTrace).toEqual("test"[stcktrace]);
113        expect(component.error).toEqual(true);
114        expect(component.showSpinner).toEqual(false);
115     });
116
117   it('should test linkToReport', () => {
118         component.linkToReport("test", "abc");
119   })
120
121   it('should test linkToFeedback', () => {
122     component.linkToFeedback("test", "abc");
123   })
124
125   it('should test linkToMail', () => {
126    component.linkToMail("test");
127   })
128
129   it('should test openOptions method', () => {
130         component.openOptions();
131         expect(component.openOptionsFlag).toEqual(component.openOptionsFlag);
132   });
133
134   it('should test downloadReportExcel method', () => {
135     spyOn(component, 'downloadReportExcel').and.callThrough();
136         component.downloadReportExcel();
137         expect(component.downloadReportExcel).toHaveBeenCalled();
138   });
139
140   it('should test applyFilter method', () => {
141       let filterValue = "test"
142       component.applyFilter(filterValue);
143       expect(component.dataSource.filter).toEqual(filterValue.trim().toLowerCase());
144   });
145
146    it('should test the ngOnChanges first If condition', () => {   
147     change = {};
148     component.queryString="queryString";
149     component.reportId1="reportId1";
150     var response={"errormessage":true}
151         component.reportMode !== "Regular"
152         component.initCnt = 1;
153         component.TriggerFFArr.length = 0;
154         let spy=spyOn(runService,'getReportDataWithFormFields').and.returnValue(Observable.of(response));
155         component.ngOnChanges(change);
156         expect(spy).toHaveBeenCalled();
157         expect(component.initCnt).toEqual(1);
158         expect(component.showDashboardReport).toEqual(false);
159         expect(component.displayedRowObj).toEqual(new Array());
160         expect(component.displayedColumns).toEqual(new Array());
161         expect(component.formFieldList).toEqual(new Array());
162         expect(component.NEWdisplayedColumns).toEqual(new Array());
163         expect(component.isReady).toEqual(false);
164         
165   });
166
167
168    it('should test initialProcess method', () => {
169       component.DashboardReportObj.length = 1;
170       component.initialProcesses();
171   });
172
173   // it('should test postFetchingReportDataFn method',()=>{
174   //   var response={
175   //                    "reportName":"reportName",
176   //                    "reportDataColumns":[{"columnTitle":"columnTitle","colId":"colId"}],
177   //                    "reportDataRows":[{"value":"value"}]
178   //                   }
179   //   component.displayedColumnsArr=["string"]
180   //   component.postFetchingReportDataFn(response)
181   // })
182
183  
184 });