wrote test case for run-dashboard-report component 98/102498/1
authorRupinder <rupinsi1@in.ibm.com>
Thu, 27 Feb 2020 13:06:30 +0000 (18:36 +0530)
committerRupinder <rupinsi1@in.ibm.com>
Thu, 27 Feb 2020 13:06:40 +0000 (18:36 +0530)
Written test cases for run-dashboard-report.component.spec.ts

Issue-ID: PORTAL-834
Change-Id: I8e64c767101dd754b96ac03130012381c29d77f0
Signed-off-by: Rupinder<rupinsi1@in.ibm.com>
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 38e7b3b..96dcdba 100644 (file)
@@ -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<RunDashboardReportComponent>;
+  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