2019-09-06 09:44:31 +00:00
|
|
|
import React from 'react';
|
2020-02-02 11:01:43 +00:00
|
|
|
import { mount } from 'enzyme';
|
2019-09-06 09:44:31 +00:00
|
|
|
import Button from '.';
|
|
|
|
|
2019-11-26 11:01:00 +00:00
|
|
|
const baseProps = {
|
|
|
|
size: 'base',
|
|
|
|
isDisabled: false,
|
|
|
|
label: 'OK'
|
|
|
|
}
|
|
|
|
|
2019-09-06 09:44:31 +00:00
|
|
|
describe('<Button />', () => {
|
|
|
|
it('renders without error', () => {
|
|
|
|
const wrapper = mount(
|
2019-11-26 11:01:00 +00:00
|
|
|
<Button {...baseProps} />
|
2019-09-06 09:44:31 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper).toExist();
|
|
|
|
});
|
2019-09-17 11:19:45 +00:00
|
|
|
|
2020-02-02 11:01:43 +00:00
|
|
|
/* it('not re-render test', () => {
|
2019-11-26 11:01:00 +00:00
|
|
|
const onClick = () => alert('Button clicked');
|
2019-09-17 11:19:45 +00:00
|
|
|
|
2019-11-26 11:01:00 +00:00
|
|
|
const wrapper = shallow(<Button {...baseProps} onClick={onClick} />).instance();
|
2019-09-17 11:19:45 +00:00
|
|
|
|
|
|
|
const shouldUpdate = wrapper.shouldComponentUpdate(wrapper.props);
|
|
|
|
|
|
|
|
expect(shouldUpdate).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('re-render test by value', () => {
|
2019-11-26 11:01:00 +00:00
|
|
|
const onClick = () => alert('Button clicked');
|
2019-09-17 11:19:45 +00:00
|
|
|
|
2019-11-26 11:01:00 +00:00
|
|
|
const wrapper = shallow(<Button {...baseProps} onClick={onClick} />).instance();
|
2019-09-17 11:19:45 +00:00
|
|
|
|
|
|
|
const shouldUpdate = wrapper.shouldComponentUpdate({
|
|
|
|
...wrapper.props,
|
|
|
|
label: "Cancel"
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(shouldUpdate).toBe(true);
|
2020-02-02 11:01:43 +00:00
|
|
|
}); */
|
2019-11-26 11:01:00 +00:00
|
|
|
|
|
|
|
it('accepts id', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Button {...baseProps} id="testId" />
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.prop('id')).toEqual('testId');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('accepts className', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Button {...baseProps} className="test" />
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.prop('className')).toEqual('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('accepts style', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Button {...baseProps} style={{ color: 'red' }} />
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.getDOMNode().style).toHaveProperty('color', 'red');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render with isHovered prop', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Button {...baseProps} isHovered />
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.prop('isHovered')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render with isClicked prop', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Button {...baseProps} isClicked />
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.prop('isClicked')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render with isDisabled prop', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Button {...baseProps} isDisabled />
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.prop('isDisabled')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render with isLoading prop', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Button {...baseProps} isLoading />
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.prop('isLoading')).toEqual(true);
|
|
|
|
|
|
|
|
wrapper.setProps({primary: true});
|
|
|
|
expect(wrapper.prop('primary')).toEqual(true);
|
|
|
|
expect(wrapper.prop('isLoading')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render with various size', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Button {...baseProps} />
|
|
|
|
);
|
|
|
|
|
|
|
|
wrapper.setProps({size: 'medium'});
|
|
|
|
expect(wrapper.prop('size')).toEqual('medium');
|
|
|
|
|
|
|
|
wrapper.setProps({size: 'big'});
|
|
|
|
expect(wrapper.prop('size')).toEqual('big');
|
|
|
|
|
|
|
|
wrapper.setProps({size: 'medium', primary: true});
|
|
|
|
expect(wrapper.prop('size')).toEqual('medium');
|
|
|
|
expect(wrapper.prop('primary')).toEqual(true);
|
|
|
|
|
|
|
|
wrapper.setProps({size: 'big', primary: true});
|
|
|
|
expect(wrapper.prop('size')).toEqual('big');
|
|
|
|
expect(wrapper.prop('primary')).toEqual(true);
|
|
|
|
|
2020-07-15 16:14:00 +00:00
|
|
|
wrapper.setProps({size: 'large', primary: true});
|
|
|
|
expect(wrapper.prop('size')).toEqual('large');
|
|
|
|
expect(wrapper.prop('primary')).toEqual(true);
|
|
|
|
|
2019-11-26 11:01:00 +00:00
|
|
|
wrapper.setProps({scale: true});
|
|
|
|
expect(wrapper.prop('scale')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('render with icon', () => {
|
|
|
|
const icon = (<>1</>);
|
|
|
|
const wrapper = mount(
|
|
|
|
<Button {...baseProps} icon={icon} />
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.prop('icon')).toEqual(icon);
|
|
|
|
|
|
|
|
wrapper.setProps({size: 'big', primary: true});
|
|
|
|
expect(wrapper.prop('size')).toEqual('big');
|
|
|
|
expect(wrapper.prop('primary')).toEqual(true);
|
|
|
|
|
|
|
|
wrapper.setProps({size: 'medium', primary: true});
|
|
|
|
expect(wrapper.prop('size')).toEqual('medium');
|
|
|
|
expect(wrapper.prop('primary')).toEqual(true);
|
2020-07-15 16:14:00 +00:00
|
|
|
|
|
|
|
wrapper.setProps({size: 'large', primary: true});
|
|
|
|
expect(wrapper.prop('size')).toEqual('large');
|
|
|
|
expect(wrapper.prop('primary')).toEqual(true);
|
2019-11-26 11:01:00 +00:00
|
|
|
});
|
2019-09-06 09:44:31 +00:00
|
|
|
});
|