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';
16 describe('RunDashboardReportComponent', () => {
17 let component: RunDashboardReportComponent;
18 let fixture: ComponentFixture<RunDashboardReportComponent>;
19 let dashboardService : DashboardReportService;
22 beforeEach(async(() => {
23 TestBed.configureTestingModule({
24 schemas: [CUSTOM_ELEMENTS_SCHEMA],
25 declarations: [ RunDashboardReportComponent ],
26 imports: [MatTableModule, RouterTestingModule, HttpClientTestingModule],
27 providers:[DashboardReportService, MockBackend, BaseRequestOptions, {
29 useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
30 return new Http(backend, defaultOptions);
32 deps: [MockBackend, BaseRequestOptions],
36 dashboardService = TestBed.get(DashboardReportService);
37 router = TestBed.get(Router);
41 fixture = TestBed.createComponent(RunDashboardReportComponent);
42 component = fixture.componentInstance;
43 fixture.detectChanges();
46 it('should create', () => {
47 expect(component).toBeTruthy();
48 fixture.detectChanges();
51 it('should test ngOnInit method', () => {
52 component.queryString = "test";
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();
61 it('should test initialProcess method', () => {
62 component.initialProcesses();
63 expect(component.dataSource.paginator).toEqual(component.paginator);
66 it('should test ngOnChanges methods if condition', () => {
69 component.queryString = "testing"
70 component.initialQueryString === "test";
71 component.initCounter > 0;
72 component.runButtonHitCounter === 2;
74 component.ngOnChanges();
75 expect(component.initialQueryString).toEqual(component.queryString);
76 expect(component.runButtonHitCounter).toEqual(component.hitCnt);
78 spyOn(component, 'initialProcesses');
79 spyOn(component, 'afterViewInitProcesses');
80 component.initialProcesses();
81 component.afterViewInitProcesses();
82 expect(component.initialProcesses).toHaveBeenCalled();
83 expect(component.afterViewInitProcesses).toHaveBeenCalled();
87 it('should test ngOnChanges methods else condition', () => {
90 component.queryString = "testing"
91 component.initialQueryString === "testing";
92 component.initCounter = 0;
93 component.runButtonHitCounter === 1;
95 component.ngOnChanges();
96 expect(component.runButtonHitCounter).toBe(component.hitCnt);
97 expect(component.initialQueryString).toBe(component.queryString);
101 it('should test applyFilter method', () => {
102 component.applyFilter("testing");
103 expect(component.dataSource.filter).toEqual("testing".trim().toLowerCase());
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());
117 it('should test linkToReport method', () => {
118 let reportId = "abc";
119 let queryParameters = "def";
120 component.linkToReport(reportId, queryParameters);
123 it('should test linkToFeedback method', () => {
124 let reportId = "abc";
125 let queryParameters = "def";
126 component.linkToFeedback(reportId, queryParameters);
129 it('should test linkToMail method', () => {
131 component.linkToMail(mailID);