added test cases for run-report component 13/103113/1
authorRupinder <rupinsi1@in.ibm.com>
Thu, 5 Mar 2020 10:04:50 +0000 (15:34 +0530)
committerRupinder <rupinsi1@in.ibm.com>
Thu, 5 Mar 2020 10:04:56 +0000 (15:34 +0530)
Written test cases for run-report.comonent.spec.ts

Issue-ID: PORTAL-834
Change-Id: I268f1f81d6c9b3eb1172048c3f3970a1b1ea9a10
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-report.component.spec.ts

index 4d4fe26..509aa82 100644 (file)
@@ -10,7 +10,8 @@ import { MatMenuModule } from '@angular/material';
 import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { RouterTestingModule } from '@angular/router/testing';
 import { RunService } from '../run.service';
-import { GridsterConfig, GridsterItem, GridType } from 'angular-gridster2';
+import 'rxjs/add/observable/empty';
+import 'rxjs/add/observable/of';
 
 describe('RunReportComponent', () => {
   let component: RunReportComponent;
@@ -21,6 +22,9 @@ describe('RunReportComponent', () => {
   let change : SimpleChanges;
   let runService : RunService;
   let options1 = {};
+  let dashboard; 
+  let dashboard2; 
+  let responseformfield = 1;
 
   beforeEach(async(() => {
     TestBed.configureTestingModule({
@@ -41,6 +45,7 @@ describe('RunReportComponent', () => {
   }));
 
   beforeEach(() => {
+    //dashboard = {"item":{"hasContent":{"name":"rupi","id":"check#check"}}};
     fixture = TestBed.createComponent(RunReportComponent);
     runService = TestBed.get(RunService);
     component = fixture.componentInstance;
@@ -48,58 +53,40 @@ describe('RunReportComponent', () => {
     component.displayedColumnsArr = displayedColumnsArr1;
     component.TriggerFFArr = trigger;
     component.options = options1;
+    component.dashboard = dashboard; 
+    component.responseFormFieldListLength = responseformfield;
     fixture.detectChanges();
   });
 
   it('should compile', () => {
-    expect(component).toBeTruthy();
+      expect(component).toBeTruthy(); 
   });
+  it('should test the ngOnChanges second If condition', () => {    
+    component.queryString = "test"
+    component.runButtonHitCnt = 1;
+    component.initialQueryString = "abc";
+    component.initCounter = 4;
+    component.hitCnt = 2;
+    component.ngOnChanges(change);
 
-  it('should test the ngOnChanges method', () => {
-        fixture.detectChanges();
-        component.reportMode !== "Regular";
-        component.initCnt > 0;
-        component.TriggerFFArr.length == 0;
-    
-        component.ngOnChanges(change);
-        expect(component.showMoreVert).toEqual(false);
-        expect(component.initCnt).toEqual(1);
-        expect(component.showDashboardReport).toEqual(false);
-        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.NEWdisplayedColumns).toEqual(new Array());
-        expect(component.isReady).toEqual(false);
-
-        runService.getReportDataWithFormFields("for", "test").subscribe((Response) => {
-          component.reportMode !== "FormField";
-          expect(component.showMoreVert).toEqual(true);
-          expect(component.showDashboardReport).toEqual(true);
-        });
-        
-        component.initialQueryString !== component.queryString;
-        component.initCounter > 0;
-        component.hitCnt !== component.runButtonHitCnt;
-        expect(component.runButtonHitCnt).toEqual(component.hitCnt);
-        expect(component.initialQueryString).toEqual(component.queryString);
-  });
+    expect(component.runButtonHitCnt).toEqual(component.hitCnt);
+    expect(component.initialQueryString).toEqual("test");
+    spyOn(component, 'initialProcesses');
+    spyOn(component, 'afterViewInitialProcesses');
+    component.initialProcesses();
+    component.afterViewInitialProcesses();
 
-  it('should test initialProcess method', () => {
-      component.initialProcesses();
-      component.DashboardReportObj.length > 0;
-      expect(component.dashboard).toEqual(component.DashboardReportObj);
-      expect(component.hitCnt).toEqual(component.runButtonHitCnt);
-      expect(component.initialQueryString).toEqual(component.queryString);
-      expect(component.initCounter).toEqual(component.initCounter++);
-  });
+    expect(component.initialProcesses).toHaveBeenCalled();
+    expect(component.afterViewInitialProcesses).toHaveBeenCalled();
+});
 
   it('should test afterViewInitialProcesses method', () => {
+      component.DashboardReportObj.length = 0;
+      component.reportMode = "Regular";
+      component.initCnt = 0;
       component.afterViewInitialProcesses();
-      component.DashboardReportObj.length === 0;
-      component.reportMode === "Regular";
-      component.initCnt == 0;
-      
+
       expect(component.showMoreVert).toEqual(false);
       expect(component.displayedColumnsArr).toEqual(new Array());
       expect(component.displayedRowObj).toEqual(new Array());
@@ -118,18 +105,50 @@ describe('RunReportComponent', () => {
        expect(component.stackTrace).toEqual("test"[stcktrace]);
        expect(component.error).toEqual(true);
        expect(component.showSpinner).toEqual(false);
-
     });
 
+  it('should test linkToReport', () => {
+        component.linkToReport("test", "abc");
+  })
+
+  it('should test linkToFeedback', () => {
+    component.linkToFeedback("test", "abc");
+  })
+
+  it('should test linkToMail', () => {
+   component.linkToMail("test");
+  })
+
   it('should test openOptions method', () => {
         component.openOptions();
         expect(component.openOptionsFlag).toEqual(component.openOptionsFlag);
   });
 
+  it('should test downloadReportExcel method', () => {
+        component.downloadReportExcel();
+  });
+
   it('should test applyFilter method', () => {
       let filterValue = "test"
       component.applyFilter(filterValue);
       expect(component.dataSource.filter).toEqual(filterValue.trim().toLowerCase());
   });
+
+   it('should test the ngOnChanges first If condition', () => {   
+    change = {};
+        component.reportMode !== "Regular"
+        component.initCnt = 1;
+        component.TriggerFFArr.length = 0;
+        component.ngOnChanges(change);
+        expect(component.showMoreVert).toEqual(false);
+        expect(component.initCnt).toEqual(1);
+        expect(component.showDashboardReport).toEqual(false);
+        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.NEWdisplayedColumns).toEqual(new Array());
+        expect(component.isReady).toEqual(false);
+  });
   
 });