1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 import { SQLComponent } from './sql.component';
4 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
5 import { FormsModule } from '@angular/forms';
6 import { HttpClientTestingModule } from '@angular/common/http/testing';
7 import { RouterTestingModule } from '@angular/router/testing';
8 import { SqlService } from './sql.service';
9 import { Observable, of } from 'rxjs';
10 import { element } from '@angular/core/src/render3';
12 describe('SQLComponentComponent', () => {
13 let sqlService: SqlService;
14 let component: SQLComponent;
15 let fixture: ComponentFixture<SQLComponent>;
16 const reportId = "test";
17 const finalGetObj = {"query":"dummyQuery"}
19 beforeEach(async(() => {
20 TestBed.configureTestingModule({
21 schemas: [CUSTOM_ELEMENTS_SCHEMA],
22 declarations: [ SQLComponent ],
23 imports: [FormsModule, HttpClientTestingModule, RouterTestingModule],
24 providers: [SqlService]
27 sqlService = TestBed.get(SqlService);
32 fixture = TestBed.createComponent(SQLComponent);
33 component = fixture.componentInstance;
34 component.reportId1 = reportId;
35 component.finalGetObj = finalGetObj;
36 sqlService = TestBed.get(SqlService);
37 fixture.detectChanges();
41 it('should create', () => {
42 expect(component).toBeTruthy();
45 it('should test ngOnInit method', () => {
47 fixture.detectChanges();
49 expect(component.showSaveSQLDialog).toEqual(false);
50 expect(component.SQLPostResponse).toEqual(true);
51 expect(component.ValidatePostResponse).toEqual({});
54 sqlService.getSQLTabData("test").subscribe(value => {
55 expect(component.showSpinner).toEqual(true);
56 expect(component.finalGetObj).toEqual(value);
57 expect(component.sqlText).toEqual(component.finalGetObj.query);
58 expect(component.showSpinner).toEqual(false);
65 it('should test ngOnChanges method', () => {
67 fixture.detectChanges();
68 component.ngOnChanges();
69 expect(component.showSaveSQLDialog).toEqual(false);
70 expect(component.SQLPostResponse).toEqual(true);
71 expect(component.ValidatePostResponse).toEqual({});
73 sqlService.getSQLTabData("test").subscribe((response) => {
74 expect(component.showSpinner).toBe(true);
75 expect(component.finalGetObj).toBe(response);
76 expect(component.sqlText).toEqual(component.finalGetObj.query);
77 expect(component.showSpinner).toEqual(false);
83 it('should test saveSQL method', () => {
84 component.SQLPostResponse === true;
86 expect(component.SQLstatus).toEqual("Success!");
87 expect(component.SQLmessage).toEqual("Your change has been saved! Definition is updated.");
88 expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
89 expect(component.SQLclosable).toEqual(true);
92 it('should test validate method', () => {
96 sqlService.postSQLValidateAndSave("test").subscribe((Response) => {
97 expect(component.showSpinner).toEqual(true);
98 expect(component.ValidateResponseString).toEqual(Response["data"]["elements"]);
99 expect(component.ValidatePostResponse).toEqual(JSON.parse(Response["data"]["elements"]));
101 component.ValidatePostResponse["query"] !== undefined;
103 expect(component.showModal).toEqual(true);
104 expect(component.Validatestatus).toEqual("SQL Test Run - Executed!");
105 expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
106 expect(component.Validateclosable).toEqual(true);
110 it('should test closeSaveModal method', () => {
111 component.closeSaveModal();
112 expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
113 expect(component.SQLclosable).toEqual(false);
116 it('should test closeValidateModal method', () => {
117 component.reportMode === "Create";
118 component.Validatestatus == "SQL Test Run - Failed!";
120 component.closeValidateModal();
121 expect(component.sqlText).toEqual(component.sqlText);
122 expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
123 expect(component.Validateclosable).toEqual(false);
126 it('should test SetValidateResponseString method', () => {
127 component.SetValidateResponseString("testing");
128 expect(component.ValidateResponseString).toEqual("testing");
131 it('should test GetValidateResponseString method', () => {
132 component.ValidateResponseString = 'test';
133 expect(component.GetValidateResponseString()).toEqual("test");