Add a Async Select that fetches options from given endpoint (#1909)

* Add a Async Select that fetches options from given endpoint

* update it statement
This commit is contained in:
vera-liu
2017-01-11 10:31:30 -08:00
committed by GitHub
parent 94d20168da
commit f0917c62f2
6 changed files with 112 additions and 106 deletions

View File

@@ -1,34 +1,35 @@
import React from 'react';
import Select from 'react-select';
import DatabaseSelect from '../../../javascripts/SqlLab/components/DatabaseSelect';
import AsyncSelect from '../../../javascripts/components/AsyncSelect';
import { shallow } from 'enzyme';
import { describe, it } from 'mocha';
import { expect } from 'chai';
import sinon from 'sinon';
describe('DatabaseSelect', () => {
describe('AsyncSelect', () => {
const mockedProps = {
actions: {},
dataEndpoint: '/slicemodelview/api/read',
onChange: sinon.spy(),
mutator: () => {},
};
it('is valid element', () => {
expect(
React.isValidElement(<DatabaseSelect {...mockedProps} />)
React.isValidElement(<AsyncSelect {...mockedProps} />)
).to.equal(true);
});
it('has one select', () => {
const wrapper = shallow(
<DatabaseSelect {...mockedProps} />
<AsyncSelect {...mockedProps} />
);
expect(wrapper.find(Select)).to.have.length(1);
});
it('calls onChange on select change', () => {
const onChange = sinon.spy();
const wrapper = shallow(
<DatabaseSelect onChange={onChange} />
<AsyncSelect {...mockedProps} />
);
wrapper.find(Select).simulate('change', { value: 1 });
expect(onChange).to.have.property('callCount', 1);
expect(mockedProps.onChange).to.have.property('callCount', 1);
});
});

View File

@@ -18,14 +18,8 @@ describe('QuerySearch', () => {
});
const wrapper = shallow(<QuerySearch {...mockedProps} />);
it('should have four Select', () => {
expect(wrapper.find(Select)).to.have.length(4);
});
it('updates userId on user selects change', () => {
wrapper.find('[name="select-user"]')
.simulate('change', { value: 1 });
expect(wrapper.state().userId).to.equal(1);
it('should have three Select', () => {
expect(wrapper.find(Select)).to.have.length(3);
});
it('updates fromTime on user selects from time', () => {