| import IconButton from '@mui/material/IconButton'; |
| import DownloadIcon from '@mui/icons-material/CloudDownload'; |
| import FilterIcon from '@mui/icons-material/FilterList'; |
| import PrintIcon from '@mui/icons-material/Print'; |
| import SearchIcon from '@mui/icons-material/Search'; |
| import ViewColumnIcon from '@mui/icons-material/ViewColumn'; |
| import Chip from '@mui/material/Chip'; |
| import { assert } from 'chai'; |
| import { mount } from 'enzyme'; |
| import React from 'react'; |
| import TableToolbar from '../src/components/TableToolbar'; |
| import getTextLabels from '../src/textLabels'; |
|
|
| const CustomChip = props => { |
| return <Chip variant="outlined" color="secondary" label={props.label} />; |
| }; |
|
|
| const icons = { |
| SearchIcon, |
| DownloadIcon, |
| PrintIcon, |
| ViewColumnIcon, |
| FilterIcon, |
| }; |
| let setTableAction = () => {}; |
| const options = { |
| print: true, |
| download: true, |
| search: true, |
| filter: true, |
| viewColumns: true, |
| textLabels: getTextLabels(), |
| downloadOptions: { |
| separator: ',', |
| filename: 'tableDownload.csv', |
| filterOptions: { |
| useDisplayedRowsOnly: true, |
| useDisplayedColumnsOnly: true, |
| }, |
| }, |
| }; |
| const columns = ['First Name', 'Company', 'City', 'State']; |
| const data = [ |
| { |
| data: ['Joe James', 'Test Corp', 'Yonkers', 'NY'], |
| dataIndex: 0, |
| }, |
| { |
| data: ['John Walsh', 'Test Corp', 'Hartford', 'CT'], |
| dataIndex: 1, |
| }, |
| { |
| data: ['Bob Herm', 'Test Corp', 'Tampa', 'FL'], |
| dataIndex: 2, |
| }, |
| { |
| data: ['James Houston', 'Test Corp', 'Dallas', 'TX'], |
| dataIndex: 3, |
| }, |
| ]; |
|
|
| const testCustomIcon = iconName => { |
| const components = { icons: { [iconName]: CustomChip } }; |
| const wrapper = mount(<TableToolbar {...{ columns, data, options, setTableAction, components }} />); |
| assert.strictEqual(wrapper.find(IconButton).length, 5); |
| assert.strictEqual(wrapper.find(CustomChip).length, 1); |
| Object.keys(icons).forEach(icon => { |
| |
| assert.strictEqual(wrapper.find(icons[icon]).length, iconName === icon ? 0 : 1); |
| }); |
| }; |
|
|
| describe('<TableToolbar /> with custom icons', function() { |
| it('should render a toolbar with a custom chip in place of the search icon', () => { |
| testCustomIcon('SearchIcon'); |
| }); |
|
|
| it('should render a toolbar with a custom chip in place of the download icon', () => { |
| testCustomIcon('DownloadIcon'); |
| }); |
|
|
| it('should render a toolbar with a custom chip in place of the print icon', () => { |
| testCustomIcon('PrintIcon'); |
| }); |
|
|
| it('should render a toolbar with a custom chip in place of the view columns icon', () => { |
| testCustomIcon('ViewColumnIcon'); |
| }); |
|
|
| it('should render a toolbar with a custom chip in place of the filter icon', () => { |
| testCustomIcon('FilterIcon'); |
| }); |
| }); |
|
|