import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { MatPaginatorModule } from '@angular/material/paginator'; import { MatSortModule } from '@angular/material/sort'; import { MatTableModule, MatTableDataSource } from '@angular/material/table'; import { ReportListComponent } from './report-list.component'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { Router } from '@angular/router'; import { AllReportsDataSource } from './report-list-datasource'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import 'rxjs/add/observable/empty'; import 'rxjs/add/observable/of'; import { environment } from 'src/environments/environment'; import { ReportListService } from './report-list.service'; describe('ReportListComponent', () => { let component: ReportListComponent; let fixture: ComponentFixture; let http: HttpClient; let reportService : ReportListService; let environment = [ { baseUrl : 'just for test' } ] beforeEach(async(() => { TestBed.configureTestingModule({ schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [ ReportListComponent ], imports: [ NoopAnimationsModule, MatPaginatorModule, MatSortModule, MatTableModule, HttpClientTestingModule, RouterTestingModule, ], providers: [HttpClient, ReportListService] }).compileComponents(); reportService = TestBed.get(ReportListService); http = TestBed.get(HttpClient); spyOn(reportService, 'deleteReport').and.returnValue(Observable.of(environment)); })); beforeEach(() => { fixture = TestBed.createComponent(ReportListComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should compile', () => { expect(component).toBeTruthy(); }); it('should test initializeReportList method', () => { component.initializeReportList(); expect(component.showSpinner).toEqual(true); expect(component.dataSource).toEqual(new AllReportsDataSource()); expect(component.intermediateDisplayedColumns).toEqual(new Array()); expect(component.finalGETObj).toEqual(new Object()); expect(component.finalGETObjRowsArr).toEqual(new Array()); expect(component.rowArr).toEqual(new Array()); expect(component.reportIdArr).toEqual(new Array()); expect(component.toggle).toEqual(false); expect(component.toggle1).toEqual(false); expect(component.finalRowArr).toEqual(new Array()); }); it('should test ngOnInit method', () => { component.ngOnInit(); expect(component.toggle).toEqual(false); }); it('should test confirmDelete method', () => { component.confirmDelete("test"); expect(component.showDialog).toEqual(true); expect(component.closable).toEqual(true); expect(component.newReportId).toEqual("test"); }); it('should test ngAfterViewInit method', () => { component.ngAfterViewInit(); expect(component.dataSource.sort).toEqual(component.sort); expect(component.dataSource.paginator).toEqual(component.paginator); expect(component.table.dataSource).toEqual(component.dataSource); }); it('should test displayReport method', () => { component.displayReport("Testing"); expect(component.reportId).toEqual("Testing"); }); it('should test runReport method', () => { component.runReport("Test"); expect(component.reportId).toEqual("Test"); }); it('should test applyFilter method', () => { component.applyFilter("ABC"); expect(component.dataSource1.filter).toEqual("abc"); }); it('should test close method', () => { component.close(); expect(component.showDialog).toEqual(true); expect(component.closable).toEqual(false); }); it('should test deleteReport method', () => { spyOn(component, 'deleteReport').and.callThrough(); component.deleteReport(); expect(component.deleteReport).toHaveBeenCalled(); }); it('should test openReportSchedule method', () => { component.openReportSchedule("test"); }); });