diff options
author | Rupinder <rupinsi1@in.ibm.com> | 2020-02-20 17:53:09 +0530 |
---|---|---|
committer | Rupinderjeet Singh <rupinsi1@in.ibm.com> | 2020-02-21 08:49:23 +0000 |
commit | 426738783b344b83f407f19702165ec254931514 (patch) | |
tree | 60ea0be9c6a636b6b16c8ca6ff5b6e027e58e6e0 /ecomp-sdk/epsdk-app-overlay/src/main | |
parent | f90a9c9f3d13a70cb7c1f1338aa19cbfc33dd7fd (diff) |
added test cases for sql component
written test cases for sql component
Issue-ID: PORTAL-834
Change-Id: I70cf9576c390a1184893694046cc4bbcd8190a8c
Signed-off-by: Rupinder<rupinsi1@in.ibm.com>
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main')
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/sql/sql.component.spec.ts | 113 |
1 files changed, 112 insertions, 1 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/sql/sql.component.spec.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/sql/sql.component.spec.ts index 0f09e4eb..795afc25 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/sql/sql.component.spec.ts +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/sql/sql.component.spec.ts @@ -1,25 +1,136 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { SQLComponent } from './sql.component'; +import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { SqlService } from './sql.service'; +import { Observable, of } from 'rxjs'; +import { element } from '@angular/core/src/render3'; describe('SQLComponentComponent', () => { + let sqlService: SqlService; let component: SQLComponent; let fixture: ComponentFixture<SQLComponent>; + const reportId = "test"; + const finalGetObj = {"query":"dummyQuery"} beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ SQLComponent ] + schemas: [CUSTOM_ELEMENTS_SCHEMA], + declarations: [ SQLComponent ], + imports: [FormsModule, HttpClientTestingModule, RouterTestingModule], + providers: [SqlService] }) .compileComponents(); + sqlService = TestBed.get(SqlService); })); beforeEach(() => { + fixture = TestBed.createComponent(SQLComponent); component = fixture.componentInstance; + component.reportId1 = reportId; + component.finalGetObj = finalGetObj; + sqlService = TestBed.get(SqlService); fixture.detectChanges(); + }); it('should create', () => { expect(component).toBeTruthy(); }); + + it('should test ngOnInit method', () => { + + fixture.detectChanges(); + component.ngOnInit(); + expect(component.showSaveSQLDialog).toEqual(false); + expect(component.SQLPostResponse).toEqual(true); + expect(component.ValidatePostResponse).toEqual({}); + + (done: DoneFn)=> { + sqlService.getSQLTabData("test").subscribe(value => { + expect(component.showSpinner).toEqual(true); + expect(component.finalGetObj).toEqual(value); + expect(component.sqlText).toEqual(component.finalGetObj.query); + expect(component.showSpinner).toEqual(false); + done(); + }) + } + + }); + + it('should test ngOnChanges method', () => { + + fixture.detectChanges(); + component.ngOnChanges(); + expect(component.showSaveSQLDialog).toEqual(false); + expect(component.SQLPostResponse).toEqual(true); + expect(component.ValidatePostResponse).toEqual({}); + + sqlService.getSQLTabData("test").subscribe((response) => { + expect(component.showSpinner).toBe(true); + expect(component.finalGetObj).toBe(response); + expect(component.sqlText).toEqual(component.finalGetObj.query); + expect(component.showSpinner).toEqual(false); + + }); + + }); + + it('should test saveSQL method', () => { + component.SQLPostResponse === true; + component.saveSQL(); + expect(component.SQLstatus).toEqual("Success!"); + expect(component.SQLmessage).toEqual("Your change has been saved! Definition is updated."); + expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog); + expect(component.SQLclosable).toEqual(true); + }); + + it('should test validate method', () => { + + component.validate(); + + sqlService.postSQLValidateAndSave("test").subscribe((Response) => { + expect(component.showSpinner).toEqual(true); + expect(component.ValidateResponseString).toEqual(Response["data"]["elements"]); + expect(component.ValidatePostResponse).toEqual(JSON.parse(Response["data"]["elements"])); + + component.ValidatePostResponse["query"] !== undefined; + + expect(component.showModal).toEqual(true); + expect(component.Validatestatus).toEqual("SQL Test Run - Executed!"); + expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog); + expect(component.Validateclosable).toEqual(true); + }) + }); + + it('should test closeSaveModal method', () => { + component.closeSaveModal(); + expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog); + expect(component.SQLclosable).toEqual(false); + }); + + it('should test closeValidateModal method', () => { + component.reportMode === "Create"; + component.Validatestatus == "SQL Test Run - Failed!"; + + component.closeValidateModal(); + expect(component.sqlText).toEqual(component.sqlText); + expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog); + expect(component.Validateclosable).toEqual(false); + }); + + it('should test SetValidateResponseString method', () => { + component.SetValidateResponseString("testing"); + expect(component.ValidateResponseString).toEqual("testing"); + }); + + it('should test GetValidateResponseString method', () => { + component.ValidateResponseString = 'test'; + expect(component.GetValidateResponseString()).toEqual("test"); + }); + }); |