Skip to content

Commit

Permalink
onSelectResetsInput tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dehamilton committed Dec 13, 2017
1 parent f3b181d commit 2c2630e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ class Select extends React.Component {
this.hasScrolledToOption = false;
}
const updatedValue = this.props.onSelectResetsInput ? '' : this.state.inputValue;
console.log(this.props.onSelectResetsInput, this.state.inputValue, updatedValue);
if (this.props.multi) {
this.setState({
focusedIndex: null,
Expand Down
60 changes: 60 additions & 0 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,66 @@ describe('Select', () => {

});

describe('with multi=true and onSelectResetsInput=false', () => {
it('should have retained inputValue after accepting selection', () => {
options = [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' },
{ value: 'three', label: 'Three' },
{ value: 'four', label: 'Four' }
];

// Render an instance of the component
wrapper = createControlWithWrapper({
value: '',
options: options,
multi: true,
closeOnSelect: false,
removeSelected: false,
onSelectResetsInput: false
});

instance.setState({
isFocused: true
});

clickArrowToOpen();
typeSearchText('two');
pressEnterToAccept();
setValueProp('two'); // trigger componentWillReceiveProps

expect(instance.state.inputValue, 'to equal', 'two');
});

it('should have reset the inputValue after accepting selection', () => {
options = [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' },
{ value: 'three', label: 'Three' },
{ value: 'four', label: 'Four' }
];

// Render an instance of the component
wrapper = createControlWithWrapper({
value: '',
options: options,
multi: true,
closeOnSelect: false,
removeSelected: false
});

instance.setState({
isFocused: true
});

clickArrowToOpen();
typeSearchText('two');
pressEnterToAccept();

expect(instance.state.inputValue, 'to equal', '');
});
});

describe('with removeSelected=false', () => {
beforeEach(() => {
options = [
Expand Down

0 comments on commit 2c2630e

Please sign in to comment.