Skip to content
Snippets Groups Projects
Unverified Commit 25d6ba4b authored by Kyle Doherty's avatar Kyle Doherty
Browse files

add enter commit + tests for methods

parent 705ce2c1
Branches
Tags
No related merge requests found
......@@ -14,6 +14,7 @@ import MetabaseAnalytics from "metabase/lib/analytics";
import {
KEYCODE_ESCAPE,
KEYCODE_ENTER,
KEYCODE_COMMA,
KEYCODE_TAB,
KEYCODE_UP,
......@@ -107,7 +108,7 @@ export default class RecipientPicker extends Component {
const { filteredUsers, selectedUserID } = this.state
// enter, tab, comma
if (keyCode === KEYCODE_ESCAPE || keyCode === KEYCODE_TAB || keyCode === KEYCODE_COMMA) {
if (keyCode === KEYCODE_ESCAPE || keyCode === KEYCODE_TAB || keyCode === KEYCODE_COMMA || keyCode === KEYCODE_ENTER) {
this.addCurrentRecipient();
}
......@@ -168,6 +169,7 @@ export default class RecipientPicker extends Component {
addRecipient = (recipient) => {
const { recipients } = this.props
// recipient is a user object, or plain object containing "email" key
this.props.onRecipientsChange(
// return the list of recipients with the new user added
......
......@@ -4,6 +4,8 @@ import { shallow } from 'enzyme'
import {
KEYCODE_DOWN,
KEYCODE_TAB,
KEYCODE_ENTER,
KEYCODE_COMMA
} from "metabase/lib/keyboard"
import Input from "metabase/components/Input"
......@@ -108,42 +110,47 @@ describe('recipient picker', () => {
expect(spy).toHaveBeenCalled()
})
it('should allow the user to use arrow keys to select a recipient', () => {
const spy = jest.fn()
describe('key selection', () => {
[KEYCODE_TAB, KEYCODE_ENTER, KEYCODE_COMMA].map(key =>
it(`should allow the user to use arrow keys and then ${key} to select a recipient`, () => {
const spy = jest.fn()
const wrapper = shallow(
<RecipientPicker
recipients={[]}
users={TEST_USERS}
isNewPulse={true}
onRecipientsChange={spy}
/>
)
const wrapper = shallow(
<RecipientPicker
recipients={[]}
users={TEST_USERS}
isNewPulse={true}
onRecipientsChange={spy}
/>
)
const input = wrapper.find(Input)
const input = wrapper.find(Input)
// limit our options to user by typing
input.simulate('change', { target: { value: 'w' }})
// limit our options to user by typing
input.simulate('change', { target: { value: 'w' }})
// the initially selected user should be the first user
expect(wrapper.state().selectedUserID).toBe(TEST_USERS[0].id)
// the initially selected user should be the first user
expect(wrapper.state().selectedUserID).toBe(TEST_USERS[0].id)
input.simulate('keyDown', {
keyCode: KEYCODE_DOWN,
preventDefault: jest.fn()
})
input.simulate('keyDown', {
keyCode: KEYCODE_DOWN,
preventDefault: jest.fn()
})
// the next possible user should be selected now
expect(wrapper.state().selectedUserID).toBe(TEST_USERS[1].id)
// the next possible user should be selected now
expect(wrapper.state().selectedUserID).toBe(TEST_USERS[1].id)
input.simulate('keydown', {
keyCode: KEYCODE_TAB,
preventDefalut: jest.fn()
})
input.simulate('keydown', {
keyCode: key,
preventDefalut: jest.fn()
})
expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveBeenCalledWith([TEST_USERS[1]])
expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveBeenCalledWith([TEST_USERS[1]])
})
)
})
describe('usage', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment