web: Components: Fixed main test and added re-render tests at ComboBox component.
This commit is contained in:
parent
f087bb22db
commit
b8765c09b4
@ -1,34 +1,93 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { mount, shallow } from 'enzyme';
|
||||
import ComboBox from '.';
|
||||
import DropDownItem from '../drop-down-item';
|
||||
|
||||
const baseOptions = [
|
||||
{
|
||||
key: 0,
|
||||
label: "Select"
|
||||
},
|
||||
{
|
||||
key: 1,
|
||||
label: "Select"
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
label: "Select"
|
||||
}
|
||||
];
|
||||
|
||||
const advancedOptions = (
|
||||
<>
|
||||
<DropDownItem>
|
||||
<span>Some text</span>
|
||||
</DropDownItem>
|
||||
</>
|
||||
);
|
||||
|
||||
const baseProps = {
|
||||
noBorder: false,
|
||||
isDisabled: false,
|
||||
selectedOption: {
|
||||
key: 0,
|
||||
label: "Select"
|
||||
},
|
||||
options: baseOptions,
|
||||
opened: false,
|
||||
onSelect: () => jest.fn(),
|
||||
size: 'base',
|
||||
scaled: true
|
||||
};
|
||||
|
||||
describe('<ComboBox />', () => {
|
||||
it('renders without error', () => {
|
||||
const advancedOptions = (
|
||||
<>
|
||||
<DropDownItem>
|
||||
<span>Some text</span>
|
||||
</DropDownItem>
|
||||
</>
|
||||
);
|
||||
|
||||
const wrapper = mount(
|
||||
<ComboBox
|
||||
options={[]} // An empty array will enable advancedOptions
|
||||
advancedOptions={advancedOptions}
|
||||
onSelect={option => console.log("Selected option", option)}
|
||||
selectedOption={{
|
||||
key: 0,
|
||||
label: "Select"
|
||||
}}
|
||||
isDisabled={false}
|
||||
scaled={false}
|
||||
size="content"
|
||||
directionX="right"
|
||||
/>
|
||||
<ComboBox {...baseProps} />
|
||||
);
|
||||
|
||||
expect(wrapper).toExist();
|
||||
});
|
||||
|
||||
it('render with advanced options', () => {
|
||||
const wrapper = mount(
|
||||
<ComboBox {...baseProps} options={[]} advancedOptions={advancedOptions} />
|
||||
);
|
||||
|
||||
expect(wrapper).toExist();
|
||||
});
|
||||
|
||||
it('disabled when isDisabled is passed', () => {
|
||||
const wrapper = mount(<ComboBox {...baseProps} isDisabled={true} />);
|
||||
|
||||
expect(wrapper.prop('isDisabled')).toEqual(true);
|
||||
});
|
||||
|
||||
it('not re-render test', () => {
|
||||
const wrapper = shallow(<ComboBox {...baseProps} />).instance();
|
||||
|
||||
const shouldUpdate = wrapper.shouldComponentUpdate(wrapper.props, wrapper.state);
|
||||
|
||||
expect(shouldUpdate).toBe(false);
|
||||
});
|
||||
|
||||
it('re-render test', () => {
|
||||
const wrapper = shallow(<ComboBox {...baseProps} />).instance();
|
||||
|
||||
const shouldUpdate = wrapper.shouldComponentUpdate({
|
||||
noBorder: true,
|
||||
isDisabled: false,
|
||||
selectedOption: {
|
||||
key: 0,
|
||||
label: "Select"
|
||||
},
|
||||
options: baseOptions,
|
||||
opened: false,
|
||||
onSelect: () => jest.fn(),
|
||||
size: 'base',
|
||||
scaled: true
|
||||
}, wrapper.state);
|
||||
|
||||
expect(shouldUpdate).toBe(true);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user