Skip to content

Commit

Permalink
fix: Added tests for focus
Browse files Browse the repository at this point in the history
  • Loading branch information
miruskin committed May 21, 2020
1 parent 9ac7b10 commit 820ef39
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/index.keyboardNav.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ test('can collapse on keyboardNavigation', t => {
t.false(wrapper.find('#c3').exists())
})

test('should set focus to first match on search', t => {
const wrapper = mount(<DropdownTreeSelect data={tree} showDropdown="always" />)
wrapper.instance().onInputChange('bb')
triggerOnKeyboardKeyDown(wrapper, ['b'])
t.deepEqual(wrapper.find('li.focused').text(), 'bbb 1')
})

test('remembers current focus on search clear', t => {
const wrapper = mount(<DropdownTreeSelect data={tree} />)
wrapper.instance().onInputChange('bb')
triggerOnKeyboardKeyDown(wrapper, ['b'])
t.deepEqual(wrapper.find('li.focused').text(), 'bbb 1')
triggerOnKeyboardKeyDown(wrapper, ['Backspace', 'Backspace', 'Backspace'])
t.deepEqual(wrapper.find('li.focused').text(), 'bbb 1')
})

test('should set focus on subsequent searches', t => {
const wrapper = mount(<DropdownTreeSelect data={tree} />)
wrapper.instance().onInputChange('bb')
triggerOnKeyboardKeyDown(wrapper, ['b'])
t.deepEqual(wrapper.find('li.focused').text(), 'bbb 1')
wrapper.instance().onInputChange('aa')
triggerOnKeyboardKeyDown(wrapper, ['a'])
t.deepEqual(wrapper.find('li.focused').text(), 'aaa 1')
})

test('can navigate searchresult on keyboardNavigation', t => {
const wrapper = mount(<DropdownTreeSelect data={tree} showDropdown="initial" />)
wrapper.instance().onInputChange('bb')
Expand Down

0 comments on commit 820ef39

Please sign in to comment.