@salesforce/design-system-react 0.10.50-alpha.1 → 0.10.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/components/accordion/__tests__/accordion.browser-test.jsx +302 -0
  2. package/components/alert/__tests__/alert.browser-test.jsx +100 -0
  3. package/components/app-launcher/__tests__/app-launcher.browser-test.jsx +228 -0
  4. package/components/app-launcher/__tests__/expandable-section.browser-test.jsx +144 -0
  5. package/components/app-launcher/__tests__/link.browser-test.jsx +107 -0
  6. package/components/app-launcher/__tests__/tile.browser-test.jsx +267 -0
  7. package/components/avatar/__tests__/avatar.browser-test.jsx +207 -0
  8. package/components/builder-header/__tests__/builder-header.browser-test.jsx +53 -0
  9. package/components/button/__tests__/button.browser-test.jsx +226 -0
  10. package/components/button-group/__tests__/button-group.browser-test.jsx +144 -0
  11. package/components/button-stateful/__tests__/button-stateful.browser-test.jsx +125 -0
  12. package/components/card/__tests__/card.browser-test.jsx +255 -0
  13. package/components/carousel/__tests__/carousel.browser-test.jsx +527 -0
  14. package/components/color-picker/__tests__/color-picker.browser-test.jsx +767 -0
  15. package/components/combobox/__tests__/combobox.browser-test.jsx +654 -0
  16. package/components/data-table/__tests__/data-table.browser-test.jsx +1051 -0
  17. package/components/date-picker/__tests__/__snapshots__/datepicker.dom-snapshot-test.jsx.snap +4429 -0
  18. package/components/date-picker/__tests__/date-picker.browser-test.jsx +497 -0
  19. package/components/date-picker/__tests__/datepicker.dom-snapshot-test.jsx +109 -0
  20. package/components/docked-composer/__tests__/docked-composer.browser-test.jsx +83 -0
  21. package/components/expandable-section/__tests__/expandable-section.browser-test.jsx +133 -0
  22. package/components/expression/__tests__/expression.browser-test.jsx +255 -0
  23. package/components/filter/__tests__/filter.browser-test.jsx +147 -0
  24. package/components/forms/input/__tests__/inline.browser-test.jsx +164 -0
  25. package/components/global-header/__tests__/global-header.browser-test.jsx +177 -0
  26. package/components/global-navigation-bar/__tests__/global-navigation-bar.browser-test.jsx +464 -0
  27. package/components/icon/__tests__/icon.browser-test.jsx +214 -0
  28. package/components/illustration/__tests__/illustration.browser-test.jsx +177 -0
  29. package/components/input/__tests__/input.browser-test.jsx +612 -0
  30. package/components/location-map/__tests__/location-map.browser-test.jsx +158 -0
  31. package/components/lookup/__tests__/lookup.browser-test.jsx +353 -0
  32. package/components/media-object/__tests__/media-object.browser-test.jsx +87 -0
  33. package/components/menu-dropdown/__tests__/dropdown.browser-test.jsx +588 -0
  34. package/components/menu-picklist/__tests__/menupicklist.snapshot-old-test.jsx +41 -0
  35. package/components/menu-picklist/__tests__/picklist-base.browser-test.jsx +275 -0
  36. package/components/modal/__tests__/modal.browser-test.jsx +333 -0
  37. package/components/notification/__tests__/notification.browser-test.jsx +113 -0
  38. package/components/page-header/__tests__/page-header.browser-test.jsx +161 -0
  39. package/components/panel/__tests__/__snapshots__/filtering.dom-snapshot-test.jsx.snap +298 -0
  40. package/components/panel/__tests__/filtering.dom-snapshot-test.jsx +9 -0
  41. package/components/pill/__tests__/pill.browser-test.jsx +308 -0
  42. package/components/pill-container/__tests__/pill-container.browser-test.jsx +186 -0
  43. package/components/popover/__tests__/popover.browser-test.jsx +327 -0
  44. package/components/progress-indicator/__tests__/progress-indicator.browser-test.jsx +335 -0
  45. package/components/radio-button-group/__tests__/radio-button-group.browser-test.jsx +122 -0
  46. package/components/radio-group/__tests__/radio-group.browser-test.jsx +119 -0
  47. package/components/setup-assistant/__tests__/setup-assistant.browser-test.jsx +77 -0
  48. package/components/slider/__tests__/slider.browser-test.jsx +389 -0
  49. package/components/spinner/__tests__/spinner.browser-test.jsx +57 -0
  50. package/components/split-view/__tests__/split-view.listbox.browser-test.jsx +225 -0
  51. package/components/split-view/__tests__/split-view.listbox.header.browser-test.jsx +158 -0
  52. package/components/split-view/__tests__/split-view.listbox.unread.browser-test.jsx +114 -0
  53. package/components/tabs/__tests__/tabs.browser-test.jsx +458 -0
  54. package/components/textarea/__tests__/textarea.browser-test.jsx +175 -0
  55. package/components/time-picker/__tests__/time-picker.browser-test.jsx +46 -0
  56. package/components/toast/__tests__/toast.browser-test.jsx +118 -0
  57. package/components/tooltip/__tests__/tooltip.browser-test.jsx +214 -0
  58. package/components/tree/__tests__/tree.browser-test.jsx +303 -0
  59. package/components/vertical-navigation/__tests__/navigation.browser-test.jsx +117 -0
  60. package/components/visual-picker/__tests__/visual-picker.browser-test.jsx +288 -0
  61. package/components/welcome-mat/__tests__/welcome-mat.browser-test.jsx +358 -0
  62. package/design-system-react-components.js +1 -1
  63. package/design-system-react-components.min.js.LICENSE.txt +1 -1
  64. package/design-system-react.js +1 -1
  65. package/design-system-react.min.js.LICENSE.txt +1 -1
  66. package/lib/design-system-react-components.min.js.LICENSE.txt +1 -1
  67. package/lib/design-system-react.min.js.LICENSE.txt +1 -1
  68. package/lib/package.json +1 -1
  69. package/package.json +1 -1
@@ -0,0 +1,1051 @@
1
+ /* eslint-disable max-lines */
2
+ import React from 'react';
3
+ import ReactDOM from 'react-dom';
4
+ import TestUtils from 'react-dom/test-utils';
5
+
6
+ import chai, { expect } from 'chai';
7
+
8
+ import { keyObjects } from '../../../utilities/key-code';
9
+
10
+ import Dropdown from '../../menu-dropdown';
11
+ import DataTable from '../../data-table';
12
+ import DataTableColumn from '../../data-table/column';
13
+ import DataTableRowActions from '../../data-table/row-actions';
14
+ import DataTableHighlightCell from '../../data-table/highlight-cell';
15
+ import IconSettings from '../../icon-settings';
16
+ import {
17
+ mountComponent,
18
+ unmountComponent,
19
+ } from '../../../tests/enzyme-helpers';
20
+
21
+ chai.should();
22
+
23
+ const { Simulate } = TestUtils;
24
+
25
+ describe('DataTable: ', function describeFunction() {
26
+ const items = [
27
+ {
28
+ id: '8IKZHZZV80',
29
+ name: 'Cloudhub',
30
+ count: 100976,
31
+ lastModified: 'Yesterday',
32
+ },
33
+ {
34
+ id: '5GJOOOPWU7',
35
+ name: 'Cloudhub + Anypoint Connectors',
36
+ count: 54976,
37
+ lastModified: 'Today',
38
+ },
39
+ {
40
+ id: 'Q8Z71ZUCEZ',
41
+ name: 'Cloud City',
42
+ count: 101280,
43
+ lastModified: 'Today',
44
+ },
45
+ {
46
+ id: '2FSH2DP0LY',
47
+ name: 'IoT',
48
+ count: 976,
49
+ lastModified: 'Yesterday',
50
+ },
51
+ {
52
+ id: '8NE888QKV1',
53
+ name: 'IoT + Anypoint Connectors',
54
+ count: 54976,
55
+ lastModified: 'Today',
56
+ },
57
+ {
58
+ id: 'M4D37GW83H',
59
+ name: 'Salesforce Tower',
60
+ count: 101280,
61
+ lastModified: 'Today',
62
+ },
63
+ ];
64
+
65
+ const itemsWithHeaderRows = [
66
+ {
67
+ id: 'K6R34GW73J',
68
+ type: 'header-row',
69
+ name: 'Address',
70
+ count: 101210,
71
+ lastModified: 'Today',
72
+ },
73
+ ...items,
74
+ {
75
+ id: 'KA78KJAY76',
76
+ type: 'header-row',
77
+ name: 'Company',
78
+ count: 101318,
79
+ lastModified: 'Today',
80
+ },
81
+ ];
82
+
83
+ const columns = [
84
+ {
85
+ label: 'Name',
86
+ property: 'name',
87
+ truncate: true,
88
+ },
89
+ {
90
+ label: 'Count',
91
+ property: 'count',
92
+ sortable: true,
93
+ },
94
+ ];
95
+
96
+ const defaultProps = {
97
+ id: 'DataTableExample-default',
98
+ items,
99
+ selectRows: true,
100
+ };
101
+
102
+ const defaultPropsWithHeaderRows = {
103
+ ...defaultProps,
104
+ items: itemsWithHeaderRows,
105
+ };
106
+
107
+ const renderTable = (instance) =>
108
+ function renderTableFunction() {
109
+ this.dom = document.createElement('div');
110
+ document.body.appendChild(this.dom);
111
+ /* deepscan-disable REACT_ASYNC_RENDER_RETURN_VALUE */
112
+ // eslint-disable-next-line react/no-render-return-value
113
+ this.component = ReactDOM.render(
114
+ <div>
115
+ <IconSettings iconPath="/assets/icons">{instance}</IconSettings>
116
+ </div>,
117
+ this.dom
118
+ );
119
+ /* deepscan-enable REACT_ASYNC_RENDER_RETURN_VALUE */
120
+ };
121
+
122
+ function removeTable() {
123
+ ReactDOM.unmountComponentAtNode(this.dom);
124
+ document.body.removeChild(this.dom);
125
+ }
126
+
127
+ const getTable = (dom) => dom.querySelector('.slds-table');
128
+
129
+ const getRow = (dom, row) => {
130
+ const tbody = getTable(dom).querySelectorAll('tbody')[0];
131
+ return tbody.querySelectorAll('tr')[row - 1];
132
+ };
133
+
134
+ const getCell = (dom, row, column) => {
135
+ const tr = getRow(dom, row);
136
+ return tr.querySelectorAll('td')[column];
137
+ };
138
+
139
+ const getMenu = (dom) => dom.querySelector('.slds-dropdown');
140
+
141
+ describe('Structure', function describeFunction2() {
142
+ beforeEach(
143
+ renderTable(
144
+ <DataTable {...defaultProps}>
145
+ {columns.map((columnProps) => (
146
+ <DataTableColumn {...columnProps} key={columnProps.property} />
147
+ ))}
148
+ </DataTable>
149
+ )
150
+ );
151
+
152
+ afterEach(removeTable);
153
+
154
+ it('has a header', function () {
155
+ const thead = getTable(this.dom).querySelectorAll('thead');
156
+ thead.should.have.length(1);
157
+ thead[0].querySelectorAll('th').should.have.length(3);
158
+ });
159
+
160
+ it('has a row for each item', function () {
161
+ const tbody = getTable(this.dom).querySelectorAll('tbody');
162
+ tbody.should.have.length(1);
163
+ tbody[0].querySelectorAll('tr').should.have.length(6);
164
+ });
165
+
166
+ it('renders the correct contents in each cell', function () {
167
+ const firstName = getCell(this.dom, 1, 1);
168
+ firstName.innerHTML.should.equal(
169
+ '<div class="" title="Cloudhub">Cloudhub</div>'
170
+ );
171
+ const secondCount = getCell(this.dom, 2, 2);
172
+ secondCount.innerHTML.should.equal(
173
+ '<div class="" title="54976">54976</div>'
174
+ );
175
+ });
176
+
177
+ it('has checkboxes when selectRows is true or "checkbox"', function () {
178
+ let checkboxes = getTable(this.dom).querySelectorAll('.slds-checkbox');
179
+ checkboxes.should.have.length(7);
180
+ removeTable.call(this);
181
+
182
+ renderTable(
183
+ <DataTable {...defaultProps} selectRows={false}>
184
+ {columns.map((columnProps) => (
185
+ <DataTableColumn {...columnProps} key={columnProps.property} />
186
+ ))}
187
+ </DataTable>
188
+ ).call(this);
189
+ checkboxes = getTable(this.dom).querySelectorAll('.slds-checkbox');
190
+ checkboxes.should.have.length(0);
191
+ removeTable.call(this);
192
+
193
+ renderTable(
194
+ <DataTable {...defaultProps} selectRows="checkbox">
195
+ {columns.map((columnProps) => (
196
+ <DataTableColumn {...columnProps} key={columnProps.property} />
197
+ ))}
198
+ </DataTable>
199
+ ).call(this);
200
+ checkboxes = getTable(this.dom).querySelectorAll('.slds-checkbox');
201
+ checkboxes.should.have.length(7);
202
+ });
203
+
204
+ it('has radios only when selectRows is "radio"', function () {
205
+ const checkboxes = getTable(this.dom).querySelectorAll('.slds-checkbox');
206
+ checkboxes.should.have.length(7);
207
+ removeTable.call(this);
208
+
209
+ renderTable(
210
+ <DataTable {...defaultProps} selectRows="radio">
211
+ {columns.map((columnProps) => (
212
+ <DataTableColumn {...columnProps} key={columnProps.property} />
213
+ ))}
214
+ </DataTable>
215
+ ).call(this);
216
+ const radios = getTable(this.dom).querySelectorAll('.slds-radio');
217
+ radios.should.have.length(6);
218
+ });
219
+ });
220
+
221
+ describe('Selectable - Checkbox', function describeFunction2() {
222
+ const defaultSelection = [
223
+ {
224
+ id: '8IKZHZZV80',
225
+ name: 'Cloudhub',
226
+ count: 100976,
227
+ lastModified: 'Yesterday',
228
+ },
229
+ ];
230
+
231
+ afterEach(removeTable);
232
+
233
+ it('can start with a row selected', function () {
234
+ renderTable(
235
+ <DataTable {...defaultProps} selection={defaultSelection}>
236
+ {columns.map((columnProps) => (
237
+ <DataTableColumn {...columnProps} key={columnProps.property} />
238
+ ))}
239
+ </DataTable>
240
+ ).call(this);
241
+
242
+ const tbody = getTable(this.dom).querySelectorAll('tbody')[0];
243
+ const selectedRows = tbody.querySelectorAll('tr.slds-is-selected');
244
+ selectedRows.should.have.length(1);
245
+ const checkedBoxes = tbody.querySelectorAll(
246
+ '.slds-checkbox input:checked'
247
+ );
248
+ checkedBoxes.should.have.length(1);
249
+ });
250
+
251
+ it('can deselect a row', function (done) {
252
+ this.onRowChange = (event, { selection }) => {
253
+ selection.should.have.length(0);
254
+ done();
255
+ };
256
+
257
+ renderTable(
258
+ <DataTable
259
+ {...defaultProps}
260
+ selection={defaultSelection}
261
+ onRowChange={this.onRowChange}
262
+ >
263
+ {columns.map((columnProps) => (
264
+ <DataTableColumn {...columnProps} key={columnProps.property} />
265
+ ))}
266
+ </DataTable>
267
+ ).call(this);
268
+
269
+ const tbody = getTable(this.dom).querySelectorAll('tbody')[0];
270
+ const selectedRow = tbody.querySelectorAll('tr.slds-is-selected')[0];
271
+ const checkbox = selectedRow.querySelectorAll('.slds-checkbox input')[0];
272
+ Simulate.change(checkbox, { target: { checked: false } });
273
+ });
274
+
275
+ it('can select a row', function (done) {
276
+ this.onRowChange = (event, { selection }) => {
277
+ selection.should.have.length(2);
278
+ selection[1].id.should.equal('5GJOOOPWU7');
279
+ done();
280
+ };
281
+
282
+ renderTable(
283
+ <DataTable
284
+ {...defaultProps}
285
+ selection={defaultSelection}
286
+ onRowChange={this.onRowChange}
287
+ >
288
+ {columns.map((columnProps) => (
289
+ <DataTableColumn {...columnProps} key={columnProps.property} />
290
+ ))}
291
+ </DataTable>
292
+ ).call(this);
293
+
294
+ const secondRow = getRow(this.dom, 2);
295
+ const checkbox = secondRow.querySelectorAll('.slds-checkbox input')[0];
296
+
297
+ Simulate.change(checkbox, { target: { checked: true } });
298
+ });
299
+
300
+ it('can select all rows', function (done) {
301
+ this.onRowChange = (event, { selection }) => {
302
+ selection.should.have.length(6);
303
+ done();
304
+ };
305
+
306
+ renderTable(
307
+ <DataTable {...defaultProps} onRowChange={this.onRowChange}>
308
+ {columns.map((columnProps) => (
309
+ <DataTableColumn {...columnProps} key={columnProps.property} />
310
+ ))}
311
+ </DataTable>
312
+ ).call(this);
313
+
314
+ const thead = getTable(this.dom).querySelectorAll('thead')[0];
315
+ const checkAll = thead.querySelectorAll('.slds-checkbox input')[0];
316
+
317
+ Simulate.change(checkAll, { target: { checked: true } });
318
+ });
319
+
320
+ it('can deselect all rows', function (done) {
321
+ this.onRowChange = (event, { selection }) => {
322
+ selection.should.have.length(0);
323
+ done();
324
+ };
325
+
326
+ renderTable(
327
+ <DataTable
328
+ {...defaultProps}
329
+ selection={items}
330
+ onRowChange={this.onRowChange}
331
+ >
332
+ {columns.map((columnProps) => (
333
+ <DataTableColumn {...columnProps} key={columnProps.property} />
334
+ ))}
335
+ </DataTable>
336
+ ).call(this);
337
+
338
+ const thead = getTable(this.dom).querySelectorAll('thead')[0];
339
+ const checkAll = thead.querySelectorAll('.slds-checkbox input')[0];
340
+
341
+ Simulate.change(checkAll, { target: { checked: false } });
342
+ });
343
+
344
+ it('can select all rows with header-rows present', function (done) {
345
+ this.onRowChange = (event, { selection }) => {
346
+ selection.should.have.length(6);
347
+ done();
348
+ };
349
+
350
+ renderTable(
351
+ <DataTable
352
+ {...defaultPropsWithHeaderRows}
353
+ onRowChange={this.onRowChange}
354
+ >
355
+ {columns.map((columnProps) => (
356
+ <DataTableColumn {...columnProps} key={columnProps.property} />
357
+ ))}
358
+ </DataTable>
359
+ ).call(this);
360
+
361
+ const thead = getTable(this.dom).querySelectorAll('thead')[0];
362
+ const checkAll = thead.querySelectorAll('.slds-checkbox input')[0];
363
+
364
+ Simulate.change(checkAll, { target: { checked: true } });
365
+ });
366
+
367
+ it('can deselect all rows with header-rows present', function (done) {
368
+ this.onRowChange = (event, { selection }) => {
369
+ selection.should.have.length(0);
370
+ done();
371
+ };
372
+
373
+ renderTable(
374
+ <DataTable
375
+ {...defaultPropsWithHeaderRows}
376
+ selection={items}
377
+ onRowChange={this.onRowChange}
378
+ >
379
+ {columns.map((columnProps) => (
380
+ <DataTableColumn {...columnProps} key={columnProps.property} />
381
+ ))}
382
+ </DataTable>
383
+ ).call(this);
384
+
385
+ const thead = getTable(this.dom).querySelectorAll('thead')[0];
386
+ const checkAll = thead.querySelectorAll('.slds-checkbox input')[0];
387
+
388
+ Simulate.change(checkAll, { target: { checked: false } });
389
+ });
390
+ });
391
+
392
+ describe('Selectable - Radio', function describeFunction2() {
393
+ const defaultSelection = [
394
+ {
395
+ id: '8IKZHZZV80',
396
+ name: 'Cloudhub',
397
+ count: 100976,
398
+ lastModified: 'Yesterday',
399
+ },
400
+ ];
401
+
402
+ afterEach(removeTable);
403
+
404
+ it('can start with a row selected', function () {
405
+ renderTable(
406
+ <DataTable
407
+ {...defaultProps}
408
+ selection={defaultSelection}
409
+ selectRows="radio"
410
+ >
411
+ {columns.map((columnProps) => (
412
+ <DataTableColumn {...columnProps} key={columnProps.property} />
413
+ ))}
414
+ </DataTable>
415
+ ).call(this);
416
+
417
+ const tbody = getTable(this.dom).querySelectorAll('tbody')[0];
418
+ const selectedRows = tbody.querySelectorAll('tr.slds-is-selected');
419
+ selectedRows.should.have.length(1);
420
+ const radios = tbody.querySelectorAll('.slds-radio input:checked');
421
+ radios.should.have.length(1);
422
+ });
423
+
424
+ it('can select a row', function (done) {
425
+ this.onRowChange = (event, { selection }) => {
426
+ selection.should.have.length(1);
427
+ selection[0].id.should.equal('5GJOOOPWU7');
428
+ done();
429
+ };
430
+
431
+ renderTable(
432
+ <DataTable
433
+ {...defaultProps}
434
+ selection={defaultSelection}
435
+ selectRows="radio"
436
+ onRowChange={this.onRowChange}
437
+ >
438
+ {columns.map((columnProps) => (
439
+ <DataTableColumn {...columnProps} key={columnProps.property} />
440
+ ))}
441
+ </DataTable>
442
+ ).call(this);
443
+
444
+ const secondRow = getRow(this.dom, 2);
445
+ const radio = secondRow.querySelectorAll('.slds-radio input')[0];
446
+
447
+ Simulate.change(radio, { target: { checked: true } });
448
+ });
449
+ });
450
+
451
+ describe('Sortable', function describeFunction2() {
452
+ afterEach(removeTable);
453
+
454
+ it('first clicked on sortable column header should result in ascending sort by default', function (done) {
455
+ this.onSort = (data) => {
456
+ data.property.should.equal('count');
457
+ data.sortDirection.should.equal('asc');
458
+ done();
459
+ };
460
+
461
+ renderTable(
462
+ <DataTable {...defaultProps} fixedLayout onSort={this.onSort}>
463
+ {columns.map((columnProps) => (
464
+ <DataTableColumn {...columnProps} key={columnProps.property} />
465
+ ))}
466
+ </DataTable>
467
+ ).call(this);
468
+
469
+ const thead = getTable(this.dom).querySelectorAll('thead')[0];
470
+ const sortButton = thead.querySelectorAll('a')[0];
471
+
472
+ Simulate.click(sortButton, {});
473
+ });
474
+
475
+ it('if isDefaultSortDescending is true, first click on sortable column header should result in descending order', function (done) {
476
+ this.onSort = (data) => {
477
+ data.property.should.equal('count');
478
+ data.sortDirection.should.equal('desc');
479
+ done();
480
+ };
481
+
482
+ renderTable(
483
+ <DataTable {...defaultProps} fixedLayout onSort={this.onSort}>
484
+ {columns.map((columnProps) => (
485
+ <DataTableColumn
486
+ {...columnProps}
487
+ isDefaultSortDescending
488
+ key={columnProps.property}
489
+ />
490
+ ))}
491
+ </DataTable>
492
+ ).call(this);
493
+
494
+ const thead = getTable(this.dom).querySelectorAll('thead')[0];
495
+ const sortButton = thead.querySelectorAll('a')[0];
496
+
497
+ Simulate.click(sortButton, {});
498
+ });
499
+
500
+ it('does not call onSort when a non-sortable column is clicked', function (done) {
501
+ this.onSort = () => {
502
+ done('sort called');
503
+ };
504
+
505
+ renderTable(
506
+ <DataTable {...defaultProps} onSort={this.onSort}>
507
+ {columns.map((columnProps) => (
508
+ <DataTableColumn {...columnProps} key={columnProps.property} />
509
+ ))}
510
+ </DataTable>
511
+ ).call(this);
512
+
513
+ const thead = getTable(this.dom).querySelectorAll('thead')[0];
514
+ const secondColumn = thead.querySelectorAll('th')[1];
515
+
516
+ Simulate.click(secondColumn, {});
517
+ setTimeout(done, 0);
518
+ });
519
+ });
520
+
521
+ describe('w/ RowActions', function describeFunction2() {
522
+ afterEach(removeTable);
523
+
524
+ it('renders the RowActions and uses dropdown override property', function () {
525
+ renderTable(
526
+ <DataTable {...defaultProps}>
527
+ {columns.map((columnProps) => (
528
+ <DataTableColumn {...columnProps} key={columnProps.property} />
529
+ ))}
530
+ <DataTableRowActions
531
+ dropdown={
532
+ <Dropdown
533
+ options={[
534
+ {
535
+ id: 0,
536
+ label: 'Add to Group',
537
+ value: '1',
538
+ },
539
+ {
540
+ id: 1,
541
+ label: 'Publish',
542
+ value: '2',
543
+ },
544
+ ]}
545
+ />
546
+ }
547
+ />
548
+ </DataTable>
549
+ ).call(this);
550
+ const rowActionMenus = [
551
+ ...this.component.getElementsByTagName('button'),
552
+ ].filter((button) => button.textContent === 'Actions');
553
+ rowActionMenus.should.have.length(6);
554
+ });
555
+
556
+ it('calls onAction & onSelect when an action is clicked', function (done) {
557
+ let expectedCalbacks = 2;
558
+
559
+ this.onAction = (item, action) => {
560
+ item.id.should.equal('8IKZHZZV80');
561
+ action.value.should.equal('1');
562
+ // eslint-disable-next-line no-plusplus
563
+ if (!--expectedCalbacks) done();
564
+ };
565
+
566
+ this.onSelect = (action) => {
567
+ action.value.should.equal('1');
568
+ // eslint-disable-next-line no-plusplus
569
+ if (!--expectedCalbacks) done();
570
+ };
571
+
572
+ renderTable(
573
+ <DataTable {...defaultProps}>
574
+ {columns.map((columnProps) => (
575
+ <DataTableColumn {...columnProps} key={columnProps.property} />
576
+ ))}
577
+ <DataTableRowActions
578
+ onAction={this.onAction}
579
+ options={[
580
+ {
581
+ id: 0,
582
+ label: 'Add to Group',
583
+ value: '1',
584
+ },
585
+ {
586
+ id: 1,
587
+ label: 'Publish',
588
+ value: '2',
589
+ },
590
+ ]}
591
+ dropdown={<Dropdown onSelect={this.onSelect} />}
592
+ />
593
+ </DataTable>
594
+ ).call(this);
595
+
596
+ const trigger = [...this.component.getElementsByTagName('button')].filter(
597
+ (button) => button.textContent === 'Actions'
598
+ )[0];
599
+ Simulate.click(trigger, {});
600
+
601
+ setTimeout(() => {
602
+ const menu = getMenu(document.body);
603
+ const firstAction = menu.querySelectorAll('.slds-dropdown__item')[0];
604
+ Simulate.click(firstAction.querySelector('a'), {});
605
+ }, 0);
606
+ });
607
+ });
608
+
609
+ describe('w/ HighlightCell', function describeFunction2() {
610
+ afterEach(removeTable);
611
+
612
+ it('marks the appropriate text in a cell', function () {
613
+ renderTable(
614
+ <DataTable {...defaultProps} search="Cloud">
615
+ {columns.map((columnProps) => (
616
+ <DataTableColumn {...columnProps} key={columnProps.property}>
617
+ <DataTableHighlightCell />
618
+ </DataTableColumn>
619
+ ))}
620
+ </DataTable>
621
+ ).call(this);
622
+
623
+ const secondRow = getRow(this.dom, 2);
624
+ const markedText = secondRow.querySelectorAll('mark')[0];
625
+ markedText.innerHTML.should.equal('Cloud');
626
+ });
627
+ });
628
+
629
+ describe('w/ Fixed Headers', function describeFunction2() {
630
+ afterEach(removeTable);
631
+
632
+ it('Renders a fixedHeader table as expected', function () {
633
+ renderTable(
634
+ <DataTable
635
+ {...defaultProps}
636
+ fixedHeader
637
+ fixedLayout
638
+ id="DataTable-FixedHeader-Test"
639
+ onFixedHeaderResize={(event, data) => {
640
+ expect(Array.isArray(data.headerRefs)).to.eql(true);
641
+ expect(data.headerRefs.length).to.eql(4);
642
+ data.headerRefs.forEach((ref) => {
643
+ expect(typeof ref).to.eql('object');
644
+ });
645
+ expect(typeof data.scrollerRef).to.eql('object');
646
+ expect(
647
+ data.scrollerRef.className.search(
648
+ 'slds-table_header-fixed_scroller'
649
+ ) >= 0
650
+ ).to.eql(true);
651
+ }}
652
+ onToggleFixedHeaderListeners={(event, data) => {
653
+ expect(typeof data.attach).to.eql('boolean');
654
+ expect(typeof data.resizeHandler).to.eql('function');
655
+ expect(typeof data.scrollerRef).to.eql('object');
656
+ expect(
657
+ data.scrollerRef.className.search(
658
+ 'slds-table_header-fixed_scroller'
659
+ ) >= 0
660
+ ).to.eql(true);
661
+ }}
662
+ selectRows="checkbox"
663
+ >
664
+ <DataTableColumn
665
+ isSorted
666
+ label="Name"
667
+ primaryColumn
668
+ property="name"
669
+ sortable
670
+ sortDirection="asc"
671
+ />
672
+ <DataTableColumn label="Count" property="count" />
673
+ <DataTableRowActions
674
+ options={[
675
+ {
676
+ id: 0,
677
+ label: 'Add to Group',
678
+ value: '1',
679
+ },
680
+ {
681
+ id: 1,
682
+ label: 'Publish',
683
+ value: '2',
684
+ },
685
+ ]}
686
+ onAction={() => {}}
687
+ dropdown={<Dropdown length="5" />}
688
+ />
689
+ </DataTable>
690
+ ).call(this);
691
+
692
+ expect(
693
+ this.dom.querySelectorAll('.slds-table_header-fixed_container').length
694
+ ).to.eql(1);
695
+ expect(
696
+ this.dom.querySelectorAll('.slds-table_header-fixed_scroller').length
697
+ ).to.eql(1);
698
+ expect(
699
+ this.dom
700
+ .querySelector('table.slds-table')
701
+ .className.search('slds-table_header-fixed') >= 0
702
+ ).to.eql(true);
703
+ expect(this.dom.querySelectorAll('thead .slds-cell-fixed').length).to.eql(
704
+ 4
705
+ );
706
+ });
707
+
708
+ it('Renders a fixedHeader table with column resizing functionality as expected', function () {
709
+ renderTable(
710
+ <DataTable
711
+ {...defaultProps}
712
+ fixedHeader
713
+ fixedLayout
714
+ resizable
715
+ id="DataTable-resizable-cols-Test"
716
+ >
717
+ <DataTableColumn
718
+ isSorted
719
+ label="Name"
720
+ primaryColumn
721
+ property="name"
722
+ sortable
723
+ sortDirection="asc"
724
+ />
725
+ <DataTableColumn label="Count" property="count" />
726
+ <DataTableRowActions
727
+ options={[
728
+ {
729
+ id: 0,
730
+ label: 'Add to Group',
731
+ value: '1',
732
+ },
733
+ {
734
+ id: 1,
735
+ label: 'Publish',
736
+ value: '2',
737
+ },
738
+ ]}
739
+ onAction={() => {}}
740
+ dropdown={<Dropdown length="5" />}
741
+ />
742
+ </DataTable>
743
+ ).call(this);
744
+
745
+ // actions column is not resizable
746
+ expect(this.dom.querySelectorAll('.grip-resizable').length).to.eql(4);
747
+ expect(this.dom.querySelectorAll('.grip-container').length).to.eql(1);
748
+ });
749
+ });
750
+
751
+ describe('Column resizing', function describeFunction2() {
752
+ beforeEach(
753
+ mountComponent(
754
+ <DataTable
755
+ {...defaultProps}
756
+ fixedLayout
757
+ keyboardNavigation
758
+ resizable
759
+ resizableOptions={{
760
+ resizeMode: 'overflow',
761
+ onResize: () => {},
762
+ }}
763
+ >
764
+ {[
765
+ ...columns.map((columnProps) => (
766
+ <DataTableColumn {...columnProps} key={columnProps.property} />
767
+ )),
768
+ ...[
769
+ <DataTableRowActions
770
+ key="actions"
771
+ options={[
772
+ {
773
+ id: 0,
774
+ label: 'Add to Group',
775
+ value: '1',
776
+ },
777
+ {
778
+ id: 1,
779
+ label: 'Publish',
780
+ value: '2',
781
+ },
782
+ ]}
783
+ onAction={() => {}}
784
+ dropdown={<Dropdown length="5" />}
785
+ />,
786
+ ],
787
+ ]}
788
+ </DataTable>
789
+ )
790
+ );
791
+
792
+ afterEach(unmountComponent);
793
+
794
+ it('Resize functionality should work with left key', function () {
795
+ const initial = this.dom.querySelectorAll('th')[0].style.width;
796
+
797
+ let cell = this.wrapper.find('td').first();
798
+ cell.simulate('focus');
799
+ expect(this.wrapper.find('td').first().prop('tabIndex')).to.equal('0');
800
+
801
+ cell.simulate('keyDown', keyObjects.UP);
802
+ cell = this.wrapper.find('th').at(0);
803
+ expect(this.wrapper.find('th').first().prop('tabIndex')).to.equal('0');
804
+
805
+ cell.simulate('keyDown', keyObjects.ENTER);
806
+ cell.simulate('keyDown', keyObjects.LEFT);
807
+ cell.simulate('keyDown', keyObjects.LEFT);
808
+ cell.simulate('keyDown', keyObjects.LEFT);
809
+ cell.simulate('keyDown', keyObjects.ESCAPE);
810
+
811
+ expect(`${parseInt(initial, 10) - 30}px`).to.equal(
812
+ this.dom.querySelectorAll('th')[0].style.width
813
+ );
814
+ });
815
+
816
+ it('Resize functionality should work with right key', function () {
817
+ const initial = this.dom.querySelectorAll('th')[0].style.width;
818
+
819
+ let cell = this.wrapper.find('td').first();
820
+ cell.simulate('focus');
821
+ expect(this.wrapper.find('td').first().prop('tabIndex')).to.equal('0');
822
+
823
+ cell.simulate('keyDown', keyObjects.UP);
824
+ cell = this.wrapper.find('th').at(0);
825
+ expect(this.wrapper.find('th').first().prop('tabIndex')).to.equal('0');
826
+
827
+ cell.simulate('keyDown', keyObjects.ENTER);
828
+ cell.simulate('keyDown', keyObjects.RIGHT);
829
+ cell.simulate('keyDown', keyObjects.RIGHT);
830
+ cell.simulate('keyDown', keyObjects.RIGHT);
831
+ cell.simulate('keyDown', keyObjects.RIGHT);
832
+ cell.simulate('keyDown', keyObjects.RIGHT);
833
+ cell.simulate('keyDown', keyObjects.RIGHT);
834
+ cell.simulate('keyDown', keyObjects.ESCAPE);
835
+
836
+ expect(`${parseInt(initial, 10) + 60}px`).to.equal(
837
+ this.dom.querySelectorAll('th')[0].style.width
838
+ );
839
+ });
840
+ });
841
+
842
+ describe('w/ Infinite Scrolling', function describeFunction2() {
843
+ afterEach(removeTable);
844
+
845
+ it('renders a spinner as expected', function () {
846
+ renderTable(
847
+ <DataTable {...defaultProps} fixedHeader fixedLayout hasMore>
848
+ {columns.map((columnProps) => (
849
+ <DataTableColumn {...columnProps} key={columnProps.property} />
850
+ ))}
851
+ </DataTable>
852
+ ).call(this);
853
+
854
+ expect(this.dom.querySelectorAll('.slds-spinner').length).to.eql(1);
855
+ });
856
+
857
+ it('onLoadMore callback is called when scroller is scrolled', function (done) {
858
+ let expectedCalbacks = 1;
859
+
860
+ this.onLoadMore = () => {
861
+ // eslint-disable-next-line no-plusplus
862
+ if (!--expectedCalbacks) done();
863
+ };
864
+
865
+ renderTable(
866
+ <DataTable
867
+ {...defaultProps}
868
+ fixedHeader
869
+ fixedLayout
870
+ hasMore
871
+ onLoadMore={this.onLoadMore}
872
+ >
873
+ {columns.map((columnProps) => (
874
+ <DataTableColumn {...columnProps} key={columnProps.property} />
875
+ ))}
876
+ </DataTable>
877
+ ).call(this);
878
+
879
+ const scroller = this.dom.querySelector(
880
+ '.slds-table_header-fixed_scroller'
881
+ );
882
+ scroller.dispatchEvent(new Event('scroll'));
883
+ });
884
+
885
+ it('onLoadMore callback is called when window is resized', function (done) {
886
+ let expectedCalbacks = 1;
887
+
888
+ this.onLoadMore = () => {
889
+ // eslint-disable-next-line no-plusplus
890
+ if (!--expectedCalbacks) done();
891
+ };
892
+
893
+ renderTable(
894
+ <DataTable
895
+ {...defaultProps}
896
+ fixedHeader
897
+ fixedLayout
898
+ hasMore
899
+ onLoadMore={this.onLoadMore}
900
+ >
901
+ {columns.map((columnProps) => (
902
+ <DataTableColumn {...columnProps} key={columnProps.property} />
903
+ ))}
904
+ </DataTable>
905
+ ).call(this);
906
+
907
+ window.dispatchEvent(new Event('resize'));
908
+ });
909
+
910
+ it('onLoadMore callback is called when the component is updated', function (done) {
911
+ let expectedCallbacks = 1;
912
+
913
+ this.onLoadMore = () => {
914
+ // eslint-disable-next-line no-plusplus
915
+ if (!--expectedCallbacks) done();
916
+ };
917
+
918
+ mountComponent(
919
+ <DataTable
920
+ {...defaultProps}
921
+ items={[]}
922
+ fixedHeader
923
+ fixedLayout
924
+ hasMore
925
+ onLoadMore={this.onLoadMore}
926
+ >
927
+ {columns.map((columnProps) => (
928
+ <DataTableColumn {...columnProps} key={columnProps.property} />
929
+ ))}
930
+ </DataTable>
931
+ ).call(this);
932
+
933
+ // Simulate the first page loading
934
+ this.wrapper.setProps({
935
+ items: [items[0]],
936
+ });
937
+ });
938
+ });
939
+
940
+ describe('Keyboard Navigation', function describeFunction2() {
941
+ beforeEach(
942
+ mountComponent(
943
+ <DataTable {...defaultProps} fixedLayout keyboardNavigation>
944
+ {[
945
+ ...columns.map((columnProps) => (
946
+ <DataTableColumn {...columnProps} key={columnProps.property} />
947
+ )),
948
+ ...[
949
+ <DataTableRowActions
950
+ key="actions"
951
+ options={[
952
+ {
953
+ id: 0,
954
+ label: 'Add to Group',
955
+ value: '1',
956
+ },
957
+ {
958
+ id: 1,
959
+ label: 'Publish',
960
+ value: '2',
961
+ },
962
+ ]}
963
+ onAction={() => {}}
964
+ dropdown={<Dropdown length="5" />}
965
+ />,
966
+ ],
967
+ ]}
968
+ </DataTable>
969
+ )
970
+ );
971
+
972
+ afterEach(unmountComponent);
973
+
974
+ it('moves selection when using keyboard up/down/left/right keys', function () {
975
+ // Focus the first cell
976
+ let cell = this.wrapper.find('td').first();
977
+ cell.simulate('focus');
978
+ expect(this.wrapper.find('td').first().prop('tabIndex')).to.equal('0');
979
+
980
+ // Press Right
981
+ cell.simulate('keyDown', keyObjects.RIGHT);
982
+ cell = this.wrapper.find('td').at(1);
983
+ expect(cell.prop('tabIndex')).to.equal('0');
984
+
985
+ // Press Down
986
+ cell.simulate('keyDown', keyObjects.DOWN);
987
+ cell = this.wrapper.find('td').at(5);
988
+ expect(cell.prop('tabIndex')).to.equal('0');
989
+
990
+ // Press Left
991
+ cell.simulate('keyDown', keyObjects.LEFT);
992
+ cell = this.wrapper.find('td').at(4);
993
+ expect(cell.prop('tabIndex')).to.equal('0');
994
+
995
+ // Press Up
996
+ cell.simulate('keyDown', keyObjects.UP);
997
+ cell = this.wrapper.find('td').at(0);
998
+ expect(cell.prop('tabIndex')).to.equal('0');
999
+ });
1000
+
1001
+ it('enters actionable mode when using keyboard enter key; and enters navigation mode when using keyboard escape key', function () {
1002
+ // Focus the first cell
1003
+ let cell = this.wrapper.find('td').first();
1004
+ cell.simulate('focus');
1005
+ expect(this.wrapper.find('td').first().prop('tabIndex')).to.equal('0');
1006
+
1007
+ // Press Enter
1008
+ cell.simulate('keyDown', keyObjects.ENTER);
1009
+
1010
+ cell = this.wrapper.find('td').first();
1011
+ expect(cell.prop('tabIndex')).to.be.undefined;
1012
+
1013
+ let checkbox = this.wrapper
1014
+ .find('td')
1015
+ .first()
1016
+ .find('input[type="checkbox"]');
1017
+ expect(checkbox.prop('tabIndex')).to.equal('0');
1018
+
1019
+ // Press Escape
1020
+ cell.simulate('keyDown', keyObjects.ESCAPE);
1021
+
1022
+ cell = this.wrapper.find('td').first();
1023
+ expect(cell.prop('tabIndex')).to.equal('0');
1024
+
1025
+ checkbox = this.wrapper.find('td').first().find('input[type="checkbox"]');
1026
+ expect(checkbox.prop('tabIndex')).to.equal('-1');
1027
+
1028
+ // Navigate to Dropdown
1029
+ cell.simulate('keyDown', keyObjects.RIGHT);
1030
+ cell.simulate('keyDown', keyObjects.RIGHT);
1031
+ cell.simulate('keyDown', keyObjects.RIGHT);
1032
+
1033
+ // Press Enter
1034
+ cell.simulate('keyDown', keyObjects.ENTER);
1035
+
1036
+ let dropdownTrigger = this.wrapper
1037
+ .find('td')
1038
+ .at(3)
1039
+ .find('.slds-dropdown-trigger button');
1040
+ expect(dropdownTrigger.prop('tabIndex')).to.equal('0');
1041
+
1042
+ // Press Escape
1043
+ cell.simulate('keyDown', keyObjects.ESCAPE);
1044
+ dropdownTrigger = this.wrapper
1045
+ .find('td')
1046
+ .at(3)
1047
+ .find('.slds-dropdown-trigger button');
1048
+ expect(dropdownTrigger.prop('tabIndex')).to.equal('-1');
1049
+ });
1050
+ });
1051
+ });