a94d9ee10e519c5637d2e4e4970ddcb6c3e3732a
[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   });
44
45   it('should create', () => { 
46     expect(component).toBeTruthy();
47   });
48
49   it('should test ngOnInit method', () => {
50         component.queryString = "test";
51         component.ngOnInit();
52         expect(component.initialQueryString).toEqual("test");
53         expect(component.initCounter).toEqual(component.initCounter++);
54         spyOn(component, 'initialProcesses');
55         component.initialProcesses();
56         expect(component.initialProcesses).toHaveBeenCalled();
57   });
58
59   it('should test initialProcess method', () => {
60         component.initialProcesses();
61         expect(component.dataSource.paginator).toEqual(component.paginator);
62   });
63
64   it('should test ngOnChanges methods if condition', () => {
65
66       component.hitCnt = 1;
67       component.queryString =  "testing"
68         component.initialQueryString === "test";
69         component.initCounter > 0;
70         component.runButtonHitCounter === 2;
71
72         component.ngOnChanges();
73         expect(component.initialQueryString).toEqual(component.queryString);
74         expect(component.runButtonHitCounter).toEqual(component.hitCnt);
75
76         spyOn(component, 'initialProcesses');
77         spyOn(component, 'afterViewInitProcesses');
78         component.initialProcesses();
79         component.afterViewInitProcesses();
80         expect(component.initialProcesses).toHaveBeenCalled();
81         expect(component.afterViewInitProcesses).toHaveBeenCalled();
82         
83   });
84
85   it('should test ngOnChanges methods else condition', () => {
86
87     component.hitCnt = 1;
88     component.queryString =  "testing"
89       component.initialQueryString === "testing";
90       component.initCounter = 0;
91       component.runButtonHitCounter === 1;
92
93       component.ngOnChanges();
94       expect(component.runButtonHitCounter).toBe(component.hitCnt);
95       expect(component.initialQueryString).toBe(component.queryString);
96       
97 });
98
99   it('should test applyFilter method', () => {
100         component.applyFilter("testing");
101         expect(component.dataSource.filter).toEqual("testing".trim().toLowerCase());
102   });
103
104    it('should test afterViewInitProcesses method', () => {
105     component.afterViewInitProcesses();
106     expect(component.displayedColumnsArr).toEqual(new Array());
107     expect(component.displayedRowObj).toEqual(new Array());
108     expect(component.displayedColumns).toEqual(new Array());
109     expect(component.formFieldList).toEqual(new Array());
110     expect(component.showSpinner).toEqual(true);
111     expect(component.isReady).toEqual(false);
112     expect(component.NEWdisplayedColumns).toEqual(new Array());
113   });
114
115     it('should test linkToReport method', () => {
116       let reportId = "abc";
117       let queryParameters = "def";
118       component.linkToReport(reportId, queryParameters);
119     });
120
121     it('should test linkToFeedback method', () => {
122       let reportId = "abc";
123       let queryParameters = "def";
124       component.linkToFeedback(reportId, queryParameters);
125     });
126
127     it('should test linkToMail method', () => {
128       let mailID = "abc";
129       component.linkToMail(mailID);
130     });
131
132 });