-
Notifications
You must be signed in to change notification settings - Fork 933
/
Copy pathMUIDataTableCustomComponents.test.js
58 lines (53 loc) · 1.6 KB
/
MUIDataTableCustomComponents.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
import React from 'react';
import { mount, shallow } from 'enzyme';
import { assert } from 'chai';
import MUIDataTable from '../src/MUIDataTable';
import Chip from '@mui/material/Chip';
import TableFilterList from '../src/components/TableFilterList';
const CustomChip = props => {
return <Chip variant="outlined" color="secondary" label={props.label} />;
};
const CustomFilterList = props => {
return <TableFilterList {...props} ItemComponent={CustomChip} />;
};
describe('<MUIDataTable /> with custom components', function() {
let data;
let columns;
before(() => {
columns = [
{ name: 'Name' },
{
name: 'Company',
options: {
filter: true,
filterType: 'custom',
filterList: ['Test Corp'],
},
},
{ name: 'City', label: 'City Label' },
{ name: 'State' },
{ name: 'Empty', options: { empty: true, filterType: 'checkbox' } },
];
data = [
['Joe James', 'Test Corp', 'Yonkers', 'NY'],
['John Walsh', 'Test Corp', 'Hartford', null],
['Bob Herm', 'Test Corp', 'Tampa', 'FL'],
['James Houston', 'Test Corp', 'Dallas', 'TX'],
];
});
it('should render a table with custom Chip in TableFilterList', () => {
const wrapper = mount(
<MUIDataTable
columns={columns}
data={data}
components={{
TableFilterList: CustomFilterList,
}}
/>,
);
const customFilterList = wrapper.find(CustomFilterList);
assert.lengthOf(customFilterList, 1);
const customChip = customFilterList.find(CustomChip);
assert.lengthOf(customChip, 1);
});
});