diff --git a/.babelrc b/.babelrc index 8fb47a89c2..e34a89d36d 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,6 @@ { "ignore": ["node-modules/**", "src/index.umd.js"], - "presets": [ "es2015", "stage-0", "react"], + "presets": [ "env", "stage-0", "react"], "env": { "test": { "plugins": ["istanbul"], diff --git a/README.md b/README.md index a022326a9a..e645a74891 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,13 @@ class App extends React.Component { console.log(`Selected: ${selectedOption.label}`); } render() { + const { selectedOption } = this.state; + const value = selectedOption && selectedOption.value; + return ( { this.select = ref; }} + onBlurResetsInput={false} + onSelectResetsInput={false} autoFocus options={options} simpleValue @@ -68,6 +73,8 @@ var StatesField = createClass({ searchable={this.state.searchable} /> + +
); } -}; +} Option.propTypes = { children: PropTypes.node, diff --git a/src/Select.js b/src/Select.js index 8981fa4fc9..f378a5a986 100644 --- a/src/Select.js +++ b/src/Select.js @@ -322,11 +322,13 @@ class Select extends React.Component { this.setState({ isOpen: toOpen, isPseudoFocused: false, + focusedOption: null, }); } else { // otherwise, focus the input and open the menu this._openAfterFocus = this.props.openOnClick; this.focus(); + this.setState({ focusedOption: null }); } } @@ -435,6 +437,18 @@ class Select extends React.Component { }); } + setInputValue(newValue) { + if (this.props.onInputChange) { + let nextState = this.props.onInputChange(newValue); + if (nextState != null && typeof nextState !== 'object') { + newValue = '' + nextState; + } + } + this.setState({ + inputValue: newValue + }); + } + handleInputValueChange(newValue) { if (this.props.onInputChange) { let nextState = this.props.onInputChange(newValue); @@ -588,10 +602,10 @@ class Select extends React.Component { const required = handleRequired(value, this.props.multi); this.setState({ required }); } + if (this.props.simpleValue && value) { + value = this.props.multi ? value.map(i => i[this.props.valueKey]).join(this.props.delimiter) : value[this.props.valueKey]; + } if (this.props.onChange) { - if (this.props.simpleValue && value) { - value = this.props.multi ? value.map(i => i[this.props.valueKey]).join(this.props.delimiter) : value[this.props.valueKey]; - } this.props.onChange(value); } } @@ -718,11 +732,15 @@ class Select extends React.Component { .filter(option => !option.option.disabled); this._scrollToFocusedOptionOnUpdate = true; if (!this.state.isOpen) { - this.setState({ + const newState = { + ...this.state, focusedOption: this._focusedOption || (options.length ? options[dir === 'next' ? 0 : options.length - 1].option : null), - inputValue: '', isOpen: true, - }); + }; + if (this.props.onSelectResetsInput) { + newState.inputValue = ''; + } + this.setState(newState); return; } if (!options.length) return; diff --git a/src/Value.js b/src/Value.js index e282fd18ca..d405e78dfc 100644 --- a/src/Value.js +++ b/src/Value.js @@ -1,6 +1,6 @@ -import React from 'react'; -import PropTypes from 'prop-types'; import classNames from 'classnames'; +import PropTypes from 'prop-types'; +import React from 'react'; class Value extends React.Component { @@ -43,12 +43,12 @@ class Value extends React.Component { this.onRemove(event); } - handleTouchMove (event) { + handleTouchMove () { // Set a flag that the view is being dragged this.dragging = true; } - handleTouchStart (event) { + handleTouchStart () { // Set a flag that the view is not being dragged this.dragging = false; } @@ -91,8 +91,7 @@ class Value extends React.Component { ); } -}; - +} Value.propTypes = { children: PropTypes.node, diff --git a/src/utils/defaultArrowRenderer.js b/src/utils/defaultArrowRenderer.js index 3fee9f0ec4..b72ae139ad 100644 --- a/src/utils/defaultArrowRenderer.js +++ b/src/utils/defaultArrowRenderer.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -export default function arrowRenderer ({ onMouseDown }) { +const arrowRenderer = ({ onMouseDown }) => { return ( { return ( ); }; + +export default clearRenderer; diff --git a/src/utils/defaultFilterOptions.js b/src/utils/defaultFilterOptions.js index 5ae9b72410..9d92331e8c 100644 --- a/src/utils/defaultFilterOptions.js +++ b/src/utils/defaultFilterOptions.js @@ -1,11 +1,11 @@ import stripDiacritics from './stripDiacritics'; import trim from './trim'; -function isValid(value) { +const isValid = value => { return typeof (value) !== 'undefined' && value !== null && value !== ''; -} +}; -function filterOptions (options, filterValue, excludeOptions, props) { +const filterOptions = (options, filterValue, excludeOptions, props) => { if (props.ignoreAccents) { filterValue = stripDiacritics(filterValue); } @@ -25,17 +25,17 @@ function filterOptions (options, filterValue, excludeOptions, props) { if (props.filterOption) return props.filterOption.call(this, option, filterValue); if (!filterValue) return true; - var value = option[props.valueKey]; - var label = option[props.labelKey]; - var hasValue = isValid(value); - var hasLabel = isValid(label); + const value = option[props.valueKey]; + const label = option[props.labelKey]; + const hasValue = isValid(value); + const hasLabel = isValid(label); if (!hasValue && !hasLabel) { return false; } - var valueTest = hasValue ? String(value) : null; - var labelTest = hasLabel ? String(label) : null; + let valueTest = hasValue ? String(value) : null; + let labelTest = hasLabel ? String(label) : null; if (props.ignoreAccents) { if (valueTest && props.matchProp !== 'label') valueTest = stripDiacritics(valueTest); @@ -55,6 +55,6 @@ function filterOptions (options, filterValue, excludeOptions, props) { (labelTest && props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0) ); }); -} +}; export default filterOptions; diff --git a/src/utils/defaultMenuRenderer.js b/src/utils/defaultMenuRenderer.js index 224a2376a5..d2fd6494ac 100644 --- a/src/utils/defaultMenuRenderer.js +++ b/src/utils/defaultMenuRenderer.js @@ -1,12 +1,12 @@ import classNames from 'classnames'; +import PropTypes from 'prop-types'; import React from 'react'; -function menuRenderer ({ +const menuRenderer = ({ focusedOption, focusOption, inputValue, instancePrefix, - labelKey, onFocus, onOptionRef, onSelect, @@ -18,11 +18,11 @@ function menuRenderer ({ selectValue, valueArray, valueKey, -}) { +}) => { let Option = optionComponent; return options.map((option, i) => { - let isSelected = valueArray && valueArray.some(x => x[valueKey] == option[valueKey]); + let isSelected = valueArray && valueArray.some(x => x[valueKey] === option[valueKey]); let isFocused = option === focusedOption; let optionClass = classNames(optionClassName, { 'Select-option': true, @@ -53,6 +53,24 @@ function menuRenderer ({ ); }); -} +}; + +menuRenderer.propTypes = { + focusOption: PropTypes.func, + focusedOption: PropTypes.object, + inputValue: PropTypes.string, + instancePrefix: PropTypes.string, + onFocus: PropTypes.func, + onOptionRef: PropTypes.func, + onSelect: PropTypes.func, + optionClassName: PropTypes.string, + optionComponent: PropTypes.func, + optionRenderer: PropTypes.func, + options: PropTypes.array, + removeValue: PropTypes.func, + selectValue: PropTypes.func, + valueArray: PropTypes.array, + valueKey: PropTypes.string, +}; export default menuRenderer; diff --git a/src/utils/stripDiacritics.js b/src/utils/stripDiacritics.js index 478d26e6b9..d6456ddc91 100644 --- a/src/utils/stripDiacritics.js +++ b/src/utils/stripDiacritics.js @@ -1,4 +1,4 @@ -var map = [ +const map = [ { 'base':'A', 'letters':/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g }, { 'base':'AA','letters':/[\uA732]/g }, { 'base':'AE','letters':/[\u00C6\u01FC\u01E2]/g }, @@ -85,9 +85,11 @@ var map = [ { 'base':'z', 'letters':/[\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763]/g }, ]; -export default function stripDiacritics (str) { - for (var i = 0; i < map.length; i++) { +const stripDiacritics = str => { + for (let i = 0; i < map.length; i++) { str = str.replace(map[i].letters, map[i].base); } return str; }; + +export default stripDiacritics; diff --git a/src/utils/trim.js b/src/utils/trim.js index 56aef05bd2..4f0172a419 100644 --- a/src/utils/trim.js +++ b/src/utils/trim.js @@ -1,3 +1,3 @@ -export default function trim(str) { - return str.replace(/^\s+|\s+$/g, ''); -} +const trim = str => str.replace(/^\s+|\s+$/g, ''); + +export default trim; diff --git a/test/Async-test.js b/test/Async-test.js index f76bb19801..ff663d42ea 100644 --- a/test/Async-test.js +++ b/test/Async-test.js @@ -1,4 +1,5 @@ 'use strict'; +/* global describe, it, beforeEach */ /* eslint react/jsx-boolean-value: 0 */ // Emulating the DOM here, only so that if this test file gets @@ -502,8 +503,7 @@ describe('Async', () => { describe('props sync test', () => { it('should update options on componentWillReceiveProps', () => { - createControl({ - }); + createControl({}); asyncInstance.componentWillReceiveProps({ options: [{ label: 'bar', @@ -513,5 +513,27 @@ describe('Async', () => { expect(asyncNode.querySelectorAll('[role=option]').length, 'to equal', 1); expect(asyncNode.querySelector('[role=option]').textContent, 'to equal', 'bar'); }); + + it('should not update options on componentWillReceiveProps', () => { + const props = { options: [] }; + createControl(props); + + const setStateStub = sinon.stub(asyncInstance, 'setState'); + asyncInstance.componentWillReceiveProps(props); + + expect(setStateStub, 'was not called'); + + setStateStub.restore(); + }); + }); + + describe('componentWillUnmount', () => { + it('should set _callback to null', () => { + createControl({}); + expect(asyncInstance._callback, 'not to equal', null); + + asyncInstance.componentWillUnmount(); + expect(asyncInstance._callback, 'to equal', null); + }); }); }); diff --git a/test/AsyncCreatable-test.js b/test/AsyncCreatable-test.js index 514a40bd8e..c891f981f5 100644 --- a/test/AsyncCreatable-test.js +++ b/test/AsyncCreatable-test.js @@ -19,11 +19,10 @@ var sinon = require('sinon'); var Select = require('../src'); describe('AsyncCreatable', () => { - let creatableInstance, creatableNode, filterInputNode, loadOptions, renderer; + let creatableInstance, creatableNode, filterInputNode, loadOptions; beforeEach(() => { loadOptions = sinon.stub(); - renderer = TestUtils.createRenderer(); }); function createControl (props = {}) { diff --git a/test/Creatable-test.js b/test/Creatable-test.js index 5a58726e3a..488eb1f78f 100644 --- a/test/Creatable-test.js +++ b/test/Creatable-test.js @@ -19,9 +19,7 @@ var TestUtils = require('react-dom/test-utils'); var Select = require('../src'); describe('Creatable', () => { - let creatableInstance, creatableNode, filterInputNode, innerSelectInstance, renderer; - - beforeEach(() => renderer = TestUtils.createRenderer()); + let creatableInstance, creatableNode, filterInputNode, innerSelectInstance; const defaultOptions = [ { value: 'one', label: 'One' }, @@ -221,7 +219,7 @@ describe('Creatable', () => { expect(test(newOption('qux', 4)), 'to be', true); expect(test(newOption('Foo', 11)), 'to be', true); }); - + it('default: isOptionUnique function should always return true if given options are empty', () => { const options = []; diff --git a/test/Option-test.js b/test/Option-test.js index e2c85b3713..9fa91468ed 100644 --- a/test/Option-test.js +++ b/test/Option-test.js @@ -1,29 +1,25 @@ -'use strict'; /* global describe, it, beforeEach */ -var helper = require('../testHelpers/jsdomHelper'); -helper(); +import helper from '../testHelpers/jsdomHelper'; +import React from 'react'; +import ReactDOM from 'react-dom'; +import sinon from 'sinon'; +import TestUtils from 'react-dom/test-utils'; +import unexpected from 'unexpected'; +import unexpectedDom from 'unexpected-dom'; +import unexpectedSinon from 'unexpected-sinon'; -var unexpected = require('unexpected'); -var unexpectedDom = require('unexpected-dom'); -var unexpectedSinon = require('unexpected-sinon'); -var sinon = require('sinon'); +import Option from '../src/Option'; -var expect = unexpected +helper(); +const expect = unexpected .clone() .installPlugin(unexpectedSinon) .installPlugin(unexpectedDom); -var React = require('react'); -var ReactDOM = require('react-dom'); -var TestUtils = require('react-dom/test-utils'); - -var Option = require('../src/Option').default; - - -describe('Option component', function() { - var onFocus, onSelect, onUnfocus, instance; - var createOption = (props) => { +describe('Option component', () => { + let onFocus, onSelect, onUnfocus, instance, node; + const createOption = props => { onFocus = sinon.spy(); onSelect = sinon.spy(); onUnfocus = sinon.spy(); @@ -36,12 +32,12 @@ describe('Option component', function() { {...props} /> ); - return instance; + return instance; }; - it('renders the given option', function() { - var props = { + beforeEach(() => { + const props = { instancePrefix: 'test', className: 'Wrapper-Class', children: 'Test Label', @@ -52,7 +48,10 @@ describe('Option component', function() { } }; instance = createOption(props); - var node = ReactDOM.findDOMNode(instance); + node = ReactDOM.findDOMNode(instance); + }); + + it('renders the given option', () => { expect(node.textContent, 'to equal', 'Test Label'); expect(onSelect, 'was not called'); TestUtils.Simulate.mouseDown(node); @@ -63,8 +62,9 @@ describe('Option component', function() { TestUtils.Simulate.mouseMove(node); expect(onFocus, 'was called'); }); - it('does not focus if Option isFocused already', function() { - var props = { + + it('does not focus if Option isFocused already', () => { + const props = { isFocused: true, instancePrefix: 'test', className: 'Wrapper-Class', @@ -76,24 +76,13 @@ describe('Option component', function() { } }; instance = createOption(props); - var node = ReactDOM.findDOMNode(instance); + node = ReactDOM.findDOMNode(instance); expect(onFocus, 'was not called'); TestUtils.Simulate.mouseEnter(node); expect(onFocus, 'was not called'); }); - it('simulates touch events', function() { - var props = { - instancePrefix: 'test', - className: 'Wrapper-Class', - children: 'Test Label', - option: { - title: 'testitem', - label: 'testitem', - className: 'Option-Class' - } - }; - instance = createOption(props); - var node = ReactDOM.findDOMNode(instance); + + it('simulates touch events', () => { expect(instance.dragging, 'to equal', undefined); // simulate scrolling event TestUtils.Simulate.touchStart(node); @@ -110,4 +99,102 @@ describe('Option component', function() { expect(onSelect, 'was called'); expect(instance.dragging, 'to equal', false); }); + + describe('blockEvent', () => { + let preventDefault, stopPropagation, openStub; + beforeEach(() =>{ + preventDefault = sinon.spy(); + stopPropagation = sinon.spy(); + openStub = sinon.stub(window, 'open'); + }); + + afterEach(() => { + openStub.restore(); + }); + + it('should call window.open', () => { + const event = { + target: { + href: 'http://go.com', + tagName: 'A', + target: 'yes', + }, + preventDefault, + stopPropagation, + }; + + instance.blockEvent(event); + + expect(openStub, 'was called once'); + expect(openStub, 'was called with', event.target.href, event.target.target); + }); + + it('should set window.location.href and not call window.open', () => { + const event = { + target: { + href: 'http://go.com', + tagName: 'A', + }, + preventDefault, + stopPropagation, + }; + + Object.defineProperty(window.location, 'href', { + writable: true, + value: 'url' + }); + + expect(window.location.href, 'not to equal', event.target.href); + + instance.blockEvent(event); + + expect(window.location.href, 'to equal', event.target.href); + expect(openStub, 'was not called'); + }); + + it('should return and not call window.open when tagName !=A', () => { + const event = { + target: { + href: 'http://go.com', + tagName: '', + }, + preventDefault, + stopPropagation, + }; + + Object.defineProperty(window.location, 'href', { + writable: true, + value: 'url' + }); + + expect(window.location.href, 'to equal', 'url'); + + instance.blockEvent(event); + + expect(window.location.href, 'to equal', 'url'); + expect(openStub, 'was not called'); + }); + + it('should return and not call window.open when no href', () => { + const event = { + target: { + tagName: 'A', + }, + preventDefault, + stopPropagation, + }; + + Object.defineProperty(window.location, 'href', { + writable: true, + value: 'url' + }); + + expect(window.location.href, 'to equal', 'url'); + + instance.blockEvent(event); + + expect(window.location.href, 'to equal', 'url'); + expect(openStub, 'was not called'); + }); + }); }); diff --git a/test/Select-test.js b/test/Select-test.js index f6e6b4f3fe..946b1f7858 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -2138,6 +2138,24 @@ describe('Select', () => { ]; describe('with single select', () => { + it('should have retained inputValue after accepting selection with onSelectResetsInput=false, when navigating via keyboard', () => { + wrapper = createControlWithWrapper({ + value: '', + options: options, + onSelectResetsInput: false, + onCloseResetsInput: false, + onBlurResetsInput: false, + simpleValue: true, + }); + clickArrowToOpen(); + typeSearchText('tw'); + pressEnterToAccept(); + setValueProp('two'); + + expect(instance.state.inputValue, 'to equal', 'tw'); + expect(instance, 'to contain',
Two
); + expect(instance, 'to contain', ); + }); it('should have retained inputValue after accepting selection with onSelectResetsInput=false', () => { // Render an instance of the component wrapper = createControlWithWrapper({ @@ -2146,6 +2164,7 @@ describe('Select', () => { onSelectResetsInput: false, onCloseResetsInput: false, onBlurResetsInput: false, + simpleValue: true, }); clickArrowToOpen(); @@ -2199,7 +2218,8 @@ describe('Select', () => { value: '', options: options, multi: true, - onSelectResetsInput: false + onSelectResetsInput: false, + simpleValue: true, }); clickArrowToOpen(); @@ -2216,6 +2236,7 @@ describe('Select', () => { value: '', options: options, multi: true, + simpleValue: true, }); clickArrowToOpen(); @@ -4434,36 +4455,44 @@ describe('Select', () => { autoFocus: true, options: defaultOptions, }); - var input = ReactDOM.findDOMNode(instance.input).querySelector('input'); + const input = ReactDOM.findDOMNode(instance.input).querySelector('input'); expect(input, 'to equal', document.activeElement); }); it('with autofocus as well, calls focus() only once', () => { + const warn = sinon.stub(console, 'warn'); wrapper = createControl({ autofocus: true, autoFocus: true, options: defaultOptions, }); - var focus = sinon.spy(instance, 'focus'); + const focus = sinon.spy(instance, 'focus'); instance.componentDidMount(); expect(focus, 'was called once'); + + warn.restore(); }); }); describe('with autofocus', () => { it('focuses the select input on mount', () => { + const warn = sinon.stub(console, 'warn'); wrapper = createControl({ autofocus: true, options: defaultOptions, }); - var input = ReactDOM.findDOMNode(instance.input).querySelector('input'); + const input = ReactDOM.findDOMNode(instance.input).querySelector('input'); expect(input, 'to equal', document.activeElement); + + warn.restore(); }); it('calls console.warn', () => { - var warn = sinon.spy(console, 'warn'); + const warn = sinon.stub(console, 'warn'); wrapper = createControl({ autofocus: true, options: defaultOptions, }); expect(warn, 'was called once'); + + warn.restore(); }); }); describe('rtl', () => { @@ -4520,4 +4549,204 @@ describe('Select', () => { }); }); }); + + describe('handleMouseDown method', () => { + let preventDefault = {}; + let event = {}; + let focusStub = {}; + let setStateStub = {}; + + beforeEach(() => { + preventDefault = sinon.spy(); + event = { + type: 'mousedown', + button: 0, + target: { + tagName: 'yo', + }, + preventDefault, + }; + + instance = createControl({ + openOnClick: true, + }); + + focusStub = sinon.stub(instance, 'focus'); + setStateStub = sinon.stub(instance, 'setState'); + }); + + afterEach(() => { + focusStub.restore(); + setStateStub.restore(); + }); + + it('for isFocused=false should set _openAfterFocus and call focus, setState, preventDefault', () => { + instance.state.isFocused = false; + expect(instance._openAfterFocus, 'to equal', false ); + expect(instance.props.openOnClick, 'to equal', true ); + expect(instance.state.isFocused, 'to equal', false ); + + instance.handleMouseDown(event); + + expect(preventDefault, 'was called once'); + expect(focusStub, 'was called once'); + expect(setStateStub, 'was called once'); + expect(instance._openAfterFocus, 'to equal', true ); + expect(setStateStub, 'was called with', { focusedOption: null }); + }); + + it('for isFocused=true and _focusAfterClear=false should call focus, setState, preventDefault', () => { + expect(instance._focusAfterClear, 'to equal', false ); + expect(instance.state.isFocused, 'to equal', true ); + + instance.handleMouseDown(event); + + expect(preventDefault, 'was called once'); + expect(focusStub, 'was called once'); + expect(setStateStub, 'was called once'); + expect(setStateStub, 'was called with', + { + isOpen: true, + isPseudoFocused: false, + focusedOption: null + }); + + }); + + it('for isFocused=true and _focusAfterClear=true should set _focusAfterClear and call focus, setState, preventDefault', () => { + instance._focusAfterClear = true; + + expect(instance._focusAfterClear, 'to equal', true ); + expect(instance.state.isFocused, 'to equal', true ); + + instance.handleMouseDown(event); + + expect(instance._focusAfterClear, 'to equal', false ); + expect(preventDefault, 'was called once'); + expect(focusStub, 'was called once'); + expect(setStateStub, 'was called once'); + expect(setStateStub, 'was called with', + { + isOpen: false, + isPseudoFocused: false, + focusedOption: null + }); + }); + + it('for searchable=false and should call focus, setState, preventDefault', () => { + instance = createControl({ searchable: false }); + + focusStub = sinon.stub(instance, 'focus'); + setStateStub = sinon.stub(instance, 'setState'); + const isOpen = instance.state.isOpen; + + instance.handleMouseDown(event); + + expect(preventDefault, 'was called once'); + expect(focusStub, 'was called once'); + expect(setStateStub, 'was called once'); + expect(setStateStub, 'was called with', { isOpen: !isOpen }); + }); + + it('for tagName="INPUT", isFocused=false should call only focus', () => { + event = { + type: 'mousedown', + button: 0, + target: { + tagName: 'INPUT', + }, + preventDefault, + }; + + instance.state.isFocused = false; + expect(instance._openAfterFocus, 'to equal', false ); + + instance.handleMouseDown(event); + + expect(instance._openAfterFocus, 'to equal', true ); + expect(preventDefault, 'was not called'); + expect(focusStub, 'was called once'); + expect(setStateStub, 'was not called'); + }); + + it('for tagName="INPUT", isFocused=true, isOpen=false should call setState', () => { + event = { + type: 'mousedown', + button: 0, + target: { + tagName: 'INPUT', + }, + preventDefault, + }; + + instance.state.isFocused = true; + instance.state.isOpen = false; + + instance.handleMouseDown(event); + + expect(preventDefault, 'was not called'); + expect(focusStub, 'was not called'); + expect(setStateStub, 'was called once'); + expect(setStateStub, 'was called with', { isOpen: true, isPseudoFocused: false }); + }); + + it('for tagName="INPUT", isFocused=true, isOpen=true should return', () => { + event = { + type: 'mousedown', + button: 0, + target: { + tagName: 'INPUT', + }, + preventDefault, + }; + + instance.state.isFocused = true; + instance.state.isOpen = true; + + instance.handleMouseDown(event); + + expect(preventDefault, 'was not called'); + expect(focusStub, 'was not called'); + expect(setStateStub, 'was not called'); + }); + + it('should return for disabled', () => { + event = { + type: 'mousedown', + button: 0, + target: { + tagName: 'INPUT', + }, + preventDefault, + }; + + instance = createControl({ disabled: true }); + + focusStub = sinon.stub(instance, 'focus'); + setStateStub = sinon.stub(instance, 'setState'); + + instance.handleMouseDown(event); + + expect(preventDefault, 'was not called'); + expect(focusStub, 'was not called'); + expect(setStateStub, 'was not called'); + }); + + it('should return for button !=0', () => { + event = { + type: 'mousedown', + button: 2, + target: { + tagName: 'INPUT', + }, + preventDefault, + }; + + instance.handleMouseDown(event); + + expect(preventDefault, 'was not called'); + expect(focusStub, 'was not called'); + expect(setStateStub, 'was not called'); + }); + }); }); diff --git a/webpack.config.js b/webpack.config.js index 4f83858c48..1df7a4fc22 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -24,7 +24,7 @@ module.exports = { exclude: [/node_modules/], use: [{ loader: 'babel-loader', - options: { presets: ['es2015'] }, + options: { presets: ['env'] }, }], }, {