4d4fe2695f2003754b5340e41bb232fc01fab960
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3 import { MatPaginatorModule } from '@angular/material/paginator';
4 import { MatSortModule } from '@angular/material/sort';
5 import { MatTableModule, MatTableDataSource } from '@angular/material/table';
6
7 import { RunReportComponent, PeriodicElement } from './run-report.component';
8 import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SimpleChange, SimpleChanges } from '@angular/core';
9 import { MatMenuModule } from '@angular/material';
10 import { HttpClientTestingModule } from '@angular/common/http/testing';
11 import { RouterTestingModule } from '@angular/router/testing';
12 import { RunService } from '../run.service';
13 import { GridsterConfig, GridsterItem, GridType } from 'angular-gridster2';
14
15 describe('RunReportComponent', () => {
16   let component: RunReportComponent;
17   let fixture: ComponentFixture<RunReportComponent>;
18   const displayedColumnsArr1 = [];
19   const DashboardReportObj1 = [];
20   const trigger = ["a","b"];
21   let change : SimpleChanges;
22   let runService : RunService;
23   let options1 = {};
24
25   beforeEach(async(() => {
26     TestBed.configureTestingModule({
27       schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
28       declarations: [ RunReportComponent ],
29       imports: [
30         NoopAnimationsModule,
31         MatPaginatorModule,
32         MatSortModule,
33         MatTableModule,
34         MatMenuModule,
35         HttpClientTestingModule,
36         RouterTestingModule
37       ],
38       providers: [RunService]
39     }).compileComponents();
40     runService = TestBed.get(RunService);
41   }));
42
43   beforeEach(() => {
44     fixture = TestBed.createComponent(RunReportComponent);
45     runService = TestBed.get(RunService);
46     component = fixture.componentInstance;
47     component.DashboardReportObj = DashboardReportObj1;
48     component.displayedColumnsArr = displayedColumnsArr1;
49     component.TriggerFFArr = trigger;
50     component.options = options1;
51     fixture.detectChanges();
52   });
53
54   it('should compile', () => {
55     expect(component).toBeTruthy();
56   });
57
58   it('should test the ngOnChanges method', () => {
59         fixture.detectChanges();
60         component.reportMode !== "Regular";
61         component.initCnt > 0;
62         component.TriggerFFArr.length == 0;
63     
64         component.ngOnChanges(change);
65         expect(component.showMoreVert).toEqual(false);
66         expect(component.initCnt).toEqual(1);
67         expect(component.showDashboardReport).toEqual(false);
68         expect(component.displayedRowObj).toEqual(new Array());
69         expect(component.displayedColumns).toEqual(new Array());
70         expect(component.formFieldList).toEqual(new Array());
71         expect(component.showSpinner).toEqual(true);
72         expect(component.NEWdisplayedColumns).toEqual(new Array());
73         expect(component.isReady).toEqual(false);
74
75         runService.getReportDataWithFormFields("for", "test").subscribe((Response) => {
76           component.reportMode !== "FormField";
77           expect(component.showMoreVert).toEqual(true);
78           expect(component.showDashboardReport).toEqual(true);
79         });
80         
81         component.initialQueryString !== component.queryString;
82         component.initCounter > 0;
83         component.hitCnt !== component.runButtonHitCnt;
84         expect(component.runButtonHitCnt).toEqual(component.hitCnt);
85         expect(component.initialQueryString).toEqual(component.queryString);
86   });
87
88   it('should test initialProcess method', () => {
89       component.initialProcesses();
90       component.DashboardReportObj.length > 0;
91       expect(component.dashboard).toEqual(component.DashboardReportObj);
92       expect(component.hitCnt).toEqual(component.runButtonHitCnt);
93       expect(component.initialQueryString).toEqual(component.queryString);
94       expect(component.initCounter).toEqual(component.initCounter++);
95   });
96
97   it('should test afterViewInitialProcesses method', () => {
98       component.afterViewInitialProcesses();
99       component.DashboardReportObj.length === 0;
100       component.reportMode === "Regular";
101       component.initCnt == 0;
102       
103       expect(component.showMoreVert).toEqual(false);
104       expect(component.displayedColumnsArr).toEqual(new Array());
105       expect(component.displayedRowObj).toEqual(new Array());
106       expect(component.displayedColumns).toEqual(new Array());
107       expect(component.formFieldList).toEqual(new Array());
108       expect(component.showSpinner).toEqual(true);
109       expect(component.isReady).toEqual(false);
110       expect(component.NEWdisplayedColumns).toEqual(new Array());
111   });
112
113   it('should test showError method', () => {
114        let errmsg = "errormessage";
115        let stcktrace = "stacktrace";
116       component.showError("test");
117        expect(component.errorMessage).toEqual("test"[errmsg]);
118        expect(component.stackTrace).toEqual("test"[stcktrace]);
119        expect(component.error).toEqual(true);
120        expect(component.showSpinner).toEqual(false);
121
122     });
123
124   it('should test openOptions method', () => {
125         component.openOptions();
126         expect(component.openOptionsFlag).toEqual(component.openOptionsFlag);
127   });
128
129   it('should test applyFilter method', () => {
130       let filterValue = "test"
131       component.applyFilter(filterValue);
132       expect(component.dataSource.filter).toEqual(filterValue.trim().toLowerCase());
133   });
134   
135 });