summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/columns/column-list/column-list.component.spec.ts
blob: c4c200e74824fa8ce2b713a66417bc66657764e6 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MatPaginatorModule } from '@angular/material/paginator';
import { MatSortModule } from '@angular/material/sort';
import { MatTableModule } from '@angular/material/table';
import { ColumnListComponent } from './column-list.component';
import { FormsModule } from '@angular/forms';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ColumnService } from '../column.service';
import 'rxjs/add/observable/of';
import { Observable } from 'rxjs/Observable';
import { HAMMER_LOADER } from '@angular/platform-browser';


describe('ColumnListComponent', () => {
  let component: ColumnListComponent;
  let fixture: ComponentFixture<ColumnListComponent>;
  let _columnService: ColumnService;


  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ ColumnListComponent],
      imports: [
        NoopAnimationsModule,
        MatPaginatorModule,
        MatSortModule,
        MatTableModule,
        FormsModule,
        HttpClientTestingModule
      ],
      providers: [{
        provide: HAMMER_LOADER,
        useValue: () => new Promise(() => {})
      }],
      schemas: [CUSTOM_ELEMENTS_SCHEMA]
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ColumnListComponent);
    component = fixture.componentInstance;
    component.reportId = 123;
    _columnService=TestBed.get(ColumnService);
  });

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

  it('should test editRecord method',()=>{
    component.editRecord("id");
    expect(component.showSpinner).toBe(true);
    expect(component.columnId).toEqual("id");

  })
  
  it('should test subscribe in editRecord method',()=>{
    
    let spy1=spyOn(_columnService,'getIndividualColumnData').and.returnValue(Observable.of('you object'));
    let spy2=spyOn(_columnService,'getDrillDownReportList').and.returnValue(Observable.of('you object'));
    let spy3=spyOn(_columnService,'getResponseTotalColsList').and.returnValue(Observable.of('you object'));
    component.editRecord("id");
    
    expect(component.columnId).toEqual("id");
    expect(spy1).toHaveBeenCalled();
    expect(spy2).toHaveBeenCalled();
    expect(spy3).toHaveBeenCalled();
    
  })

  it('should test ngOnChanges method',()=>{
    spyOn(console,'log');
    component.ngOnChanges();
    expect(console.log).toHaveBeenCalledWith("Hit");
  })

  it('should test close method',()=>{
    let spy1=spyOn(_columnService,'getColumnList').and.returnValue(Observable.of(''));
    const spy = spyOn((component as any).changeDetectorRefs, 'detectChanges');
    component.close();
    expect(spy1).toHaveBeenCalled();
    expect(spy).toHaveBeenCalled();
    expect(component.finalObjArr).toEqual([]);
    expect(component.finalGetObj).toEqual('');
    expect(component.dataSource.data).toEqual(component.finalObjArr);
    expect(component.dataSource.sort).toEqual(component.sort);
    expect(component.dataSource.paginator).toEqual(component.paginator);
    expect(component.table.dataSource).toEqual(component.dataSource)
    expect(component.showSpinner).toEqual(false);
  })

  it('should test complete method',()=>{
    component.showEditDrillDownPage=true;
    component.complete();
    expect(component.showEditDrillDownPage).toBe(false);
    expect(component.showConfirmButton).toBe(false);
  })

it('should test onCompleted method',()=>{
  component.onCompleted("drilldownParamsArr");
  expect(component.drilldownParams).toBeUndefined();
})

it('should test save method',()=>{
  component.noWrap=true;
  const spy = spyOn((component as any).changeDetectorRefs, 'detectChanges');
  component.save();
  expect(spy).toHaveBeenCalled();
  expect(component.showSpinner).toBe(true);
  expect(component.finalPOSTObj["tabId"]).toEqual("ColEdit");
  expect(component.finalPOSTObj["tabName"]).toEqual("Column Edit");
  expect(component.finalPOSTObj["colId"]).toEqual(component.id);
  expect(component.finalPOSTObj["colName"]).toEqual(component.name);
  expect(component.finalPOSTObj["colType"]).toEqual("");
  expect(component.finalPOSTObj["colspan"]).toEqual(component.colspan);
  expect(component.finalPOSTObj["dataType"]).toEqual(component.dataType);
  expect(component.finalPOSTObj["depeondsOnForField"]).toEqual(component.dependsOnFormFields);
  expect(component.finalPOSTObj["displayAlignment"]).toEqual(component.displayAlignment);
  expect(component.finalPOSTObj["displayHeaderAlignment"]).toEqual(component.displayHeaderAlignment);
  expect(component.finalPOSTObj["displayName"]).toEqual(component.displayName);
  expect(component.finalPOSTObj["displayTotal"]).toEqual(component.displayTotal);
  expect(component.finalPOSTObj["displayWidth"]).toEqual(10);
  expect(component.finalPOSTObj["displayWidthInPixel"]).toEqual(component.displayWidthInPixel);
  //expect(component.finalPOSTObj[""]).toEqual();
  expect(component.finalPOSTObj["drilldownParams"]).toEqual(component.drilldownParams);
  expect(component.finalPOSTObj["drilldownType"]).toEqual("");
  expect(component.finalPOSTObj["drilldownURL"]).toEqual(component.drilldownURL);
  expect(component.finalPOSTObj["errorMessage"]).toEqual("");
  expect(component.finalPOSTObj["errorStackTrace"]).toEqual("");
  expect(component.finalPOSTObj["groupByPos"]).toEqual(component.groupByPos);
  expect(component.finalPOSTObj["hideRepeatedKey"]).toEqual(component.hideRepeatedValues);
  expect(component.finalPOSTObj["indentation"]).toEqual(component.indentation);
  expect(component.finalPOSTObj["level"]).toEqual(component.multiGroupColumnLevel);
  expect(component.finalPOSTObj["noWrap"]).toEqual("Y");
  expect(component.finalPOSTObj["sortable"]).toEqual(component.sortable);
  expect(component.finalPOSTObj["subTotalCustomText"]).toEqual(component.displayTotal);
  expect(component.finalPOSTObj["visible"]).toEqual(component.visible);
  
  
})

it('should test if codition inside save method',()=>{ 
  component.showSaveColDialog=true;
  let spy=spyOn(_columnService,'postColumnChanges').and.returnValue(Observable.of('you object'))
  const spy1 = spyOn((component as any).changeDetectorRefs, 'detectChanges');
  component.save();
  expect(spy).toHaveBeenCalled();
  expect(spy1).toHaveBeenCalled();
  expect(component.EditColstatus).toEqual("Success!");
  expect(component.EditColmessage).toEqual("Your change has been saved! Row definition is updated.");
  expect(component.showSaveColDialog).toBe(false);
  expect(component.Colclosable).toBe(true);
})

it('should test else codition inside save method',()=>{ 
  component.showSaveColDialog=true;
  let spy=spyOn(_columnService,'postColumnChanges').and.returnValue(Observable.of(''))
  const spy1 = spyOn((component as any).changeDetectorRefs, 'detectChanges');
  component.save();
  expect(spy).toHaveBeenCalled();
  expect(spy1).toHaveBeenCalled();
  expect(component.EditColstatus).toEqual("Failure!");
  expect(component.EditColmessage).toEqual("Row definition could not be updated.");
  expect(component.showSaveColDialog).toBe(false);
  expect(component.Colclosable).toBe(true);
})

it('should be testing drillDownLinkPage method',()=>{
  component.showEditDrillDownPage=true
  component.drillDownLinkPage();
  expect(component.showEditDrillDownPage).toEqual(false);
  expect(component.showConfirmButton).toBe(true);
})



});