c894bff6ce70abe4dcabb28808e616fc82303138
[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 import { element } from '@angular/core/src/render3';
12 import { environment } from 'src/environments/environment';
13
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"}
20
21   beforeEach(async(() => {
22     TestBed.configureTestingModule({
23       schemas: [CUSTOM_ELEMENTS_SCHEMA],
24       declarations: [ SQLComponent ],
25       imports: [FormsModule, HttpClientTestingModule, RouterTestingModule],
26       providers: [SqlService]
27     })
28     .compileComponents();
29     sqlService = TestBed.get(SqlService);
30   }));
31
32   beforeEach(() => {
33
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();
40
41   });
42
43   it('should create', () => {
44     expect(component).toBeTruthy();
45   });
46
47   it('should test ngOnInit method', () => {
48       component.ngOnInit();
49       expect(component.showSaveSQLDialog).toEqual(false);
50       expect(component.SQLPostResponse).toEqual(true);
51       expect(component.ValidatePostResponse).toEqual({});
52   });
53
54   it('should test ngOnChanges methods', () => {
55     
56       fixture.detectChanges();
57       component.ngOnChanges();
58       expect(component.showSaveSQLDialog).toEqual(false);
59       expect(component.SQLPostResponse).toEqual(true);
60       expect(component.ValidatePostResponse).toEqual({});
61   });
62
63   it('should test saveSQL methods if condition', () => {
64       component.SQLPostResponse = true;
65       component.saveSQL();
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);
70   });
71
72   it('should test validate method', () => {
73         component.validate();
74   });
75
76   it('should test closeSaveModal method', () => {
77       component.closeSaveModal();
78       expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
79       expect(component.SQLclosable).toEqual(false);
80   });
81
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);
89
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);
95   });
96
97   it('should test SetValidateResponseString method', () => {
98       component.SetValidateResponseString("testing");
99       expect(component.ValidateResponseString).toEqual("testing");
100   });
101
102   it('should test GetValidateResponseString method', () => {
103       component.ValidateResponseString = 'test';
104       expect(component.GetValidateResponseString()).toEqual("test");
105   });
106
107 });