From eb46569f894f578fea785640905ed732199a5223 Mon Sep 17 00:00:00 2001 From: Rupinder Date: Thu, 27 Feb 2020 18:36:30 +0530 Subject: wrote test case for run-dashboard-report component Written test cases for run-dashboard-report.component.spec.ts Issue-ID: PORTAL-834 Change-Id: I8e64c767101dd754b96ac03130012381c29d77f0 Signed-off-by: Rupinder --- .../run-dashboard-report.component.spec.ts | 75 ++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/run/run-report/run-dashboard-report/run-dashboard-report.component.spec.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/run/run-report/run-dashboard-report/run-dashboard-report.component.spec.ts index 38e7b3ba..96dcdbaa 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/run/run-report/run-dashboard-report/run-dashboard-report.component.spec.ts +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/run/run-report/run-dashboard-report/run-dashboard-report.component.spec.ts @@ -1,16 +1,26 @@ 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 } from '@angular/router'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { DashboardReportService } from './dashboard-report.service'; describe('RunDashboardReportComponent', () => { let component: RunDashboardReportComponent; let fixture: ComponentFixture; + let dashboardService : DashboardReportService; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ RunDashboardReportComponent ] + schemas: [CUSTOM_ELEMENTS_SCHEMA], + declarations: [ RunDashboardReportComponent ], + imports: [MatTableModule, RouterTestingModule, HttpClientTestingModule], + providers: [DashboardReportService] }) .compileComponents(); + dashboardService = TestBed.get(DashboardReportService); })); beforeEach(() => { @@ -19,7 +29,64 @@ describe('RunDashboardReportComponent', () => { fixture.detectChanges(); }); - it('should create', () => { + it('should create', () => { expect(component).toBeTruthy(); + fixture.detectChanges(); + }); + + 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 method', () => { + component.initialQueryString !== component.queryString; + component.initCounter > 0; + component.runButtonHitCounter !== component.hitCnt; + + 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 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()); + + dashboardService.getReportDataWithFormFields("dummy", "test").subscribe((Response) => { + expect(component.formFieldPresent).toEqual(false); + expect(component.responseFormFieldListLength).toEqual(0); + expect(component.reportName).toEqual(Response["reportName"]); + }); + }); + + it('should test applyFilter method', () => { + component.applyFilter("testing"); + expect(component.dataSource.filter).toEqual("testing".trim().toLowerCase()); }); -}); + +}); \ No newline at end of file -- cgit 1.2.3-korg