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 'rxjs/add/observable/of';
10 import { Observable } from 'rxjs/Observable';
11 import { element } from '@angular/core/src/render3';
12 import { environment } from 'src/environments/environment';
14 describe('SQLComponentComponent', () => {
15 let sqlService: SqlService;
16 let component: SQLComponent;
17 let fixture: ComponentFixture<SQLComponent>;
18 const reportId = "test";
19 const finalGetObj = {"query":"dummyQuery"}
21 beforeEach(async(() => {
22 TestBed.configureTestingModule({
23 schemas: [CUSTOM_ELEMENTS_SCHEMA],
24 declarations: [ SQLComponent ],
25 imports: [FormsModule, HttpClientTestingModule, RouterTestingModule],
26 providers: [SqlService]
29 sqlService = TestBed.get(SqlService);
34 fixture = TestBed.createComponent(SQLComponent);
35 component = fixture.componentInstance;
36 component.reportId1 = reportId;
37 component.finalGetObj = finalGetObj;
38 sqlService = TestBed.get(SqlService);
39 fixture.detectChanges();
43 it('should create', () => {
44 expect(component).toBeTruthy();
47 it('should test ngOnInit method', () => {
49 expect(component.showSaveSQLDialog).toEqual(false);
50 expect(component.SQLPostResponse).toEqual(true);
51 expect(component.ValidatePostResponse).toEqual({});
54 it('should test ngOnChanges methods', () => {
56 fixture.detectChanges();
57 component.ngOnChanges();
58 expect(component.showSaveSQLDialog).toEqual(false);
59 expect(component.SQLPostResponse).toEqual(true);
60 expect(component.ValidatePostResponse).toEqual({});
63 it('should test saveSQL methods if condition', () => {
64 component.SQLPostResponse = true;
66 expect(component.SQLstatus).toEqual("Success!");
67 expect(component.SQLmessage).toEqual("Your change has been saved! Definition is updated.");
68 expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
69 expect(component.SQLclosable).toEqual(true);
72 it('should test validate method', () => {
76 it('should test closeSaveModal method', () => {
77 component.closeSaveModal();
78 expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
79 expect(component.SQLclosable).toEqual(false);
82 it('should test closeValidateModal method', () => {
83 component.reportMode = "Create";
84 component.Validatestatus = "SQL Test Run - Failed!";
85 component.closeValidateModal();
86 expect(component.sqlText).toEqual(component.sqlText);
87 expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
88 expect(component.Validateclosable).toEqual(false);
90 component.reportMode = "Create";
91 component.Validatestatus = "SQL Test Run - Passed!";
92 component.closeValidateModal();
93 expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
94 expect(component.Validateclosable).toEqual(false);
97 it('should test SetValidateResponseString method', () => {
98 component.SetValidateResponseString("testing");
99 expect(component.ValidateResponseString).toEqual("testing");
102 it('should test GetValidateResponseString method', () => {
103 component.ValidateResponseString = 'test';
104 expect(component.GetValidateResponseString()).toEqual("test");