cffd529091d41a35ded4400ef0e41c4e72483763
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
3 import { DefinitionComponent } from './definition.component';
4 import { CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
5 import { HttpClientTestingModule } from '@angular/common/http/testing';
6 import { FormsModule } from '@angular/forms';
7 import { RouterTestingModule } from '@angular/router/testing';
8 import 'rxjs/add/observable/of';
9 import { Observable } from 'rxjs/Observable';
10 import { DefinitionService } from './definition.service';
11 import { ActivatedRoute } from '@angular/router';
12
13 describe('DefinitionComponent', () => {
14   let component: DefinitionComponent;
15   let fixture: ComponentFixture<DefinitionComponent>;
16   let _definitionService:DefinitionService;
17   let activatedRoute:ActivatedRoute;
18   var response={
19     "reportId":123,
20     "reportName":"reportName",
21     "reportDescr":"reportDescr",
22     "reportType":"Linear",
23     "dbInfo":"dbInfo",
24     "formHelpText":"formHelpText",
25     "repDefType":"repDefType",
26     "pageSize":20,
27     "hideFormFieldsAfterRun":true,
28     "maxRowsInExcelCSVDownload":10,
29     "frozenColumns":10,
30     "dataGridAlign":"dataGridAlign",
31     "emptyMessage":"emptyMessage",
32     "dataContainerHeight":12,
33     "dataContainerWidth":13,
34     "allowScheduler":true,
35     "sizedByContent":true,
36     "displayOptions":{"string":"string"},
37     "runtimeColSortDisabled":true,
38     "numFormCols":100,
39     "reportTitle":"reportTitle",
40     "reportSubTitle":"reportSubTitle",
41     "oneTimeRec":true,
42     "hourlyRec":true,
43     "dailyRec":true,
44     "dailyMFRec":true,
45     "weeklyRec":true,
46     "monthlyRec":true,
47     "dashboardLayoutJSON":'"data"',
48     "dashboardLayoutHTML":"dashboardLayoutHTML",
49     "displayArea":{"selected":true}
50   }
51
52   beforeEach(async(() => {
53     TestBed.configureTestingModule({
54       schemas:[CUSTOM_ELEMENTS_SCHEMA],
55       declarations: [ DefinitionComponent ],
56       imports:[
57         FormsModule,
58         HttpClientTestingModule,
59         RouterTestingModule
60       ],
61       providers:[DefinitionService]
62     })
63     .compileComponents();
64   }));
65
66   beforeEach(() => {
67     fixture = TestBed.createComponent(DefinitionComponent);
68     component = fixture.componentInstance;
69     fixture.detectChanges();
70     _definitionService=TestBed.get(DefinitionService);
71     activatedRoute=TestBed.get(ActivatedRoute)
72   });
73
74   it('should create', () => {
75     expect(component).toBeTruthy();
76   });
77
78   it('should test ngOnInit method',()=>{
79     component.IncomingReportId=-1;
80     component.reportMode="Create";
81     let spy=spyOn(_definitionService,'getDefinitionPageDetails').and.returnValue(Observable.of(response));
82     component.ngOnInit();
83     expect(spy).toHaveBeenCalled();
84     expect(_definitionService.getDefinitionPageDetails).toHaveBeenCalled();
85     expect(component.isEdit).toBe(true);
86     expect(component.showDialog).toBe(false);
87   });
88
89   it('should test ngOnInit method',()=>{
90     component.IncomingReportId=1;
91     component.reportMode="Edit";
92     let spy=spyOn(_definitionService,'getDefinitionPageDetails').and.returnValue(Observable.of(response));
93     component.ngOnInit();
94     expect(spy).toHaveBeenCalled();
95     expect(_definitionService.getDefinitionPageDetails).toHaveBeenCalled();
96   });
97
98   it('should test first if condition in saveDefinitionInfo method',()=>{
99     component.IncomingReportId=-1;
100     component.reportMode="Create";
101     component.allowScheduler=true;
102     component.sizedByContent = true;
103     component.saveDefinitionInfo();
104     expect(component.finalPostObj["tabName"]).toEqual("Definition");
105     expect(component.finalPostObj["tabId"]).toEqual("Def");
106     expect(component.finalPostObj["reportId"]).toEqual(component.reportId);
107     expect(component.finalPostObj["reportName"]).toEqual(component.reportName);
108     expect(component.finalPostObj["reportDescr"]).toEqual(component.reportDescription);
109     expect(component.finalPostObj["reportType"]).toEqual(component.reportType);
110     expect(component.finalPostObj["reportTypeList"]).toEqual(null);
111     expect(component.finalPostObj["dbInfo"]).toEqual(component.dataSrc);
112     expect(component.finalPostObj["formHelpText"]).toEqual(component.helpText);
113     expect(component.finalPostObj["pageSize"]).toEqual(component.pageSize);
114     expect(component.finalPostObj["hideFormFieldsAfterRun"]).toEqual(component.hideFormFields1);
115     expect(component.finalPostObj["maxRowsInExcelCSVDownload"]).toEqual(component.maxRows);
116     expect(component.finalPostObj["frozenColumns"]).toEqual(component.colsFrozen);
117     expect(component.finalPostObj["dataGridAlign"]).toEqual(component.gridAlign);
118     expect(component.finalPostObj["emptyMessage"]).toEqual(component.emptyMessage);
119     expect(component.finalPostObj["dataContainerHeight"]).toEqual(component.heightContainer);
120     expect(component.finalPostObj["dataContainerWidth"]).toEqual(component.widthContainer);
121     expect(component.finalPostObj["runtimeColSortDisabled"]).toEqual(component.disableColumnSort);
122     expect(component.finalPostObj["numFormCols"]).toEqual(component.runTimeFormNum);
123     expect(component.finalPostObj["reportTitle"]).toEqual(component.reportTitle);
124     expect(component.finalPostObj["reportSubTitle"]).toEqual(component.reportSubTitle);
125     expect(component.finalPostObj["oneTimeRec"]).toEqual(component.oneTime);
126     expect(component.finalPostObj["hourlyRec"]).toEqual(component.hourly);
127     expect(component.finalPostObj["dailyRec"]).toEqual(component.daily);
128     expect(component.finalPostObj["dailyMFRec"]).toEqual(component.MonFri);
129     expect(component.finalPostObj["weeklyRec"]).toEqual(component.Weekly);
130     expect(component.finalPostObj["monthlyRec"]).toEqual(component.Monthly);
131     expect(component.finalPostObj["allowScheduler"]).toEqual("Y");
132     expect(component.finalPostObj["sizedByContent"]).toEqual("Y");
133     expect(component.finalPostObj["repDefType"]).toEqual(component.reportDefinition);
134
135   })
136
137   it('should test second if condition in saveDefinitionInfo method',()=>{
138     component.IncomingReportId=1;
139     component.reportMode="Edit";
140     component.allowScheduler=true;
141     component.sizedByContent = true;
142     component.reportType="Dashboard";
143     component.saveDefinitionInfo();
144     
145     expect(component.finalPostObj["tabName"]).toEqual("Definition");
146     expect(component.finalPostObj["tabId"]).toEqual("Def");
147     expect(component.finalPostObj["reportId"]).toEqual(component.reportId);
148     expect(component.finalPostObj["reportName"]).toEqual(component.reportName);
149     expect(component.finalPostObj["reportDescr"]).toEqual(component.reportDescription);
150     expect(component.finalPostObj["reportType"]).toEqual(component.reportType);
151   
152     expect(component.finalPostObj["dashboardLayoutJSON"]).toEqual(JSON.stringify(component.dashboardObj));
153     expect(component.finalPostObj["dashboardLayoutHTML"]).toEqual(component.dashboardLayoutHTML);
154
155   })
156
157   it('should test else condition inside second if condition in saveDefinitionInfo method',()=>{
158     component.IncomingReportId=1;
159     component.reportMode="Edit";
160     component.reportType!="dashboard";
161     component.saveDefinitionInfo();
162     expect(component.finalPostObj["reportTypeList"]).toEqual(null);
163     expect(component.finalPostObj["dbInfo"]).toEqual(component.dataSrc);
164     expect(component.finalPostObj["formHekpText"]).toEqual(component.helpText);
165     expect(component.finalPostObj["pageSize"]).toEqual(component.pageSize);
166   })
167   
168   it('should test subscribe in second if condition present inside saveDefinitionnInfo method',()=>{
169     component.IncomingReportId=1;
170     component.reportMode="Edit";
171     component.showDialog=true;
172     let spy=spyOn(_definitionService,'portDefinitionPageDetails').and.returnValue(Observable.of(''))
173     component.saveDefinitionInfo();
174     expect(spy).toHaveBeenCalled()
175     expect(component.status).toEqual("Failure!");
176     expect(component.message).toEqual("Definition could not be updated.");
177     expect(component.showDialog).toBe(false);
178     expect(component.closable).toBe(true);
179
180   })
181
182   it('should test close method',()=>{
183     component.showDialog=true;
184     component.close();
185     expect(component.showDialog).toEqual(false);
186     expect(component.closable).toEqual(false);
187   })
188
189   it('should test onTransferDashboardObj method',()=>{
190     expect(component.onTransferDashboardObj('value')).toBeUndefined();
191   })
192
193 });