import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { MatTableModule } from '@angular/material'; import { RunDashboardReportComponent } from './run-dashboard-report.component'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { RouterModule, Router } from '@angular/router'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { DashboardReportService } from './dashboard-report.service'; import { MockBackend, MockConnection } from '@angular/http/testing'; import { Http, BaseRequestOptions } from '@angular/http'; import { Observable } from 'rxjs'; import 'rxjs/add/observable/empty'; import 'rxjs/add/observable/of'; import { environment } from 'src/environments/environment'; describe('RunDashboardReportComponent', () => { let component: RunDashboardReportComponent; let fixture: ComponentFixture; let dashboardService : DashboardReportService; let router: Router; beforeEach(async(() => { TestBed.configureTestingModule({ schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [ RunDashboardReportComponent ], imports: [MatTableModule, RouterTestingModule, HttpClientTestingModule], providers:[DashboardReportService, MockBackend, BaseRequestOptions, { provide: Http, useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { return new Http(backend, defaultOptions); }, deps: [MockBackend, BaseRequestOptions], }] }) .compileComponents(); dashboardService = TestBed.get(DashboardReportService); router = TestBed.get(Router); })); beforeEach(() => { fixture = TestBed.createComponent(RunDashboardReportComponent); component = fixture.componentInstance; }); it('should create', () => { expect(component).toBeTruthy(); }); it('should test ngOnInit method', () => { component.queryString = "test"; component.ngOnInit(); expect(component.initialQueryString).toEqual("test"); expect(component.initCounter).toEqual(component.initCounter++); spyOn(component, 'initialProcesses'); component.initialProcesses(); expect(component.initialProcesses).toHaveBeenCalled(); }); it('should test initialProcess method', () => { component.initialProcesses(); expect(component.dataSource.paginator).toEqual(component.paginator); }); it('should test ngOnChanges methods if condition', () => { component.hitCnt = 1; component.queryString = "testing" component.initialQueryString === "test"; component.initCounter > 0; component.runButtonHitCounter === 2; component.ngOnChanges(); expect(component.initialQueryString).toEqual(component.queryString); expect(component.runButtonHitCounter).toEqual(component.hitCnt); spyOn(component, 'initialProcesses'); spyOn(component, 'afterViewInitProcesses'); component.initialProcesses(); component.afterViewInitProcesses(); expect(component.initialProcesses).toHaveBeenCalled(); expect(component.afterViewInitProcesses).toHaveBeenCalled(); }); it('should test ngOnChanges methods else condition', () => { component.hitCnt = 1; component.queryString = "testing" component.initialQueryString === "testing"; component.initCounter = 0; component.runButtonHitCounter === 1; component.ngOnChanges(); expect(component.runButtonHitCounter).toBe(component.hitCnt); expect(component.initialQueryString).toBe(component.queryString); }); it('should test applyFilter method', () => { component.applyFilter("testing"); expect(component.dataSource.filter).toEqual("testing".trim().toLowerCase()); }); it('should test afterViewInitProcesses method', () => { component.afterViewInitProcesses(); expect(component.displayedColumnsArr).toEqual(new Array()); expect(component.displayedRowObj).toEqual(new Array()); expect(component.displayedColumns).toEqual(new Array()); expect(component.formFieldList).toEqual(new Array()); expect(component.showSpinner).toEqual(true); expect(component.isReady).toEqual(false); expect(component.NEWdisplayedColumns).toEqual(new Array()); }); it('should test linkToReport method', () => { let reportId = "abc"; let queryParameters = "def"; component.linkToReport(reportId, queryParameters); }); it('should test linkToFeedback method', () => { let reportId = "abc"; let queryParameters = "def"; component.linkToFeedback(reportId, queryParameters); }); it('should test linkToMail method', () => { let mailID = "abc"; component.linkToMail(mailID); }); });