-
Notifications
You must be signed in to change notification settings - Fork 932
/
Copy pathMUIDataTableBodyCell.test.js
74 lines (67 loc) · 2.11 KB
/
MUIDataTableBodyCell.test.js
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
import React from 'react';
import { spy, stub } from 'sinon';
import { mount, shallow } from 'enzyme';
import { assert, expect, should } from 'chai';
import MUIDataTable from '../src/MUIDataTable';
import TableBodyCell from '../src/components/TableBodyCell';
describe('<TableBodyCell />', function() {
let data;
let columns;
before(() => {
columns = [
{
name: 'Name',
},
'Company',
{ name: 'City', label: 'City Label', options: { filterType: 'textField' } },
{
name: 'State',
options: { filterType: 'multiselect' },
},
{ name: 'Empty', options: { empty: true, filterType: 'checkbox' } },
];
data = [
['Joe James', 'Test Corp', 'Yonkers', 'NY'],
['John Walsh', 'Test Corp', 'Hartford', null],
['Bob Herm', 'Test Corp X', 'Tampa', 'FL'],
['James Houston', 'Test Corp', 'Dallas', 'TX'],
];
});
it('should execute "onCellClick" prop when clicked if provided', () => {
var clickCount = 0;
var colIndex, rowIndex, colData;
const options = {
onCellClick: (val, colMeta) => {
clickCount++;
colIndex = colMeta.colIndex;
rowIndex = colMeta.rowIndex;
colData = val;
},
};
const fullWrapper = mount(<MUIDataTable columns={columns} data={data} options={options} />);
fullWrapper
.find('[data-testid="MuiDataTableBodyCell-0-0"]')
.at(0)
.simulate('click');
assert.strictEqual(clickCount, 1);
assert.strictEqual(colIndex, 0);
assert.strictEqual(rowIndex, 0);
assert.strictEqual(colData, 'Joe James');
fullWrapper
.find('[data-testid="MuiDataTableBodyCell-2-3"]')
.at(0)
.simulate('click');
assert.strictEqual(clickCount, 2);
assert.strictEqual(colIndex, 2);
assert.strictEqual(rowIndex, 3);
assert.strictEqual(colData, 'Dallas');
fullWrapper
.find('[data-testid="MuiDataTableBodyCell-1-2"]')
.at(0)
.simulate('click');
assert.strictEqual(clickCount, 3);
assert.strictEqual(colIndex, 1);
assert.strictEqual(rowIndex, 2);
assert.strictEqual(colData, 'Test Corp X');
});
});