da71826212c4bc0cb1aba1ba29e7beeadbcc8360
[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, MatTableDataSource } from '@angular/material/table';
6
7 import { RunReportComponent, PeriodicElement } from './run-report.component';
8 import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SimpleChange, 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 dashboard2; 
28   let responseformfield = 1;
29   let environment = [
30     {
31       baseUrl: 'just a link'
32     }
33   ]
34
35
36   beforeEach(async(() => {
37     TestBed.configureTestingModule({
38       schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
39       declarations: [ RunReportComponent ],
40       imports: [
41         NoopAnimationsModule,
42         MatPaginatorModule,
43         MatSortModule,
44         MatTableModule,
45         MatMenuModule,
46         HttpClientTestingModule,
47         RouterTestingModule
48       ],
49       providers: [RunService]
50     }).compileComponents();
51     runService = TestBed.get(RunService);
52     //spyOn(runService, 'getReportDataWithFormFields').and.returnValue(Observable.of(environment));
53     //spyOn(runService, 'getReportData').and.returnValue(Observable.of(environment));
54     spyOn(runService, 'downloadReportExcel').and.returnValue(Observable.of(environment));
55   }));
56
57   beforeEach(() => {
58     //dashboard = {"item":{"hasContent":{"name":"rupi","id":"check#check"}}};
59     fixture = TestBed.createComponent(RunReportComponent);
60     runService = TestBed.get(RunService);
61     component = fixture.componentInstance;
62     component.DashboardReportObj = DashboardReportObj1;
63     component.displayedColumnsArr = displayedColumnsArr1;
64     component.TriggerFFArr = trigger;
65     component.options = options1;
66     component.dashboard = dashboard; 
67     component.responseFormFieldListLength = responseformfield;
68     //fixture.detectChanges();
69   });
70
71   it('should compile', () => {
72       expect(component).toBeTruthy(); 
73   });
74  
75   it('should test the ngOnChanges second If condition', () => {    
76     component.queryString = "test"
77     component.runButtonHitCnt = 1;
78     component.initialQueryString = "abc";
79     component.initCounter = 4;
80     component.hitCnt = 2;
81     component.ngOnChanges(change);
82
83     expect(component.runButtonHitCnt).toEqual(component.hitCnt);
84     expect(component.initialQueryString).toEqual("test");
85     spyOn(component, 'initialProcesses');
86     spyOn(component, 'afterViewInitialProcesses');
87     component.initialProcesses();
88     component.afterViewInitialProcesses();
89
90     expect(component.initialProcesses).toHaveBeenCalled();
91     expect(component.afterViewInitialProcesses).toHaveBeenCalled();
92 });
93
94   it('should test afterViewInitialProcesses method', () => {
95       component.DashboardReportObj.length = 0;
96       component.reportMode = "Regular";
97       component.initCnt = 0;
98       component.afterViewInitialProcesses();
99
100       expect(component.showMoreVert).toEqual(false);
101       expect(component.displayedColumnsArr).toEqual(new Array());
102       expect(component.displayedRowObj).toEqual(new Array());
103       expect(component.displayedColumns).toEqual(new Array());
104       expect(component.formFieldList).toEqual(new Array());
105       expect(component.showSpinner).toEqual(true);
106       expect(component.isReady).toEqual(false);
107       expect(component.NEWdisplayedColumns).toEqual(new Array());
108   });
109
110   it('should test showError method', () => {
111        let errmsg = "errormessage";
112        let stcktrace = "stacktrace";
113       component.showError("test");
114        expect(component.errorMessage).toEqual("test"[errmsg]);
115        expect(component.stackTrace).toEqual("test"[stcktrace]);
116        expect(component.error).toEqual(true);
117        expect(component.showSpinner).toEqual(false);
118     });
119
120   it('should test linkToReport', () => {
121         component.linkToReport("test", "abc");
122   })
123
124   it('should test linkToFeedback', () => {
125     component.linkToFeedback("test", "abc");
126   })
127
128   it('should test linkToMail', () => {
129    component.linkToMail("test");
130   })
131
132   it('should test openOptions method', () => {
133         component.openOptions();
134         expect(component.openOptionsFlag).toEqual(component.openOptionsFlag);
135   });
136
137
138   it('should test applyFilter method', () => {
139       let filterValue = "test"
140       component.applyFilter(filterValue);
141       expect(component.dataSource.filter).toEqual(filterValue.trim().toLowerCase());
142   });
143
144    it('should test the ngOnChanges first If condition', () => {   
145     change = {};
146         component.reportMode !== "Regular"
147         component.initCnt = 1;
148         component.TriggerFFArr.length = 0;
149         component.ngOnChanges(change);
150         expect(component.showMoreVert).toEqual(false);
151         expect(component.initCnt).toEqual(1);
152         expect(component.showDashboardReport).toEqual(false);
153         expect(component.displayedRowObj).toEqual(new Array());
154         expect(component.displayedColumns).toEqual(new Array());
155         expect(component.formFieldList).toEqual(new Array());
156         expect(component.showSpinner).toEqual(true);
157         expect(component.NEWdisplayedColumns).toEqual(new Array());
158         expect(component.isReady).toEqual(false);
159   });
160
161    it('should test initialProcess method', () => {
162       component.DashboardReportObj.length = 1;
163       component.initialProcesses();
164   });
165
166   // it('should test postFetchingReportDataFn method', () => {
167   //     let response: any;
168   //     component.postFetchingReportDataFn(response);
169   // })
170
171   // it('should test ngOnChanges subscribe method', ()  => {
172   //     spyOn(component, 'ngOnChanges').and.callThrough();
173   //     component.ngOnChanges(change);
174   //     expect(component.ngOnChanges).toHaveBeenCalled();
175   // })
176
177   // it('should test postFetchingReportDataFn method', () => {
178   //   let obj: any;
179   //     component.postFetchingReportDataFn(obj);
180   // })
181   
182 });