+
@@ -718,6 +738,7 @@ SelectField.propTypes = {
autocompleteFilter: PropTypes.func,
selectionsRenderer: PropTypes.func,
menuCloseButton: PropTypes.node,
+ menuCancelButton: PropTypes.node,
canAutoPosition: PropTypes.bool,
multiple: PropTypes.bool,
openImmediately: PropTypes.bool,
@@ -725,7 +746,9 @@ SelectField.propTypes = {
disabled: PropTypes.bool,
onChange: PropTypes.func,
onMenuOpen: PropTypes.func,
- onAutoCompleteTyping: PropTypes.func
+ onAutoCompleteTyping: PropTypes.func,
+ onRequestClose: PropTypes.func,
+ useLayerForClickAway: PropTypes.bool
}
SelectField.defaultProps = {
@@ -734,6 +757,7 @@ SelectField.defaultProps = {
checkedIcon:
,
unCheckedIcon:
,
menuCloseButton: null,
+ menuCancelButton: null,
canAutoPosition: true,
multiple: false,
openImmediately: false,
@@ -755,7 +779,9 @@ SelectField.defaultProps = {
onChange: () => {},
onMenuOpen: () => {},
onAutoCompleteTyping: () => {},
- children: []
+ children: [],
+ onRequestClose: () => {},
+ useLayerForClickAway: false
}
export default SelectField
diff --git a/src/SuperSelectField.test.js b/src/SuperSelectField.test.js
index 2dfe8c2..3fd22ea 100644
--- a/src/SuperSelectField.test.js
+++ b/src/SuperSelectField.test.js
@@ -6,22 +6,21 @@
/* eslint-env jest */
import React from 'react'
import { render } from 'react-dom'
-import { shallow } from 'enzyme'
+
+import { shallow, configure } from 'enzyme'
+import Adapter from 'enzyme-adapter-react-16'
import getMuiTheme from 'material-ui/styles/getMuiTheme'
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
+
import SuperSelectField from './SuperSelectField'
+configure({ adapter: new Adapter() })
const muiTheme = getMuiTheme()
const shallowWithContext = node => shallow(node, {context: {muiTheme}})
-/*
-const mountWithContext = node => mount(node, {
- context: {muiTheme},
- childContextTypes: {muiTheme: PropTypes.object}
-})
-*/
+
const testChildren = [
-
Test Child
,
+
Test Child
,
Test Child
]
@@ -44,15 +43,15 @@ describe('Default states, styles, and behaviors', () => {
})
it('expects the menu to open when clicked', () => {
- const wrapper = shallowWithContext(
)
+ const wrapper = shallowWithContext(
{testChildren})
wrapper.simulate('click')
expect(wrapper.find('Popover').props().open).toBe(true)
})
it('expects the menu to render children', () => {
const wrapper = shallowWithContext(
{testChildren})
- wrapper.simulate('click') // opens menu
- const firstChild = wrapper.find('MenuItem').first()
+ wrapper.simulate('click', { event: {} })
+ const firstChild = wrapper.find('ListItem').first()
expect(firstChild.props().primaryText).toBe(testChildren[0])
})
@@ -64,25 +63,38 @@ describe('Default states, styles, and behaviors', () => {
describe('When selecting an option', () => {
it('expects the menu to close', () => {
const wrapper = shallowWithContext(
{testChildren})
+ expect(wrapper.find('Popover').props().open).toBe(false)
+
wrapper.simulate('click') // opens menu
- const children = wrapper.find('MenuItem')
+ expect(wrapper.find('Popover').props().open).toBe(true)
+ const children = wrapper.find('ListItem')
expect(children).toHaveLength(2)
- children.first().simulate('touchTap')
- console.log('children', children)
- // expect(wrapper.find('Popover').props().open).toBe(false)
+ wrapper.find('ListItem').first().simulate('click', { preventDefault: () => {} })
+ expect(wrapper.find('Popover').props().open).toBe(false)
})
it('expects the menu to close when clicking outside')
-/* it('expects the onChange handler to be called', () => {
+ it('expects the onChange handler to be called', () => {
const callback = jest.fn()
const wrapper = shallowWithContext(
{testChildren})
wrapper.setState({ isOpen: true })
expect(callback).not.toHaveBeenCalled()
- wrapper.find('MenuItem').first().simulate('touchTap')
- expect(callback).toHaveBeenCalledTimes(1)
- // expect(callback).toHaveBeenCalledWith(arg1, arg2, ...)
- }) */
+ wrapper.find('ListItem').first().simulate('click', { target: {}, preventDefault: () => {} })
+ wrapper.first().simulate('keyDown', { key: 'Escape' })
+ expect(callback).toBeCalledWith({'label': 'test', 'value': '1'}, undefined)
+ })
+
+ it('expects the onChange handler to not be called', () => {
+ const callback = jest.fn()
+ const onRequestClose = jest.fn()
+ const wrapper = shallowWithContext(
{testChildren})
+ wrapper.setState({ isOpen: true })
+ expect(callback).not.toHaveBeenCalled()
+ wrapper.find('ListItem').first().simulate('click', { target: {}, preventDefault: () => {} })
+ wrapper.first().simulate('keyDown', { key: 'Escape' })
+ expect(callback).not.toHaveBeenCalled()
+ })
})
describe('Children composition', () => {