From d8511f988489b3fe06abd8c3302ad02b55865020 Mon Sep 17 00:00:00 2001 From: leMaik Date: Sun, 3 Dec 2017 19:25:12 +0100 Subject: [PATCH] Add another chip focus test. --- src/ChipInput.spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ChipInput.spec.js b/src/ChipInput.spec.js index 4919512..12582fe 100644 --- a/src/ChipInput.spec.js +++ b/src/ChipInput.spec.js @@ -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( + + ) + 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(