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"};
22 "baseUrl": 'just for test'
26 beforeEach(async(() => {
27 TestBed.configureTestingModule({
28 schemas: [CUSTOM_ELEMENTS_SCHEMA],
29 declarations: [ SQLComponent ],
30 imports: [FormsModule, HttpClientTestingModule, RouterTestingModule],
31 providers: [SqlService]
34 sqlService = TestBed.get(SqlService);
36 spyOn(sqlService, 'getSQLTabData').and.returnValue(Observable.of(environment));
37 spyOn(sqlService, 'postSQLValidateAndSave').and.returnValue(Observable.of(environment));
42 fixture = TestBed.createComponent(SQLComponent);
43 component = fixture.componentInstance;
44 component.reportId1 = reportId;
45 component.finalGetObj = finalGetObj;
46 fixture.detectChanges();
50 it('should create', () => {
51 expect(component).toBeTruthy();
54 it('should test ngOninit subscribe method', () => {
55 spyOn(component, 'ngOnInit').and.callThrough();
57 expect(component.ngOnInit).toHaveBeenCalled();
60 it('should test ngOnInit method', () => {
62 expect(component.showSaveSQLDialog).toEqual(false);
63 expect(component.SQLPostResponse).toEqual(true);
64 expect(component.ValidatePostResponse).toEqual({});
67 it('should test ngOnChanges methods', () => {
69 fixture.detectChanges();
70 component.ngOnChanges();
71 expect(component.showSaveSQLDialog).toEqual(false);
72 expect(component.SQLPostResponse).toEqual(true);
73 expect(component.ValidatePostResponse).toEqual({});
76 it('should test saveSQL methods if condition', () => {
77 component.SQLPostResponse = true;
79 expect(component.SQLstatus).toEqual("Success!");
80 expect(component.SQLmessage).toEqual("Your change has been saved! Definition is updated.");
81 expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
82 expect(component.SQLclosable).toEqual(true);
85 it('should test closeSaveModal method', () => {
86 component.closeSaveModal();
87 expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
88 expect(component.SQLclosable).toEqual(false);
91 it('should test closeValidateModal method', () => {
92 component.reportMode = "Create";
93 component.Validatestatus = "SQL Test Run - Failed!";
94 component.closeValidateModal();
95 expect(component.sqlText).toEqual(component.sqlText);
96 expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
97 expect(component.Validateclosable).toEqual(false);
99 component.reportMode = "Create";
100 component.Validatestatus = "SQL Test Run - Passed!";
101 component.closeValidateModal();
102 expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
103 expect(component.Validateclosable).toEqual(false);
106 it('should test SetValidateResponseString method', () => {
107 component.SetValidateResponseString("testing");
108 expect(component.ValidateResponseString).toEqual("testing");
111 it('should test GetValidateResponseString method', () => {
112 component.ValidateResponseString = 'test';
113 expect(component.GetValidateResponseString()).toEqual("test");
116 // it('should test validate method', () => {
117 // spyOn(component, 'validate').and.callThrough();
118 // component.validate();
119 // expect(component.validate).toHaveBeenCalled();