Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,14 @@ var Select = React.createClass({
});
}
if (newProps.value !== this.state.value || newProps.placeholder !== this.props.placeholder || optionsChanged) {
var setState = () => {
this.setState(this.getStateFromValue(newProps.value, newProps.options, newProps.placeholder));
var setState = (newState) => {
this.setState(this.getStateFromValue(newProps.value,
(newState && newState.options) || newProps.options,
newProps.placeholder)
);
};
if (this.props.asyncOptions) {
this.loadAsyncOptions(newProps.value, setState);
this.loadAsyncOptions(newProps.value, {}, setState);
} else {
setState();
}
Expand Down Expand Up @@ -514,7 +517,7 @@ var Select = React.createClass({
}
}
this.setState(newState);
if (callback) callback.call(this, {});
if (callback) callback.call(this, newState);
return;
}
}
Expand All @@ -540,7 +543,7 @@ var Select = React.createClass({
}
}
this.setState(newState);
if (callback) callback.call(this, {});
if (callback) callback.call(this, newState);
});
},

Expand Down
31 changes: 28 additions & 3 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ describe('Select', function() {
beforeEach(function () {

// Render an instance of the component
instance = createControl({
wrapper = createControlWithWrapper({
value: '',
asyncOptions: asyncOptions,
autoload: true
Expand Down Expand Up @@ -1134,12 +1134,20 @@ describe('Select', function() {
]
});


expect(function () {
typeSearchText('tes');
}, 'to throw exception', new Error('Something\'s wrong jim'));
});

it('calls the asyncOptions function when the value prop changes', function () {

expect(asyncOptions, 'was called once');

wrapper.setPropsForChild({ value: 'test2' });

expect(asyncOptions, 'was called twice');
});


});

Expand Down Expand Up @@ -1172,7 +1180,7 @@ describe('Select', function() {
beforeEach(function () {

// Render an instance of the component
instance = createControl({
wrapper = createControlWithWrapper({
value: '',
asyncOptions: asyncOptions,
disableCache: true
Expand All @@ -1195,6 +1203,23 @@ describe('Select', function() {
expect(asyncOptions, 'was called times', 4);

});

it('updates the displayed value after changing value and refreshing from asyncOptions', function () {

asyncOptions.reset();
asyncOptions.callsArgWith(1, null, {
options: [
{ value: 'newValue', label: 'New Value from Server' },
{ value: 'test', label: 'TEST one' }
]
});

wrapper.setPropsForChild({ value: 'newValue' });

expect(React.findDOMNode(instance), 'queried for first', DISPLAYED_SELECTION_SELECTOR,
'to have text', 'New Value from Server');
});


});
});
Expand Down