e0ea762db82895b10a0e6bdd931d6b3f75223e97
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 import { MatTableModule } from '@angular/material';
3 import { RunDashboardReportComponent } from './run-dashboard-report.component';
4 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
5 import { RouterModule, Router } from '@angular/router';
6 import { HttpClientTestingModule } from '@angular/common/http/testing';
7 import { RouterTestingModule } from '@angular/router/testing';
8 import { DashboardReportService } from './dashboard-report.service';
9 import { MockBackend, MockConnection } from '@angular/http/testing';
10 import { Http, BaseRequestOptions } from '@angular/http';
11 import { Observable } from 'rxjs';
12 import 'rxjs/add/observable/empty';
13 import 'rxjs/add/observable/of';
14 import { environment } from 'src/environments/environment';
15
16 describe('RunDashboardReportComponent', () => {
17   let component: RunDashboardReportComponent;
18   let fixture: ComponentFixture<RunDashboardReportComponent>;
19   let dashboardService : DashboardReportService;
20   let router: Router;
21
22   beforeEach(async(() => {
23     TestBed.configureTestingModule({
24       schemas: [CUSTOM_ELEMENTS_SCHEMA],
25       declarations: [ RunDashboardReportComponent ],
26       imports: [MatTableModule, RouterTestingModule, HttpClientTestingModule],
27       providers:[DashboardReportService, MockBackend, BaseRequestOptions, {
28         provide: Http,
29                     useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
30                         return new Http(backend, defaultOptions);
31                     },
32                     deps: [MockBackend, BaseRequestOptions],
33       }]
34     })
35     .compileComponents();
36     dashboardService = TestBed.get(DashboardReportService);
37     router = TestBed.get(Router);
38   }));
39
40   beforeEach(() => {
41     fixture = TestBed.createComponent(RunDashboardReportComponent);
42     component = fixture.componentInstance;
43     fixture.detectChanges();
44   });
45
46   it('should create', () => { 
47     expect(component).toBeTruthy();
48     fixture.detectChanges();
49   });
50
51   it('should test ngOnInit method', () => {
52         component.queryString = "test";
53         component.ngOnInit();
54         expect(component.initialQueryString).toEqual("test");
55         expect(component.initCounter).toEqual(component.initCounter++);
56         spyOn(component, 'initialProcesses');
57         component.initialProcesses();
58         expect(component.initialProcesses).toHaveBeenCalled();
59   });
60
61   it('should test initialProcess method', () => {
62         component.initialProcesses();
63         expect(component.dataSource.paginator).toEqual(component.paginator);
64   });
65
66   it('should test ngOnChanges methods if condition', () => {
67
68       component.hitCnt = 1;
69       component.queryString =  "testing"
70         component.initialQueryString === "test";
71         component.initCounter > 0;
72         component.runButtonHitCounter === 2;
73
74         component.ngOnChanges();
75         expect(component.initialQueryString).toEqual(component.queryString);
76         expect(component.runButtonHitCounter).toEqual(component.hitCnt);
77
78         spyOn(component, 'initialProcesses');
79         spyOn(component, 'afterViewInitProcesses');
80         component.initialProcesses();
81         component.afterViewInitProcesses();
82         expect(component.initialProcesses).toHaveBeenCalled();
83         expect(component.afterViewInitProcesses).toHaveBeenCalled();
84         
85   });
86
87   it('should test ngOnChanges methods else condition', () => {
88
89     component.hitCnt = 1;
90     component.queryString =  "testing"
91       component.initialQueryString === "testing";
92       component.initCounter = 0;
93       component.runButtonHitCounter === 1;
94
95       component.ngOnChanges();
96       expect(component.runButtonHitCounter).toBe(component.hitCnt);
97       expect(component.initialQueryString).toBe(component.queryString);
98       
99 });
100
101   it('should test applyFilter method', () => {
102         component.applyFilter("testing");
103         expect(component.dataSource.filter).toEqual("testing".trim().toLowerCase());
104   });
105
106    it('should test afterViewInitProcesses method', () => {
107     component.afterViewInitProcesses();
108     expect(component.displayedColumnsArr).toEqual(new Array());
109     expect(component.displayedRowObj).toEqual(new Array());
110     expect(component.displayedColumns).toEqual(new Array());
111     expect(component.formFieldList).toEqual(new Array());
112     expect(component.showSpinner).toEqual(true);
113     expect(component.isReady).toEqual(false);
114     expect(component.NEWdisplayedColumns).toEqual(new Array());
115   });
116
117     it('should test linkToReport method', () => {
118       let reportId = "abc";
119       let queryParameters = "def";
120       component.linkToReport(reportId, queryParameters);
121     });
122
123     it('should test linkToFeedback method', () => {
124       let reportId = "abc";
125       let queryParameters = "def";
126       component.linkToFeedback(reportId, queryParameters);
127     });
128
129     it('should test linkToMail method', () => {
130       let mailID = "abc";
131       component.linkToMail(mailID);
132     });
133
134 });