summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/sql/sql.component.spec.ts
blob: 52082c9f20663ec1ff9d1b19633db1a84186b7c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { SQLComponent } from './sql.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { SqlService } from './sql.service';
import 'rxjs/add/observable/of';
import { Observable } from 'rxjs/Observable';


describe('SQLComponentComponent', () => {
  let sqlService: SqlService;
  let component: SQLComponent;
  let fixture: ComponentFixture<SQLComponent>;
  const reportId =  "test";
  const finalGetObj = {"query":"dummyQuery"};
  let elements = [];
  let environment = [
    {
     "baseUrl": 'just for test'
    }
  ]

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
      declarations: [ SQLComponent ],
      imports: [FormsModule, HttpClientTestingModule, RouterTestingModule],
      providers: [SqlService]
    })
    .compileComponents();
    sqlService = TestBed.get(SqlService);
    let response : any;
    spyOn(sqlService, 'getSQLTabData').and.returnValue(Observable.of(environment));
    spyOn(sqlService, 'postSQLValidateAndSave').and.returnValue(Observable.of(environment));
  }));

  beforeEach(() => {

    fixture = TestBed.createComponent(SQLComponent); 
    component = fixture.componentInstance;
    component.reportId1 = reportId;
    component.finalGetObj = finalGetObj;
    fixture.detectChanges();

  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should test ngOninit subscribe method', () => {
      spyOn(component, 'ngOnInit').and.callThrough();
      component.ngOnInit();
      expect(component.ngOnInit).toHaveBeenCalled();
  });

  it('should test ngOnInit method', () => {
      component.ngOnInit();
      expect(component.showSaveSQLDialog).toEqual(false);
      expect(component.SQLPostResponse).toEqual(true);
      expect(component.ValidatePostResponse).toEqual({});
  });

  it('should test ngOnChanges methods', () => {
    
      fixture.detectChanges();
      component.ngOnChanges();
      expect(component.showSaveSQLDialog).toEqual(false);
      expect(component.SQLPostResponse).toEqual(true);
      expect(component.ValidatePostResponse).toEqual({});
  });

  it('should test saveSQL methods if condition', () => {
      component.SQLPostResponse = true;
      component.saveSQL();
      expect(component.SQLstatus).toEqual("Success!");
      expect(component.SQLmessage).toEqual("Your change has been saved! Definition is updated.");
      expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
      expect(component.SQLclosable).toEqual(true);
  });

  it('should test closeSaveModal method', () => {
      component.closeSaveModal();
      expect(component.showSaveSQLDialog).toEqual(component.showSaveSQLDialog);
      expect(component.SQLclosable).toEqual(false);
  });

  it('should test closeValidateModal method', () => {
      component.reportMode = "Create";
      component.Validatestatus = "SQL Test Run - Failed!";
      component.closeValidateModal();
      expect(component.sqlText).toEqual(component.sqlText);
      expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
      expect(component.Validateclosable).toEqual(false);

      component.reportMode = "Create";
      component.Validatestatus = "SQL Test Run - Passed!";
      component.closeValidateModal();
      expect(component.showValidateSQLDialog).toEqual(component.showValidateSQLDialog);
      expect(component.Validateclosable).toEqual(false);
  });

  it('should test SetValidateResponseString method', () => {
      component.SetValidateResponseString("testing");
      expect(component.ValidateResponseString).toEqual("testing");
  });

  it('should test GetValidateResponseString method', () => {
      component.ValidateResponseString = 'test';
      expect(component.GetValidateResponseString()).toEqual("test");
  });

//     it('should test validate method', () => {
//       spyOn(component, 'validate').and.callThrough();
//       component.validate();
//       expect(component.validate).toHaveBeenCalled();
// });

});