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

Commit

Permalink
Add duplicate and invalid chip tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed Dec 3, 2017
1 parent df48516 commit 7598bc4
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/ChipInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,39 @@ describe('uncontrolled mode', () => {
tree.find('Cancel').first().simulate('click')
expect(handleChange).toBeCalledWith(['bar'])
})

it('does not add empty chips', () => {
const handleChange = jest.fn()
const tree = mount(
<ChipInput onChange={handleChange} />
)

tree.find('input').getDOMNode().value = ' '
tree.find('input').simulate('keyDown', { keyCode: 13 }) // press enter
expect(handleChange).not.toBeCalled()
})

it('does not add duplicate chips by default', () => {
const handleChange = jest.fn()
const tree = mount(
<ChipInput defaultValue={['a']} onChange={handleChange} />
)

tree.find('input').getDOMNode().value = 'a'
tree.find('input').simulate('keyDown', { keyCode: 13 }) // press enter
expect(handleChange).not.toBeCalled()
})

it('does add duplicate chips if allowDuplicates is set to true', () => {
const handleChange = jest.fn()
const tree = mount(
<ChipInput defaultValue={['a']} onChange={handleChange} allowDuplicates />
)

tree.find('input').getDOMNode().value = 'a'
tree.find('input').simulate('keyDown', { keyCode: 13 }) // press enter
expect(handleChange).toBeCalledWith(['a', 'a'])
})
})

describe('chip focusing', () => {
Expand Down Expand Up @@ -148,7 +181,7 @@ describe('chip focusing', () => {
tree.find('input').simulate('keyDown', { keyCode: 39 }) // arrow right
expect(getFocusedChip(tree).text()).toBe('c')

// onfocus all chips if the right arrow key is pressed when focusing the last chip
// unfocus all chips if the right arrow key is pressed when focusing the last chip
tree.find('input').simulate('keyDown', { keyCode: 39 }) // arrow right
expect(getFocusedChip(tree).length).toBe(0)
})
Expand Down Expand Up @@ -234,3 +267,12 @@ describe('floating label', () => {
expect(tree.find('InputLabel').prop('shrink')).toBe(true)
})
})

describe('helper text', () => {
it('is displayed', () => {
const tree = mount(
<ChipInput helperText='Helper text' />
)
expect(tree.find('FormHelperText').text()).toBe('Helper text')
})
})

0 comments on commit 7598bc4

Please sign in to comment.