8442c87304d59496288cffbb9e8baa20912dab95
[portal/sdk.git] /
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3 import { MatPaginatorModule } from '@angular/material/paginator';
4 import { MatSortModule } from '@angular/material/sort';
5 import { MatTableModule } from '@angular/material/table';
6 import { ColumnListComponent } from './column-list.component';
7 import { FormsModule } from '@angular/forms';
8 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
9 import { HttpClientTestingModule } from '@angular/common/http/testing';
10 import { ColumnService } from '../column.service';
11 import 'rxjs/add/observable/of';
12 import { Observable } from 'rxjs/Observable';
13
14
15 describe('ColumnListComponent', () => {
16   let component: ColumnListComponent;
17   let fixture: ComponentFixture<ColumnListComponent>;
18   let _columnService: ColumnService;
19
20
21   beforeEach(async(() => {
22     TestBed.configureTestingModule({
23       declarations: [ ColumnListComponent],
24       imports: [
25         NoopAnimationsModule,
26         MatPaginatorModule,
27         MatSortModule,
28         MatTableModule,
29         FormsModule,
30         HttpClientTestingModule
31       ],
32       schemas: [CUSTOM_ELEMENTS_SCHEMA]
33     }).compileComponents();
34   }));
35
36   beforeEach(() => {
37     fixture = TestBed.createComponent(ColumnListComponent);
38     component = fixture.componentInstance;
39     fixture.detectChanges();
40     _columnService=TestBed.get(ColumnService);
41   });
42
43   it('should compile', () => {
44     expect(component).toBeTruthy();
45   });
46
47   it('should test editRecord method',()=>{
48     component.editRecord("id");
49     expect(component.showSpinner).toBe(true);
50     expect(component.columnId).toEqual("id");
51
52   })
53   
54   it('should test subscribe in editRecord method',()=>{
55     
56     let spy1=spyOn(_columnService,'getIndividualColumnData').and.returnValue(Observable.of('you object'));
57     let spy2=spyOn(_columnService,'getDrillDownReportList').and.returnValue(Observable.of('you object'));
58     let spy3=spyOn(_columnService,'getResponseTotalColsList').and.returnValue(Observable.of('you object'));
59     component.editRecord("id");
60    
61     expect(component.columnId).toEqual("id");
62     expect(spy1).toHaveBeenCalled();
63     expect(spy2).toHaveBeenCalled();
64     expect(spy3).toHaveBeenCalled();
65     
66   })
67
68   it('should test ngOnChanges method',()=>{
69     spyOn(console,'log');
70     component.ngOnChanges();
71     expect(console.log).toHaveBeenCalledWith("Hit");
72   })
73
74   it('should test close method',()=>{
75     let spy1=spyOn(_columnService,'getColumnList').and.returnValue(Observable.of(''));
76     component.close();
77     expect(spy1).toHaveBeenCalled();
78     expect(component.finalObjArr).toEqual([]);
79     expect(component.finalGetObj).toEqual('');
80     expect(component.dataSource.data).toEqual(component.finalObjArr);
81     expect(component.dataSource.sort).toEqual(component.sort);
82     expect(component.dataSource.paginator).toEqual(component.paginator);
83     expect(component.table.dataSource).toEqual(component.dataSource)
84     expect(component.showSpinner).toEqual(false);
85   })
86
87   it('should test complete method',()=>{
88     component.showEditDrillDownPage=true;
89     component.complete();
90     expect(component.showEditDrillDownPage).toBe(false);
91     expect(component.showConfirmButton).toBe(false);
92   })
93
94 it('should test onCompleted method',()=>{
95   component.onCompleted("drilldownParamsArr");
96   expect(component.drilldownParams).toBeUndefined();
97 })
98
99 it('should test save method',()=>{
100   component.noWrap=true;
101   component.save();
102   expect(component.showSpinner).toBe(true);
103   expect(component.finalPOSTObj["tabId"]).toEqual("ColEdit");
104   expect(component.finalPOSTObj["tabName"]).toEqual("Column Edit");
105   expect(component.finalPOSTObj["colId"]).toEqual(component.id);
106   expect(component.finalPOSTObj["colName"]).toEqual(component.name);
107   expect(component.finalPOSTObj["colType"]).toEqual("");
108   expect(component.finalPOSTObj["colspan"]).toEqual(component.colspan);
109   expect(component.finalPOSTObj["dataType"]).toEqual(component.dataType);
110   expect(component.finalPOSTObj["depeondsOnForField"]).toEqual(component.dependsOnFormFields);
111   expect(component.finalPOSTObj["displayAlignment"]).toEqual(component.displayAlignment);
112   expect(component.finalPOSTObj["displayHeaderAlignment"]).toEqual(component.displayHeaderAlignment);
113   expect(component.finalPOSTObj["displayName"]).toEqual(component.displayName);
114   expect(component.finalPOSTObj["displayTotal"]).toEqual(component.displayTotal);
115   expect(component.finalPOSTObj["displayWidth"]).toEqual(10);
116   expect(component.finalPOSTObj["displayWidthInPixel"]).toEqual(component.displayWidthInPixel);
117   //expect(component.finalPOSTObj[""]).toEqual();
118   expect(component.finalPOSTObj["drilldownParams"]).toEqual(component.drilldownParams);
119   expect(component.finalPOSTObj["drilldownType"]).toEqual("");
120   expect(component.finalPOSTObj["drilldownURL"]).toEqual(component.drilldownURL);
121   expect(component.finalPOSTObj["errorMessage"]).toEqual("");
122   expect(component.finalPOSTObj["errorStackTrace"]).toEqual("");
123   expect(component.finalPOSTObj["groupByPos"]).toEqual(component.groupByPos);
124   expect(component.finalPOSTObj["hideRepeatedKey"]).toEqual(component.hideRepeatedValues);
125   expect(component.finalPOSTObj["indentation"]).toEqual(component.indentation);
126   expect(component.finalPOSTObj["level"]).toEqual(component.multiGroupColumnLevel);
127   expect(component.finalPOSTObj["noWrap"]).toEqual("Y");
128   expect(component.finalPOSTObj["sortable"]).toEqual(component.sortable);
129   expect(component.finalPOSTObj["subTotalCustomText"]).toEqual(component.displayTotal);
130   expect(component.finalPOSTObj["visible"]).toEqual(component.visible);
131   
132   
133 })
134
135 it('should test if codition inside save method',()=>{ 
136   component.showSaveColDialog=true;
137   let spy=spyOn(_columnService,'postColumnChanges').and.returnValue(Observable.of('you object'))
138   component.save();
139   expect(spy).toHaveBeenCalled();
140   expect(component.EditColstatus).toEqual("Success!");
141   expect(component.EditColmessage).toEqual("Your change has been saved! Row definition is updated.");
142   expect(component.showSaveColDialog).toBe(false);
143   expect(component.Colclosable).toBe(true);
144 })
145
146 it('should test else codition inside save method',()=>{ 
147   component.showSaveColDialog=true;
148   let spy=spyOn(_columnService,'postColumnChanges').and.returnValue(Observable.of(''))
149   component.save();
150   expect(spy).toHaveBeenCalled();
151   expect(component.EditColstatus).toEqual("Failure!");
152   expect(component.EditColmessage).toEqual("Row definition could not be updated.");
153   expect(component.showSaveColDialog).toBe(false);
154   expect(component.Colclosable).toBe(true);
155 })
156
157 it('should be testing drillDownLinkPage method',()=>{
158   component.showEditDrillDownPage=true
159   component.drillDownLinkPage();
160   expect(component.showEditDrillDownPage).toEqual(false);
161   expect(component.showConfirmButton).toBe(true);
162 })
163
164
165
166 });