52082c9f20663ec1ff9d1b19633db1a84186b7c2
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
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
12
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"};
19   let elements = [];
20   let environment = [
21     {
22      "baseUrl": 'just for test'
23     }
24   ]
25
26   beforeEach(async(() => {
27     TestBed.configureTestingModule({
28       schemas: [CUSTOM_ELEMENTS_SCHEMA],
29       declarations: [ SQLComponent ],
30       imports: [FormsModule, HttpClientTestingModule, RouterTestingModule],
31       providers: [SqlService]
32     })
33     .compileComponents();
34     sqlService = TestBed.get(SqlService);
35     let response : any;
36     spyOn(sqlService, 'getSQLTabData').and.returnValue(Observable.of(environment));
37     spyOn(sqlService, 'postSQLValidateAndSave').and.returnValue(Observable.of(environment));
38   }));
39
40   beforeEach(() => {
41
42     fixture = TestBed.createComponent(SQLComponent); 
43     component = fixture.componentInstance;
44     component.reportId1 = reportId;
45     component.finalGetObj = finalGetObj;
46     fixture.detectChanges();
47
48   });
49
50   it('should create', () => {
51     expect(component).toBeTruthy();
52   });
53
54   it('should test ngOninit subscribe method', () => {
55       spyOn(component, 'ngOnInit').and.callThrough();
56       component.ngOnInit();
57       expect(component.ngOnInit).toHaveBeenCalled();
58   });
59
60   it('should test ngOnInit method', () => {
61       component.ngOnInit();
62       expect(component.showSaveSQLDialog).toEqual(false);
63       expect(component.SQLPostResponse).toEqual(true);
64       expect(component.ValidatePostResponse).toEqual({});
65   });
66
67   it('should test ngOnChanges methods', () => {
68     
69       fixture.detectChanges();
70       component.ngOnChanges();
71       expect(component.showSaveSQLDialog).toEqual(false);
72       expect(component.SQLPostResponse).toEqual(true);
73       expect(component.ValidatePostResponse).toEqual({});
74   });
75
76   it('should test saveSQL methods if condition', () => {
77       component.SQLPostResponse = true;
78       component.saveSQL();
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);
83   });
84
85   it('should test closeSaveModal method', () => {
86       component.closeSaveModal();
87       expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
88       expect(component.SQLclosable).toEqual(false);
89   });
90
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);
98
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);
104   });
105
106   it('should test SetValidateResponseString method', () => {
107       component.SetValidateResponseString("testing");
108       expect(component.ValidateResponseString).toEqual("testing");
109   });
110
111   it('should test GetValidateResponseString method', () => {
112       component.ValidateResponseString = 'test';
113       expect(component.GetValidateResponseString()).toEqual("test");
114   });
115
116 //     it('should test validate method', () => {
117 //       spyOn(component, 'validate').and.callThrough();
118 //       component.validate();
119 //       expect(component.validate).toHaveBeenCalled();
120 // });
121
122 });