summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/definition/definition.component.spec.ts
blob: c5fe0a6c8089c5b6ff24529713e587bfd2dd19d9 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DefinitionComponent } from './definition.component';
import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { CommonModule } from '@angular/common';
import { Http } from '@angular/http';
import 'rxjs/add/observable/of';
import { Observable } from 'rxjs/Observable';
import { DefinitionService } from './definition.service';

describe('PilotPageComponent', () => {
  let component: DefinitionComponent;
  let fixture: ComponentFixture<DefinitionComponent>;
  let _http:Http;
  let _definitionService:DefinitionService;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      schemas:[CUSTOM_ELEMENTS_SCHEMA],
      declarations: [ DefinitionComponent ],
      imports:[
        FormsModule,
        HttpClientTestingModule,
        RouterTestingModule
      ],
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(DefinitionComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
    _definitionService=TestBed.get(DefinitionService)
  });

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

  it('should test ngOnInit method',()=>{
    component.ngOnInit();
    expect(component.isEdit).toBe(true);
    expect(component.showDialog).toBe(false);
    expect(component.showSpinner).toBe(true);
  });

  // it('should test first if condition inside ngOnInit method',()=>{
  //   component.IncomingReportId =-1;
  //   component.reportMode = "Create";
  //   let spy=spyOn(_definitionService,'getDefinitionPageDetails').and.returnValue(Observable.of(""));
  //   component.ngOnInit();
  //   expect(spy).toHaveBeenCalled();
  // })

  it('should test first if condition in saveDefinitionInfo method',()=>{
    component.IncomingReportId=-1;
    component.reportMode="Create";
    component.reportTitle='Report';
    component.allowScheduler=true;
    component.sizedByContent = true;
    component.saveDefinitionInfo();
    expect(component.finalPostObj["tabName"]).toEqual("Definition");
    expect(component.finalPostObj["tabId"]).toEqual("Def");
    expect(component.finalPostObj["reportId"]).toEqual(component.reportId);
    expect(component.finalPostObj["reportName"]).toEqual(component.reportName);
    expect(component.finalPostObj["reportDescr"]).toEqual(component.reportDescription);
    expect(component.finalPostObj["reportType"]).toEqual(component.reportType);
    expect(component.finalPostObj["reportTypeList"]).toEqual(null);
    expect(component.finalPostObj["dbInfo"]).toEqual(component.dataSrc);
    expect(component.finalPostObj["formHelpText"]).toEqual(component.helpText);
    expect(component.finalPostObj["pageSize"]).toEqual(component.pageSize);
   
    //expect(component.finalPostObj[""]).toEqual(component.);
    expect(component.finalPostObj["hideFormFieldsAfterRun"]).toEqual(component.hideFormFields1);
    expect(component.finalPostObj["maxRowsInExcelCSVDownload"]).toEqual(component.maxRows);
    expect(component.finalPostObj["frozenColumns"]).toEqual(component.colsFrozen);
    expect(component.finalPostObj["dataGridAlign"]).toEqual(component.gridAlign);
    expect(component.finalPostObj["emptyMessage"]).toEqual(component.emptyMessage);
    expect(component.finalPostObj["dataContainerHeight"]).toEqual(component.heightContainer);
    expect(component.finalPostObj["dataContainerWidth"]).toEqual(component.widthContainer);
    expect(component.finalPostObj["runtimeColSortDisabled"]).toEqual(component.disableColumnSort);
    expect(component.finalPostObj["numFormCols"]).toEqual(component.runTimeFormNum);
    expect(component.finalPostObj["reportTitle"]).toEqual('Report');
    expect(component.finalPostObj["reportSubTitle"]).toEqual(component.reportSubTitle);
    expect(component.finalPostObj["oneTimeRec"]).toEqual(component.oneTime);
    expect(component.finalPostObj["hourlyRec"]).toEqual(component.hourly);
    expect(component.finalPostObj["dailyRec"]).toEqual(component.daily);
    expect(component.finalPostObj["dailyMFRec"]).toEqual(component.MonFri);
    expect(component.finalPostObj["weeklyRec"]).toEqual(component.Weekly);
    expect(component.finalPostObj["monthlyRec"]).toEqual(component.Monthly);
    expect(component.finalPostObj["allowScheduler"]).toEqual("Y");
    expect(component.finalPostObj["sizedByContent"]).toEqual("Y");
    expect(component.finalPostObj["repDefType"]).toEqual(component.reportDefinition);

  })

  it('should test second if condition in saveDefinitionInfo method',()=>{
    component.IncomingReportId=1;
    component.reportMode="Edit";
    component.allowScheduler=true;
    component.sizedByContent = true;
    component.reportType="Dashboard";
    component.reportTitle='Report';
    component.saveDefinitionInfo();
    
    expect(component.finalPostObj["tabName"]).toEqual("Definition");
    expect(component.finalPostObj["tabId"]).toEqual("Def");
    expect(component.finalPostObj["reportId"]).toEqual(component.reportId);
    expect(component.finalPostObj["reportName"]).toEqual(component.reportName);
    expect(component.finalPostObj["reportDescr"]).toEqual(component.reportDescription);
    expect(component.finalPostObj["reportType"]).toEqual(component.reportType);
  
    expect(component.finalPostObj["dashboardLayoutJSON"]).toEqual(JSON.stringify(component.dashboardObj));
    expect(component.finalPostObj["dashboardLayoutHTML"]).toEqual(component.dashboardLayoutHTML);

  })

   

  it('should test else condition inside second if condition in saveDefinitionInfo method',()=>{
    component.IncomingReportId=1;
    component.reportMode="Edit";
    component.reportType!="dashboard";
    component.reportTitle='Report';
    component.saveDefinitionInfo();
    expect(component.finalPostObj["reportTypeList"]).toEqual(null);
    expect(component.finalPostObj["dbInfo"]).toEqual(component.dataSrc);
    expect(component.finalPostObj["formHekpText"]).toEqual(component.helpText);
    expect(component.finalPostObj["pageSize"]).toEqual(component.pageSize);
  })
  
  it('should test subscribe in second if condition present inside saveDefinitionnInfo method',()=>{
    component.IncomingReportId=1;
    component.reportMode="Edit";
    component.showDialog=true;
    component.reportTitle='Report';
    let spy=spyOn(_definitionService,'portDefinitionPageDetails').and.returnValue(Observable.of(''))
    component.saveDefinitionInfo();
    expect(spy).toHaveBeenCalled()
    expect(component.status).toEqual("Failure!");
    expect(component.message).toEqual("Definition could not be updated.");
    expect(component.showDialog).toBe(false);
    expect(component.closable).toBe(true);

  })



  it('should test close method',()=>{
    component.showDialog=true;
    component.close();
    expect(component.showDialog).toEqual(false);
    expect(component.closable).toEqual(false);
  })

  it('should test onTransferDashboardObj method',()=>{
    expect(component.onTransferDashboardObj('value')).toBeUndefined();
  })
});