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';
13 describe('SQLComponentComponent', () => {
14 let sqlService: SqlService;
15 let component: SQLComponent;
16 let fixture: ComponentFixture<SQLComponent>;
17 const reportId = "test";
18 const finalGetObj = {"query":"dummyQuery"};
21 "baseUrl": 'just for test'
25 beforeEach(async(() => {
26 TestBed.configureTestingModule({
27 schemas: [CUSTOM_ELEMENTS_SCHEMA],
28 declarations: [ SQLComponent ],
29 imports: [FormsModule, HttpClientTestingModule, RouterTestingModule],
30 providers: [SqlService]
33 sqlService = TestBed.get(SqlService);
34 spyOn(sqlService, 'getSQLTabData').and.returnValue(Observable.of(environment));
39 fixture = TestBed.createComponent(SQLComponent);
40 component = fixture.componentInstance;
41 component.reportId1 = reportId;
42 component.finalGetObj = finalGetObj;
43 fixture.detectChanges();
47 it('should create', () => {
48 expect(component).toBeTruthy();
51 it('should test ngOninit subscribe method', () => {
52 spyOn(component, 'ngOnInit').and.callThrough();
54 expect(component.ngOnInit).toHaveBeenCalled();
57 it('should test ngOnInit method', () => {
59 expect(component.showSaveSQLDialog).toEqual(false);
60 expect(component.SQLPostResponse).toEqual(true);
61 expect(component.ValidatePostResponse).toEqual({});
64 it('should test ngOnChanges methods', () => {
66 fixture.detectChanges();
67 component.ngOnChanges();
68 expect(component.showSaveSQLDialog).toEqual(false);
69 expect(component.SQLPostResponse).toEqual(true);
70 expect(component.ValidatePostResponse).toEqual({});
73 it('should test saveSQL methods if condition', () => {
74 component.SQLPostResponse = true;
76 expect(component.SQLstatus).toEqual("Success!");
77 expect(component.SQLmessage).toEqual("Your change has been saved! Definition is updated.");
78 expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
79 expect(component.SQLclosable).toEqual(true);
82 it('should test saveSQL method else condition',()=>{
83 component.SQLPostResponse = false;
87 it('should test validate method',()=>{
88 component.sqlText="sqlText";
89 var response={"data":{"elements":'{"elements":""}'}}
90 let spy=spyOn(sqlService,'postSQLValidateAndSave').and.returnValue(Observable.of(response))
92 expect(spy).toHaveBeenCalled();
95 it('should test validate method',()=>{
96 component.sqlText="sqlText";
97 var response={"data":{"elements":'{"query":"query"}'}}
98 let spy=spyOn(sqlService,'postSQLValidateAndSave').and.returnValue(Observable.of(response))
100 expect(spy).toHaveBeenCalled();
103 it('should test closeSaveModal method', () => {
104 component.closeSaveModal();
105 expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
106 expect(component.SQLclosable).toEqual(false);
109 it('should test closeValidateModal method', () => {
110 component.reportMode = "Create";
111 component.Validatestatus = "SQL Test Run - Failed!";
112 component.closeValidateModal();
113 expect(component.sqlText).toEqual(component.sqlText);
114 expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
115 expect(component.Validateclosable).toEqual(false);
117 component.reportMode = "Create";
118 component.Validatestatus = "SQL Test Run - Passed!";
119 component.closeValidateModal();
120 expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
121 expect(component.Validateclosable).toEqual(false);
124 it('should test SetValidateResponseString method', () => {
125 component.SetValidateResponseString("testing");
126 expect(component.ValidateResponseString).toEqual("testing");
129 it('should test GetValidateResponseString method', () => {
130 component.ValidateResponseString = 'test';
131 expect(component.GetValidateResponseString()).toEqual("test");