web: Components: Added tests at DropDownItem component

This commit is contained in:
Ilya Oleshko 2019-11-01 09:21:59 +03:00
parent d358ac5fa6
commit 2caab45513

View File

@ -1,18 +1,76 @@
import React from 'react';
import { mount } from 'enzyme';
import { mount, shallow } from 'enzyme';
import DropDownItem from '.';
const baseProps = {
isSeparator: false,
isHeader: false,
tabIndex: -1,
label: 'test',
disabled: false,
icon: 'NavLogoIcon',
noHover: false,
onClick: jest.fn()
}
describe('<DropDownItem />', () => {
it('renders without error', () => {
const wrapper = mount(
<DropDownItem
isSeparator={false}
isHeader={false}
label='Button 1'
icon='NavLogoIcon'
onClick={() => console.log('Button 1 clicked')} />
<DropDownItem {...baseProps} />
);
expect(wrapper).toExist();
});
it('check disabled props', () => {
const wrapper = mount(
<DropDownItem {...baseProps} disabled={true} />
);
expect(wrapper.prop('disabled')).toEqual(true);
});
it('check isSeparator props', () => {
const wrapper = mount(
<DropDownItem {...baseProps} isSeparator={true} />
);
expect(wrapper.prop('isSeparator')).toEqual(true);
});
it('check isHeader props', () => {
const wrapper = mount(
<DropDownItem {...baseProps} isHeader={true} />
);
expect(wrapper.prop('isHeader')).toEqual(true);
});
it('check noHover props', () => {
const wrapper = mount(
<DropDownItem {...baseProps} noHover={true} />
);
expect(wrapper.prop('noHover')).toEqual(true);
});
it('causes function onClick()', () => {
const onClick = jest.fn();
const wrapper = shallow(<DropDownItem id='test' {...baseProps} onClick={onClick} />);
wrapper.find("#test").simulate("click")
expect(onClick).toHaveBeenCalled();
});
it('render without child', () => {
const wrapper = shallow(
<DropDownItem >
test
</DropDownItem>
);
expect(wrapper.props.children).toEqual(undefined);
});
});