mirror of
https://github.com/apache/superset.git
synced 2026-04-17 23:25:05 +00:00
[sql lab]Add autoSelect (#2713)
In sql editor database dropdown list, we want to auto-select the first available option.
This commit is contained in:
committed by
Maxime Beauchemin
parent
cb14640a82
commit
fffb7b500a
@@ -4,6 +4,7 @@ import { shallow } from 'enzyme';
|
||||
import { describe, it } from 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import sinon from 'sinon';
|
||||
import $ from 'jquery';
|
||||
|
||||
import AsyncSelect from '../../../javascripts/components/AsyncSelect';
|
||||
|
||||
@@ -11,7 +12,10 @@ describe('AsyncSelect', () => {
|
||||
const mockedProps = {
|
||||
dataEndpoint: '/slicemodelview/api/read',
|
||||
onChange: sinon.spy(),
|
||||
mutator: () => {},
|
||||
mutator: () => [
|
||||
{ value: 1, label: 'main' },
|
||||
{ value: 2, label: 'another' },
|
||||
],
|
||||
};
|
||||
it('is valid element', () => {
|
||||
expect(
|
||||
@@ -33,4 +37,33 @@ describe('AsyncSelect', () => {
|
||||
wrapper.find(Select).simulate('change', { value: 1 });
|
||||
expect(mockedProps.onChange).to.have.property('callCount', 1);
|
||||
});
|
||||
|
||||
describe('auto select', () => {
|
||||
let stub;
|
||||
beforeEach(() => {
|
||||
stub = sinon.stub($, 'get');
|
||||
stub.yields();
|
||||
});
|
||||
afterEach(() => {
|
||||
stub.restore();
|
||||
});
|
||||
it('should be off by default', () => {
|
||||
const wrapper = shallow(
|
||||
<AsyncSelect {...mockedProps} />,
|
||||
);
|
||||
const spy = sinon.spy(wrapper.instance(), 'onChange');
|
||||
|
||||
wrapper.instance().fetchOptions();
|
||||
expect(spy.callCount).to.equal(0);
|
||||
});
|
||||
it('should auto select first option', () => {
|
||||
const wrapper = shallow(
|
||||
<AsyncSelect {...mockedProps} autoSelect />,
|
||||
);
|
||||
const spy = sinon.spy(wrapper.instance(), 'onChange');
|
||||
|
||||
wrapper.instance().fetchOptions();
|
||||
expect(spy.calledWith(wrapper.instance().state.options[0])).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user