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