795afc2589bc0d48369375ddc57124923b81b1d1
[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 { Observable, of } from 'rxjs';
10 import { element } from '@angular/core/src/render3';
11
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"}
18
19   beforeEach(async(() => {
20     TestBed.configureTestingModule({
21       schemas: [CUSTOM_ELEMENTS_SCHEMA],
22       declarations: [ SQLComponent ],
23       imports: [FormsModule, HttpClientTestingModule, RouterTestingModule],
24       providers: [SqlService]
25     })
26     .compileComponents();
27     sqlService = TestBed.get(SqlService);
28   }));
29
30   beforeEach(() => {
31
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();
38
39   });
40
41   it('should create', () => {
42     expect(component).toBeTruthy();
43   });
44
45   it('should test ngOnInit method', () => {
46     
47     fixture.detectChanges();
48       component.ngOnInit();
49       expect(component.showSaveSQLDialog).toEqual(false);
50       expect(component.SQLPostResponse).toEqual(true);
51       expect(component.ValidatePostResponse).toEqual({});
52
53       (done: DoneFn)=> {
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);
59           done();
60         })
61       }
62
63   });
64
65   it('should test ngOnChanges method', () => {
66     
67       fixture.detectChanges();
68       component.ngOnChanges();
69       expect(component.showSaveSQLDialog).toEqual(false);
70       expect(component.SQLPostResponse).toEqual(true);
71       expect(component.ValidatePostResponse).toEqual({});
72
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);
78         
79          });
80
81   });
82
83   it('should test saveSQL method', () => {
84       component.SQLPostResponse === true;
85       component.saveSQL();
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);
90   });
91
92   it('should test validate method', () => {
93
94       component.validate();
95
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"]));
100
101         component.ValidatePostResponse["query"] !== undefined;
102
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);
107       })
108   });
109
110   it('should test closeSaveModal method', () => {
111       component.closeSaveModal();
112       expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
113       expect(component.SQLclosable).toEqual(false);
114   });
115
116   it('should test closeValidateModal method', () => {
117       component.reportMode === "Create";
118       component.Validatestatus == "SQL Test Run - Failed!";
119
120       component.closeValidateModal();
121       expect(component.sqlText).toEqual(component.sqlText);
122       expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
123       expect(component.Validateclosable).toEqual(false);
124   });
125
126   it('should test SetValidateResponseString method', () => {
127       component.SetValidateResponseString("testing");
128       expect(component.ValidateResponseString).toEqual("testing");
129   });
130
131   it('should test GetValidateResponseString method', () => {
132       component.ValidateResponseString = 'test';
133       expect(component.GetValidateResponseString()).toEqual("test");
134   });
135
136 });