diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report/run-report.component.spec.ts')
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report/run-report.component.spec.ts | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report/run-report.component.spec.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report/run-report.component.spec.ts new file mode 100644 index 00000000..8c1d5260 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/report-run/run/run-report/run-report.component.spec.ts @@ -0,0 +1,188 @@ +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 { RunReportComponent, PeriodicElement } from './run-report.component'; +import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SimpleChange, SimpleChanges } from '@angular/core'; +import { MatMenuModule } from '@angular/material'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { RunService } from '../run.service'; +import 'rxjs/add/observable/empty'; +import 'rxjs/add/observable/of'; +import { Observable } from 'rxjs'; +import {MatDialog, MatDialogModule} from '@angular/material'; +import {HttpCacheService} from '../../../shared/services/cache.service'; + +describe('RunReportComponent', () => { + let component: RunReportComponent; + let fixture: ComponentFixture<RunReportComponent>; + const displayedColumnsArr1 = []; + const DashboardReportObj1 = []; + const trigger = ["a","b"]; + let change : SimpleChanges; + let runService : RunService; + let httpCacheService : HttpCacheService; + let matDialog : MatDialog; + let options1 = {}; + let dashboard; + let dashboard2; + let responseformfield = 1; + let environment = [ + { + baseUrl: 'just a link' + } + ] + + + beforeEach(async(() => { + TestBed.configureTestingModule({ + schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], + declarations: [ RunReportComponent ], + imports: [ + NoopAnimationsModule, + MatPaginatorModule, + MatSortModule, + MatTableModule, + MatMenuModule, + HttpClientTestingModule, + RouterTestingModule, + MatDialogModule + ], + providers: [RunService, HttpCacheService, MatDialog] + }).compileComponents(); + runService = TestBed.get(RunService); + httpCacheService = TestBed.get(HttpCacheService); + matDialog = TestBed.get(MatDialog); + //spyOn(runService, 'getReportDataWithFormFields').and.returnValue(Observable.of(environment)); + //spyOn(runService, 'getReportData').and.returnValue(Observable.of(environment)); + spyOn(runService, 'downloadReportExcel').and.returnValue(Observable.of(environment)); + })); + + beforeEach(() => { + //dashboard = {"item":{"hasContent":{"name":"rupi","id":"check#check"}}}; + fixture = TestBed.createComponent(RunReportComponent); + runService = TestBed.get(RunService); + httpCacheService = TestBed.get(HttpCacheService); + matDialog = TestBed.get(MatDialog); + + component = fixture.componentInstance; + component.DashboardReportObj = DashboardReportObj1; + component.displayedColumnsArr = displayedColumnsArr1; + component.TriggerFFArr = trigger; + component.options = options1; + component.dashboard = dashboard; + component.responseFormFieldListLength = responseformfield; + //fixture.detectChanges(); + }); + + it('should compile', () => { + 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); + + expect(component.runButtonHitCnt).toEqual(component.hitCnt); + expect(component.initialQueryString).toEqual("test"); + spyOn(component, 'initialProcesses'); + spyOn(component, 'afterViewInitialProcesses'); + component.initialProcesses(); + component.afterViewInitialProcesses(); + + 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(); + + expect(component.showMoreVert).toEqual(false); + 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()); + }); + + it('should test showError method', () => { + + const spy1 = spyOn((component as any).changeDetectorRefs, 'detectChanges'); + component.showError(); + expect(spy1).toHaveBeenCalled(); + expect(component.showSpinner).toEqual(false); + }); + + it('should test linkToReport', () => { + component.linkToReport("test", "abc"); + }) + + it('should test linkToMail', () => { + const spy1 = spyOn((component as any).changeDetectorRefs, 'detectChanges'); + component.linkToMail("test"); + expect(spy1).toHaveBeenCalled(); + }) + + it('should test openOptions method', () => { + component.openOptions(); + expect(component.openOptionsFlag).toEqual(component.openOptionsFlag); + }); + + + 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); + }); + + it('should test initialProcess method', () => { + component.DashboardReportObj.length = 1; + component.initialProcesses(); + }); + + // it('should test postFetchingReportDataFn method', () => { + // let response: any; + // component.postFetchingReportDataFn(response); + // }) + + // it('should test ngOnChanges subscribe method', () => { + // spyOn(component, 'ngOnChanges').and.callThrough(); + // component.ngOnChanges(change); + // expect(component.ngOnChanges).toHaveBeenCalled(); + // }) + + // it('should test postFetchingReportDataFn method', () => { + // let obj: any; + // component.postFetchingReportDataFn(obj); + // }) + +}); |