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;
45 it('should create', () => {
46 expect(component).toBeTruthy();
49 it('should test ngOnInit method', () => {
50 component.queryString = "test";
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();
59 it('should test initialProcess method', () => {
60 component.initialProcesses();
61 expect(component.dataSource.paginator).toEqual(component.paginator);
64 it('should test ngOnChanges methods if condition', () => {
67 component.queryString = "testing"
68 component.initialQueryString === "test";
69 component.initCounter > 0;
70 component.runButtonHitCounter === 2;
72 component.ngOnChanges();
73 expect(component.initialQueryString).toEqual(component.queryString);
74 expect(component.runButtonHitCounter).toEqual(component.hitCnt);
76 spyOn(component, 'initialProcesses');
77 spyOn(component, 'afterViewInitProcesses');
78 component.initialProcesses();
79 component.afterViewInitProcesses();
80 expect(component.initialProcesses).toHaveBeenCalled();
81 expect(component.afterViewInitProcesses).toHaveBeenCalled();
85 it('should test ngOnChanges methods else condition', () => {
88 component.queryString = "testing"
89 component.initialQueryString === "testing";
90 component.initCounter = 0;
91 component.runButtonHitCounter === 1;
93 component.ngOnChanges();
94 expect(component.runButtonHitCounter).toBe(component.hitCnt);
95 expect(component.initialQueryString).toBe(component.queryString);
99 it('should test applyFilter method', () => {
100 component.applyFilter("testing");
101 expect(component.dataSource.filter).toEqual("testing".trim().toLowerCase());
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());
115 it('should test linkToReport method', () => {
116 let reportId = "abc";
117 let queryParameters = "def";
118 component.linkToReport(reportId, queryParameters);
121 it('should test linkToFeedback method', () => {
122 let reportId = "abc";
123 let queryParameters = "def";
124 component.linkToFeedback(reportId, queryParameters);
127 it('should test linkToMail method', () => {
129 component.linkToMail(mailID);