Skip to content

Commit

Permalink
test(select): add select test
Browse files Browse the repository at this point in the history
  • Loading branch information
shiliqian committed Mar 12, 2021
1 parent 79c7f80 commit 9bb389b
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/components/select/__tests__/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const optionsWithOutGroup = values.map((value, index) => ({
label: labels[index],
}));

const expecialGroupOptions = values.map((value, index) => ({
value,
label: labels[index],
groupValue: undefined,
groupLabel: undefined,
}));

describe('<Select /> Single Multiple options or groupOptions ', () => {
it('renders <Select /> components', () => {
const tree = renderer.create(<Select defaultValue="all" options={options} />).toJSON();
Expand All @@ -47,7 +54,6 @@ describe('<Select /> Single Multiple options or groupOptions ', () => {
.toJSON();
expect(tree).toMatchSnapshot();
});

it('renders <Select.Option /> components', () => {
const tree = renderer
.create(
Expand Down Expand Up @@ -132,6 +138,13 @@ describe('<Select /> Single Multiple options or groupOptions ', () => {
expect(document.querySelector('.gio-select-dropdown').querySelectorAll('.gio-select-list-option')).toHaveLength(1);
tree.unmount();
});
it('renders <Select /> expecialGroup components', () => {
const tree = mount(<Select options={expecialGroupOptions} />);
tree.simulate('click');
expect(document.querySelector('.gio-select-dropdown')).not.toBeNull();
expect(document.querySelector('.gio-select-list-group')).not.toBeNull();
tree.unmount();
});
});

describe('<Select /> allowClear onClear onAllowClear', () => {
Expand Down Expand Up @@ -310,6 +323,21 @@ describe('<Select allowCustomOptions multiple/> keyDown', () => {
tree.unmount();
});
});
it('keyDown mouseEnter', () => {
const tree = mount(<Select multiple searchable="default" mode="tags" options={optionsWithOutGroup} />);
act(() => {
tree.simulate('click');
});
act(() => {
tree.find('input').simulate('change', { target: { value: '全部' } });
});
tree.mount().find('.gio-select-list-option').simulate('mouseenter');
tree.mount().find('.gio-select-list').simulate('keyDown', { keyCode: 13, key: 'Enter' });
expect(tree.render().find('.gio-select-values-wrapper').children('.gio-tag')).toHaveLength(1);
act(() => {
tree.unmount();
});
});
it('keyDown', async () => {
const tree = mount(<Select multiple mode="tags" options={optionsWithOutGroup} />);
act(() => {
Expand Down Expand Up @@ -420,8 +448,6 @@ describe('<Select allowCustomOptions multiple/> keyDown', () => {
tree.mount().find('.gio-select-list').simulate('keyDown', { keyCode: 38, key: 'ArrowUp' });
tree.mount().find('.gio-select-list').simulate('keyDown', { keyCode: 38, key: 'ArrowUp' });
tree.mount().find('.gio-select-list').simulate('keyDown', { keyCode: 13, key: 'Enter' });
// tree.mount().find('.gio-select-list').simulate('mouseLeave');
// tree.mount().find('.gio-select-list-option-container').simulate('mouseEnter');
expect(tree.render().find('.gio-select-values-wrapper').children('.gio-tag')).toHaveLength(1);
tree.unmount();
});
Expand Down

0 comments on commit 9bb389b

Please sign in to comment.