Skip to content

Commit

Permalink
better test
Browse files Browse the repository at this point in the history
  • Loading branch information
jscottsmith committed Nov 6, 2018
1 parent b4533ce commit 7b4a0ed
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions _tests/molecules/SearchSelectOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,14 @@ describe('Expect <SearchSelectOptions>', () => {

it('to handle focus with arrow keys', () => {
const wrapper = mount(<SearchSelectOptions options={options} {...defaultProps} />);
wrapper
.find('button[name="option0"]')
.simulate('keydown', { keyCode: charCodes.ARROW_DOWN, preventDefault: () => {} });
expect(wrapper.state().focusedIndex).toBe(1);
wrapper
.find('button[name="option1"]')
.simulate('keydown', { keyCode: charCodes.ARROW_UP, preventDefault: () => {} });
expect(wrapper.state().focusedIndex).toBe(0);
wrapper
.find('button[name="option0"]')
.simulate('keydown', { keyCode: charCodes.ARROW_LEFT, preventDefault: () => {} });
expect(wrapper.state().focusedIndex).toBe(11);
wrapper
.find('button[name="option11"]')
.simulate('keydown', { keyCode: charCodes.ARROW_RIGHT, preventDefault: () => {} });
expect(wrapper.state().focusedIndex).toBe(0);
[
['[name="option0"]', charCodes.ARROW_DOWN, 1],
['[name="option1"]', charCodes.ARROW_UP, 0],
['[name="option0"]', charCodes.ARROW_LEFT, 11],
['[name="option11"]', charCodes.ARROW_RIGHT, 0]
].forEach(([name, code, expected]) => {
wrapper.find(name).simulate('keydown', { keyCode: code, preventDefault: () => {} });
expect(wrapper.state().focusedIndex).toBe(expected);
});
});
});

0 comments on commit 7b4a0ed

Please sign in to comment.