Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Commit

Permalink
Add another chip focus test.
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed Dec 3, 2017
1 parent a8978b5 commit d8511f9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/ChipInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ describe('chip focusing', () => {
expect(getFocusedChip(tree).text()).toBe('c')
})

it('focuses the last chip when pressing the left arrow key if the input is empty', () => {
const tree = mount(
<ChipInput defaultValue={['a', 'b', 'c']} />
)
tree.find('input').simulate('keyDown', { keyCode: 37 }) // arrow left
expect(getFocusedChip(tree).text()).toBe('c')

// don't focus the chip if the input is not empty
tree.find('input').getDOMNode().value = 'd'
tree.find('input').simulate('keyDown')
expect(getFocusedChip(tree).length).toBe(0)
tree.find('input').simulate('keyDown', { keyCode: 37, target: { value: 'd' } }) // arrow left
expect(getFocusedChip(tree).length).toBe(0)
})

it('unfocuses the focused chip while adding a new chip', () => {
const tree = mount(
<ChipInput defaultValue={['foo', 'bar']} />
Expand Down

0 comments on commit d8511f9

Please sign in to comment.