This commit is contained in:
Nikita Gopienko 2019-11-01 09:36:42 +03:00
commit a69b9a19bc
2 changed files with 108 additions and 16 deletions

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);
});
});

View File

@ -35,12 +35,24 @@ describe('<DropDown />', () => {
expect(wrapper.prop('directionX')).toEqual('right');
});
it('directionX right manualX', () => {
const wrapper = mount(<DropDown {...baseProps} directionX='right' manualX='100px' />);
expect(wrapper.prop('directionX')).toEqual('right');
});
it('directionY top', () => {
const wrapper = mount(<DropDown {...baseProps} directionY='top' />);
expect(wrapper.prop('directionY')).toEqual('top');
});
it('directionY top manualY', () => {
const wrapper = mount(<DropDown {...baseProps} directionY='top' manualY='100%' />);
expect(wrapper.prop('directionY')).toEqual('top');
});
it('withArrow', () => {
const wrapper = mount(<DropDown {...baseProps} withArrow />);
@ -74,15 +86,37 @@ describe('<DropDown />', () => {
expect(wrapper.children()).toHaveLength(1);
});
/*
it('with maxHeight and children', () => {
const wrapper = mount((
<DropDown {...baseProps} maxHeight={200}>
<div>1</div>
</DropDown>
));
expect(wrapper.children()).toHaveLength(1);
it('with maxHeight and children', () => {
const child = (<div>1</div>);
const wrapper = shallow((
<DropDown
maxHeight={0}>
{child}
</DropDown>
)).instance();
expect(wrapper.props.children).toEqual(child);
});
*/
it('componentDidUpdate() state lifecycle test', () => {
const wrapper = shallow(<DropDown {...baseProps} />);
const instance = wrapper.instance();
wrapper.setState({ isOpen: true });
instance.componentDidUpdate(wrapper.props(), wrapper.state());
expect(wrapper.state()).toBe(wrapper.state());
});
it('componentDidUpdate() props lifecycle test', () => {
const wrapper = shallow(<DropDown {...baseProps} />);
const instance = wrapper.instance();
instance.componentDidUpdate({ opened: true }, wrapper.state());
expect(wrapper.props()).toBe(wrapper.props());
});
});