diff --git a/superset/assets/javascripts/explore/components/controls/SelectControl.jsx b/superset/assets/javascripts/explore/components/controls/SelectControl.jsx index 09a7346a47618..0b609696493e2 100644 --- a/superset/assets/javascripts/explore/components/controls/SelectControl.jsx +++ b/superset/assets/javascripts/explore/components/controls/SelectControl.jsx @@ -34,7 +34,6 @@ export default class SelectControl extends React.PureComponent { super(props); this.state = { options: this.getOptions(props) }; this.onChange = this.onChange.bind(this); - this.renderOption = this.renderOption.bind(this); } componentWillReceiveProps(nextProps) { if (nextProps.choices !== this.props.choices) { @@ -60,7 +59,6 @@ export default class SelectControl extends React.PureComponent { value: c[0], label, }; - if (c[2]) option.imgSrc = c[2]; } else if (Object.is(c)) { option = c; } else { @@ -88,17 +86,6 @@ export default class SelectControl extends React.PureComponent { } return options; } - renderOption(opt) { - if (opt.imgSrc) { - return ( -
- {opt.value} - {opt.label} -
- ); - } - return opt.label; - } render() { // Tab, comma or Enter will trigger a new option created for FreeFormSelect const selectProps = { @@ -111,7 +98,7 @@ export default class SelectControl extends React.PureComponent { clearable: this.props.clearable, isLoading: this.props.isLoading, onChange: this.onChange, - optionRenderer: this.renderOption, + optionRenderer: () => opt.label, }; // Tab, comma or Enter will trigger a new option created for FreeFormSelect const selectWrap = this.props.freeForm ? diff --git a/superset/assets/spec/javascripts/explorev2/actions_spec.js b/superset/assets/spec/javascripts/explore/actions_spec.js similarity index 100% rename from superset/assets/spec/javascripts/explorev2/actions_spec.js rename to superset/assets/spec/javascripts/explore/actions_spec.js diff --git a/superset/assets/spec/javascripts/explorev2/components/ChartContainer_spec.js b/superset/assets/spec/javascripts/explore/components/ChartContainer_spec.js similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/ChartContainer_spec.js rename to superset/assets/spec/javascripts/explore/components/ChartContainer_spec.js diff --git a/superset/assets/spec/javascripts/explorev2/components/CheckboxControl_spec.jsx b/superset/assets/spec/javascripts/explore/components/CheckboxControl_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/CheckboxControl_spec.jsx rename to superset/assets/spec/javascripts/explore/components/CheckboxControl_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/ControlPanelsContainer_spec.jsx b/superset/assets/spec/javascripts/explore/components/ControlPanelsContainer_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/ControlPanelsContainer_spec.jsx rename to superset/assets/spec/javascripts/explore/components/ControlPanelsContainer_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/ControlRow_spec.jsx b/superset/assets/spec/javascripts/explore/components/ControlRow_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/ControlRow_spec.jsx rename to superset/assets/spec/javascripts/explore/components/ControlRow_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/DisplayQueryButton_spec.jsx b/superset/assets/spec/javascripts/explore/components/DisplayQueryButton_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/DisplayQueryButton_spec.jsx rename to superset/assets/spec/javascripts/explore/components/DisplayQueryButton_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/EmbedCodeButton_spec.jsx b/superset/assets/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/EmbedCodeButton_spec.jsx rename to superset/assets/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/ExploreActionButtons_spec.jsx b/superset/assets/spec/javascripts/explore/components/ExploreActionButtons_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/ExploreActionButtons_spec.jsx rename to superset/assets/spec/javascripts/explore/components/ExploreActionButtons_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/ExploreViewContainer_spec.js b/superset/assets/spec/javascripts/explore/components/ExploreViewContainer_spec.js similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/ExploreViewContainer_spec.js rename to superset/assets/spec/javascripts/explore/components/ExploreViewContainer_spec.js diff --git a/superset/assets/spec/javascripts/explorev2/components/FilterControl_spec.jsx b/superset/assets/spec/javascripts/explore/components/FilterControl_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/FilterControl_spec.jsx rename to superset/assets/spec/javascripts/explore/components/FilterControl_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/Filter_spec.jsx b/superset/assets/spec/javascripts/explore/components/Filter_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/Filter_spec.jsx rename to superset/assets/spec/javascripts/explore/components/Filter_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/QueryAndSaveBtns_spec.jsx b/superset/assets/spec/javascripts/explore/components/QueryAndSaveBtns_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/QueryAndSaveBtns_spec.jsx rename to superset/assets/spec/javascripts/explore/components/QueryAndSaveBtns_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/RunQueryActionButton_spec.jsx b/superset/assets/spec/javascripts/explore/components/RunQueryActionButton_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/RunQueryActionButton_spec.jsx rename to superset/assets/spec/javascripts/explore/components/RunQueryActionButton_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/SaveModal_spec.jsx b/superset/assets/spec/javascripts/explore/components/SaveModal_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/SaveModal_spec.jsx rename to superset/assets/spec/javascripts/explore/components/SaveModal_spec.jsx diff --git a/superset/assets/spec/javascripts/explore/components/SelectControl_spec.jsx b/superset/assets/spec/javascripts/explore/components/SelectControl_spec.jsx new file mode 100644 index 0000000000000..7508eebd41463 --- /dev/null +++ b/superset/assets/spec/javascripts/explore/components/SelectControl_spec.jsx @@ -0,0 +1,79 @@ +/* eslint-disable no-unused-expressions */ +import React from 'react'; +import Select, { Creatable } from 'react-select'; +import sinon from 'sinon'; +import { expect } from 'chai'; +import { describe, it, beforeEach } from 'mocha'; +import { shallow } from 'enzyme'; +import SelectControl from '../../../../javascripts/explore/components/controls/SelectControl'; + +const defaultProps = { + choices: [['1 year ago', '1 year ago'], ['today', 'today']], + name: 'row_limit', + label: 'Row Limit', + onChange: sinon.spy(), +}; + +const options = [ + { value: '1 year ago', label: '1 year ago' }, + { value: 'today', label: 'today' }, +]; + +describe('SelectControl', () => { + let wrapper; + + beforeEach(() => { + wrapper = shallow(); + }); + + it('renders a Select', () => { + expect(wrapper.find(Select)).to.have.lengthOf(1); + }); + + it('calls onChange when toggled', () => { + const select = wrapper.find(Select); + select.simulate('change', { value: 50 }); + expect(defaultProps.onChange.calledWith(50)).to.be.true; + }); + + it('renders a Creatable for freeform', () => { + wrapper = shallow(); + expect(wrapper.find(Creatable)).to.have.lengthOf(1); + }); + + describe('getOptions', () => { + it('returns the correct options', () => { + expect(wrapper.instance().getOptions(defaultProps)).to.deep.equal(options); + }); + + it('returns the correct options when freeform is set to true', () => { + const freeFormProps = Object.assign(defaultProps, { + choices: [], + freeForm: true, + value: ['one', 'two'], + }); + const newOptions = [ + { value: 'one', label: 'one' }, + { value: 'two', label: 'two' }, + ]; + expect(wrapper.instance().getOptions(freeFormProps)).to.deep.equal(newOptions); + }); + }); + + describe('componentWillReceiveProps', () => { + it('sets state.options if props.choices has changed', () => { + const updatedOptions = [ + { value: 'three', label: 'three' }, + { value: 'four', label: 'four' }, + ]; + const newProps = { + choices: [['three', 'three'], ['four', 'four']], + name: 'name', + freeForm: false, + value: null, + }; + wrapper.setProps(newProps); + expect(wrapper.state().options).to.deep.equal(updatedOptions); + }); + }); +}); diff --git a/superset/assets/spec/javascripts/explorev2/components/TextArea_spec.jsx b/superset/assets/spec/javascripts/explore/components/TextArea_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/TextArea_spec.jsx rename to superset/assets/spec/javascripts/explore/components/TextArea_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/URLShortLinkButton_spec.jsx b/superset/assets/spec/javascripts/explore/components/URLShortLinkButton_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/URLShortLinkButton_spec.jsx rename to superset/assets/spec/javascripts/explore/components/URLShortLinkButton_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/VizTypeControl_spec.jsx b/superset/assets/spec/javascripts/explore/components/VizTypeControl_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/components/VizTypeControl_spec.jsx rename to superset/assets/spec/javascripts/explore/components/VizTypeControl_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/utils_spec.jsx b/superset/assets/spec/javascripts/explore/utils_spec.jsx similarity index 100% rename from superset/assets/spec/javascripts/explorev2/utils_spec.jsx rename to superset/assets/spec/javascripts/explore/utils_spec.jsx diff --git a/superset/assets/spec/javascripts/explorev2/components/SelectControl_spec.jsx b/superset/assets/spec/javascripts/explorev2/components/SelectControl_spec.jsx deleted file mode 100644 index a2caeff601b9b..0000000000000 --- a/superset/assets/spec/javascripts/explorev2/components/SelectControl_spec.jsx +++ /dev/null @@ -1,38 +0,0 @@ -/* eslint-disable no-unused-expressions */ -import React from 'react'; -import Select, { Creatable } from 'react-select'; -import sinon from 'sinon'; -import { expect } from 'chai'; -import { describe, it, beforeEach } from 'mocha'; -import { shallow } from 'enzyme'; -import SelectControl from '../../../../javascripts/explore/components/controls/SelectControl'; - -const defaultProps = { - choices: [[10, 10], [20, 20]], - name: 'row_limit', - label: 'Row Limit', - onChange: sinon.spy(), -}; - -describe('SelectControl', () => { - let wrapper; - - beforeEach(() => { - wrapper = shallow(); - }); - - it('renders a Select', () => { - expect(wrapper.find(Select)).to.have.lengthOf(1); - }); - - it('calls onChange when toggled', () => { - const select = wrapper.find(Select); - select.simulate('change', { value: 50 }); - expect(defaultProps.onChange.calledWith(50)).to.be.true; - }); - - it('renders a Creatable for freeform', () => { - wrapper = shallow(); - expect(wrapper.find(Creatable)).to.have.lengthOf(1); - }); -});