import React from 'react'; import { spy, stub } from 'sinon'; import { mount, shallow } from 'enzyme'; import { assert } from 'chai'; import getTextLabels from '../src/textLabels'; import TableHeadCell from '../src/components/TableHeadCell'; import TableCell from '@mui/material/TableCell'; import TableSortLabel from '@mui/material/TableSortLabel'; import HelpIcon from '@mui/icons-material/Help'; import { DndProvider } from 'react-dnd'; import { HTML5Backend } from 'react-dnd-html5-backend'; describe('', function() { let classes; before(() => { classes = { root: {}, }; }); it('should add custom props to header cell if "setCellHeaderProps" provided', () => { const options = { sort: true, textLabels: getTextLabels() }; const toggleSort = () => {}; const setCellHeaderProps = { myProp: 'test', className: 'testClass' }; const selectRowUpdate = stub(); const toggleExpandRow = () => {}; const mountWrapper = mount( some content , ); const props = mountWrapper.find(TableCell).props(); const classNames = props.className.split(' '); const finalClass = classNames[classNames.length - 1]; assert.strictEqual(props.myProp, 'test'); assert.strictEqual(finalClass, 'testClass'); }); it('should render a table head cell with sort label when options.sort = true provided', () => { const options = { sort: true, textLabels: getTextLabels() }; const toggleSort = () => {}; const wrapper = mount( some content , ); const actualResult = wrapper.find(TableSortLabel); assert.strictEqual(actualResult.length, 1); }); it('should render a table head cell without sort label when options.sort = false provided', () => { const options = { sort: false, textLabels: getTextLabels() }; const toggleSort = () => {}; const shallowWrapper = shallow( some content , ); const actualResult = shallowWrapper.find(TableSortLabel); assert.strictEqual(actualResult.length, 0); }); it('should render a table help icon when hint provided', () => { const options = { sort: true, textLabels: getTextLabels() }; const wrapper = mount( some content , ); const actualResult = wrapper.find(HelpIcon); assert.strictEqual(actualResult.length, 1); }); it('should render a table head cell without custom tooltip when hint provided', () => { const options = { sort: true, textLabels: getTextLabels() }; const shallowWrapper = shallow( some content , ).dive(); const actualResult = shallowWrapper.find(HelpIcon); assert.strictEqual(actualResult.length, 0); }); it('should trigger toggleSort prop callback when calling method handleSortClick', () => { const options = { sort: true, textLabels: getTextLabels() }; const toggleSort = spy(); const wrapper = mount( some content , ); const instance = wrapper .find('td') .at(0) .childAt(0); const event = { target: { value: 'All' } }; instance.simulate('click'); assert.strictEqual(toggleSort.callCount, 1); }); });