Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix auto select override pre-selected value bug #2745

Merged
merged 2 commits into from
May 11, 2017
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
2 changes: 1 addition & 1 deletion superset/assets/javascripts/components/AsyncSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AsyncSelect extends React.PureComponent {
$.get(this.props.dataEndpoint, (data) => {
this.setState({ options: mutator ? mutator(data) : data, isLoading: false });

if (this.props.autoSelect && this.state.options.length) {
if (!this.props.value && this.props.autoSelect && this.state.options.length) {
this.onChange(this.state.options[0]);
}
})
Expand Down
12 changes: 12 additions & 0 deletions superset/assets/spec/javascripts/components/AsyncSelect_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,17 @@ describe('AsyncSelect', () => {
expect(spy.callCount).to.equal(1);
expect(spy.calledWith(wrapper.instance().state.options[0])).to.equal(true);
});
it('should not auto select when value prop is set', () => {
const wrapper = mount(
<AsyncSelect {...mockedProps} value={2} autoSelect />,
);
const spy = sinon.spy(wrapper.instance(), 'onChange');

server.respond();

expect(spy.callCount).to.equal(0);
expect(wrapper.find(Select)).to.have.length(1);
expect(wrapper.find('.Select-value-label').children().first().text()).to.equal('another');
});
});
});