9e1cd459637083731e422bc433156eed16148ed1
[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 } 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
21   beforeEach(async(() => {
22     TestBed.configureTestingModule({
23       schemas: [CUSTOM_ELEMENTS_SCHEMA],
24       declarations: [ RunDashboardReportComponent ],
25       imports: [MatTableModule, RouterTestingModule, HttpClientTestingModule],
26       providers:[DashboardReportService, MockBackend, BaseRequestOptions, {
27         provide: Http,
28                     useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
29                         return new Http(backend, defaultOptions);
30                     },
31                     deps: [MockBackend, BaseRequestOptions],
32       }]
33     })
34     .compileComponents();
35     dashboardService = TestBed.get(DashboardReportService);
36   }));
37
38   beforeEach(() => {
39     fixture = TestBed.createComponent(RunDashboardReportComponent);
40     component = fixture.componentInstance;
41     fixture.detectChanges();
42   });
43
44   it('should create', () => { 
45     expect(component).toBeTruthy();
46     fixture.detectChanges();
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 applyFilter method', () => {
86         component.applyFilter("testing");
87         expect(component.dataSource.filter).toEqual("testing".trim().toLowerCase());
88   });
89
90  
91    it('should test afterViewInitProcesses method', () => {
92     component.afterViewInitProcesses();
93     expect(component.displayedColumnsArr).toEqual(new Array());
94     expect(component.displayedRowObj).toEqual(new Array());
95     expect(component.displayedColumns).toEqual(new Array());
96     expect(component.formFieldList).toEqual(new Array());
97     expect(component.showSpinner).toEqual(true);
98     expect(component.isReady).toEqual(false);
99     expect(component.NEWdisplayedColumns).toEqual(new Array());
100   });
101
102   describe('Should test afterViewInitProcesses', () => {
103     it('should validate on afterViewInitProcesses subscribe return', () => {
104         let spy = spyOn(dashboardService, 'getReportDataWithFormFields')
105         .and.returnValue(Observable.of());
106           component.afterViewInitProcesses();  
107           // expect(component.formFieldPresent).toEqual(false);
108           // expect(component.responseFormFieldListLength).toEqual(0);      
109           expect(spy).toHaveBeenCalled();
110   
111     });
112 });
113
114 });