509aa82e05ff3496dd8193fba7be63ba6464241e
[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
16 describe('RunReportComponent', () => {
17   let component: RunReportComponent;
18   let fixture: ComponentFixture<RunReportComponent>;
19   const displayedColumnsArr1 = [];
20   const DashboardReportObj1 = [];
21   const trigger = ["a","b"];
22   let change : SimpleChanges;
23   let runService : RunService;
24   let options1 = {};
25   let dashboard; 
26   let dashboard2; 
27   let responseformfield = 1;
28
29   beforeEach(async(() => {
30     TestBed.configureTestingModule({
31       schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
32       declarations: [ RunReportComponent ],
33       imports: [
34         NoopAnimationsModule,
35         MatPaginatorModule,
36         MatSortModule,
37         MatTableModule,
38         MatMenuModule,
39         HttpClientTestingModule,
40         RouterTestingModule
41       ],
42       providers: [RunService]
43     }).compileComponents();
44     runService = TestBed.get(RunService);
45   }));
46
47   beforeEach(() => {
48     //dashboard = {"item":{"hasContent":{"name":"rupi","id":"check#check"}}};
49     fixture = TestBed.createComponent(RunReportComponent);
50     runService = TestBed.get(RunService);
51     component = fixture.componentInstance;
52     component.DashboardReportObj = DashboardReportObj1;
53     component.displayedColumnsArr = displayedColumnsArr1;
54     component.TriggerFFArr = trigger;
55     component.options = options1;
56     component.dashboard = dashboard; 
57     component.responseFormFieldListLength = responseformfield;
58     fixture.detectChanges();
59   });
60
61   it('should compile', () => {
62       expect(component).toBeTruthy(); 
63   });
64  
65   it('should test the ngOnChanges second If condition', () => {    
66     component.queryString = "test"
67     component.runButtonHitCnt = 1;
68     component.initialQueryString = "abc";
69     component.initCounter = 4;
70     component.hitCnt = 2;
71     component.ngOnChanges(change);
72
73     expect(component.runButtonHitCnt).toEqual(component.hitCnt);
74     expect(component.initialQueryString).toEqual("test");
75     spyOn(component, 'initialProcesses');
76     spyOn(component, 'afterViewInitialProcesses');
77     component.initialProcesses();
78     component.afterViewInitialProcesses();
79
80     expect(component.initialProcesses).toHaveBeenCalled();
81     expect(component.afterViewInitialProcesses).toHaveBeenCalled();
82 });
83
84   it('should test afterViewInitialProcesses method', () => {
85       component.DashboardReportObj.length = 0;
86       component.reportMode = "Regular";
87       component.initCnt = 0;
88       component.afterViewInitialProcesses();
89
90       expect(component.showMoreVert).toEqual(false);
91       expect(component.displayedColumnsArr).toEqual(new Array());
92       expect(component.displayedRowObj).toEqual(new Array());
93       expect(component.displayedColumns).toEqual(new Array());
94       expect(component.formFieldList).toEqual(new Array());
95       expect(component.showSpinner).toEqual(true);
96       expect(component.isReady).toEqual(false);
97       expect(component.NEWdisplayedColumns).toEqual(new Array());
98   });
99
100   it('should test showError method', () => {
101        let errmsg = "errormessage";
102        let stcktrace = "stacktrace";
103       component.showError("test");
104        expect(component.errorMessage).toEqual("test"[errmsg]);
105        expect(component.stackTrace).toEqual("test"[stcktrace]);
106        expect(component.error).toEqual(true);
107        expect(component.showSpinner).toEqual(false);
108     });
109
110   it('should test linkToReport', () => {
111         component.linkToReport("test", "abc");
112   })
113
114   it('should test linkToFeedback', () => {
115     component.linkToFeedback("test", "abc");
116   })
117
118   it('should test linkToMail', () => {
119    component.linkToMail("test");
120   })
121
122   it('should test openOptions method', () => {
123         component.openOptions();
124         expect(component.openOptionsFlag).toEqual(component.openOptionsFlag);
125   });
126
127   it('should test downloadReportExcel method', () => {
128         component.downloadReportExcel();
129   });
130
131   it('should test applyFilter method', () => {
132       let filterValue = "test"
133       component.applyFilter(filterValue);
134       expect(component.dataSource.filter).toEqual(filterValue.trim().toLowerCase());
135   });
136
137    it('should test the ngOnChanges first If condition', () => {   
138     change = {};
139         component.reportMode !== "Regular"
140         component.initCnt = 1;
141         component.TriggerFFArr.length = 0;
142         component.ngOnChanges(change);
143         expect(component.showMoreVert).toEqual(false);
144         expect(component.initCnt).toEqual(1);
145         expect(component.showDashboardReport).toEqual(false);
146         expect(component.displayedRowObj).toEqual(new Array());
147         expect(component.displayedColumns).toEqual(new Array());
148         expect(component.formFieldList).toEqual(new Array());
149         expect(component.showSpinner).toEqual(true);
150         expect(component.NEWdisplayedColumns).toEqual(new Array());
151         expect(component.isReady).toEqual(false);
152   });
153   
154 });