-
Notifications
You must be signed in to change notification settings - Fork 13
/
lightningDataGridTests.resource
240 lines (216 loc) · 9.95 KB
/
lightningDataGridTests.resource
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
describe("Grid Tests", function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
//Reusing the same grid for most tests to save on setup/teardown costs
var cmp;
afterAll(function() {
//Clear the component
$T.clearRenderedTestComponents();
})
describe('Test Lightning-Data-Grid', function(){
it('renders the Data Grid', function(done) {
var renderInto = document.getElementById("renderTestComponents");
$T.createComponent("c:DataGridImpl", {}, renderInto)
.then(function(component) {
expect(component.isRendered()).toBe(true);
cmp = component;
done();
}).catch(function(e) {
done.fail(e);
});
});
it('has a toolbar', function(done) {
var grid = cmp.find("exampleGrid");
var toolbar = grid.find("toolbar");
expect(toolbar).toBeTruthy();
done();
});
it('has headers', function(done) {
var grid = cmp.find("exampleGrid");
var headers = grid.find("headers");
expect(headers).toBeTruthy();
done();
});
it('offsets the view', function(done) {
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.view").length > 0;
}).then(function(){
var grid = cmp.find("exampleGrid");
expect(grid.get("v.data").length).toBe(300);
expect(grid.get("v.view").length).toBe(10);
expect(grid.find("rows").length).toBe(10);
done();
});
});
it('handles mouse wheel events', function(done) {
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.view").length > 0;
}).then(function(){
var grid = cmp.find("exampleGrid");
var table = grid.find("table");
var mouseEnter = new MouseEvent("mouseenter");
table.getElement().dispatchEvent(mouseEnter);
expect(typeof grid.mouseWheelHandler).toBe("function");
//LockerService isn't currently exposing the WheelEvent as a CTOR. Workaround for now.
var wheelDown = new CustomEvent("wheel");
wheelDown.deltaY = 1;
table.getElement().dispatchEvent(wheelDown);
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.offSetIndex") === 11;
}).then(function() {
expect(grid.get("v.offSetIndex")).toBe(11);
expect(grid.get("v.view")[0].data.name).toBe("Contact Name 1");
var wheelUp = new CustomEvent("wheel");
wheelUp.deltaY = -1;
table.getElement().dispatchEvent(wheelUp);
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.offSetIndex") === 10;
}).then(function() {
expect(grid.get("v.offSetIndex")).toBe(10);
expect(grid.get("v.view")[0].data.name).toBe("Contact Name 0");
var mouseLeave = new MouseEvent("mouseleave");
table.getElement().dispatchEvent(mouseLeave);
done();
});
});
});
});
it('handles the child toggle', function(done) {
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.view").length > 0;
}).then(function(){
var grid = cmp.find("exampleGrid");
var rows = grid.find("rows");
var cells = rows[9].find("cells");
cells[0].toggleChildren();
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.hierarchy").length > 100;
}).then(function() {
rows = grid.find("rows");
var subRow = rows[9];
expect(grid.get("v.hierarchy").length).toBe(101);
expect(rows[8].get("v.rowData").expanded).toBe(true);
expect(subRow.get("v.rowData").data.name).toBe("Sub Contact Name 00");
var subCells = subRow.find("cells");
subCells[0].toggleChildren();
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.hierarchy").length > 101;
}).then(function() {
rows = grid.find("rows");
var subSubRow = rows[9];
expect(grid.get("v.hierarchy").length).toBe(102);
expect(rows[8].get("v.rowData").expanded).toBe(true);
expect(subSubRow.get("v.rowData").parent).toBe("Id-Sub-00");
cells[0].toggleChildren();
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.hierarchy").length == 100;
}).then(function() {
expect(grid.get("v.hierarchy").length).toBe(100);
expect(rows[7].get("v.rowData").expanded).toBe(false);
done();
});
});
});
});
});
it('handles a data refresh', function(done) {
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.view").length > 0;
}).then(function(){
var grid = cmp.find("exampleGrid");
var data = grid.get("v.data");
data[0].data.name = "Captain Hook";
grid.set("v.data", data);
grid.refresh();
var view = grid.get("v.view");
expect(view[0].data.name).toBe("Captain Hook");
done();
});
});
it('handles a cell edit', function(done) {
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.view").length > 0;
}).then(function(){
var grid = cmp.find("exampleGrid");
var rows = grid.find("rows");
var cells = rows[7].find("cells");
var dataItem = cells[0].get("v.dataItem");
var childrenVisible = cells[0].get("v.childrenVisible");
var cellEle = document.getElementById("ltng-grid-col-name-row-0-clickable");
var dblClickEvent = new MouseEvent('dblclick');
cellEle.dispatchEvent(dblClickEvent);
expect(cells[0].get("v.editMode")).toBe(true);
var editor = cells[0].get("v.editors")[0];
editor.set("v.value", "Peter Venkman");
cells[0].editCell();
expect(cells[0].get("v.editMode")).toBe(false);
expect(grid.get("v.data")[0].data.name).toBe("Peter Venkman");
done();
});
});
it('handles a search', function(done) {
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.view").length > 0;
}).then(function() {
var grid = cmp.find("exampleGrid");
var searchbar = cmp.find("search");
searchbar.set("v.query", "Peter Venkman");
searchbar.search();
return $T.waitFor(function() {
var grid = cmp.find("exampleGrid");
return grid.get("v.view").length == 1;
}).then(function() {
var grid = cmp.find("exampleGrid");
var rows = grid.find("rows");
expect(rows.length).toBe(1);
done();
});
});
});
it('handles larger volume', function(done) {
$T.clearRenderedTestComponents();
var renderInto = document.getElementById("renderTestComponents");
$T.createComponent("c:DataGridImpl", {"dataSize": 1000}, renderInto)
.then(function(component) {
return $T.waitFor(function() {
var grid = component.find("exampleGrid");
return grid.get("v.view").length > 0;
}).then(function(){
var grid = component.find("exampleGrid");
expect(grid.get("v.view").length).toBe(10);
done();
});
}).catch(function(e) {
done.fail(e);
});
});
it('renders a grid instead of a tree', function(done) {
$T.clearRenderedTestComponents();
var renderInto = document.getElementById("renderTestComponents");
$T.createComponent("c:DataGridImpl", {"type": "grid"}, renderInto)
.then(function(component) {
return $T.waitFor(function() {
var grid = component.find("exampleGrid");
return grid.get("v.view").length > 0;
}).then(function(){
var grid = component.find("exampleGrid");
expect(grid.get("v.view").length).toBe(10);
done();
});
}).catch(function(e) {
done.fail(e);
});
});
$T.clearRenderedTestComponents();
});
});