Skip to content

Commit

Permalink
zd - Add class to Select component when in Async mode for testing
Browse files Browse the repository at this point in the history
This would simplify testing when this component is used in selenium tests. We can wait for the result set to be loaded, but doing so would require that change to made in every place this is being used in tests. Adding this class would allow the page object to be able to check itself and every test would benefit automatically.
  • Loading branch information
zldavis committed Dec 11, 2017
1 parent 909e2bd commit 47d963d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/Select.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import ReactSelect from 'react-select-plus';
import classnames from 'classnames';
import Close from './Close';
import Icon from './Icon';
import noop from 'lodash.noop';
Expand All @@ -11,6 +12,7 @@ import './Select.scss';

class Select extends React.Component {
static propTypes = {
className: PropTypes.string,
defaultValue: PropTypes.any,
loadOptions: PropTypes.func,
onChange: PropTypes.func,
Expand Down Expand Up @@ -48,9 +50,10 @@ class Select extends React.Component {
}

render() {
const { value, ...props } = this.props;
const { className, value, ...props } = this.props;
delete props.onChange; // don't pass onChange prop to react-select
const SelectElement = this.props.loadOptions ? ReactSelect.Async : ReactSelect;
const classNames = classnames(className, {'select-async': this.props.loadOptions});

return (
<SelectElement
Expand All @@ -61,6 +64,7 @@ class Select extends React.Component {
onChange={this.onChange}
value={value || this.state.value}
ref={this.bindInput}
className={classNames}
{...props}
/>
);
Expand Down
20 changes: 20 additions & 0 deletions test/components/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('<Select />', () => {
it('should have a blank default', () => {
assert.equal(component.type(), ReactSelect);
assert.equal(component.prop('value'), null);
assert(!component.hasClass('select-async'));
});

it('should clear input', () => {
Expand Down Expand Up @@ -78,6 +79,25 @@ describe('<Select />', () => {

const component = shallow(<Select loadOptions={getOptions} />);
assert.equal(component.type(), ReactSelect.Async);
assert(component.hasClass('select-async'));
});

it('should append the async class to the className prop', () => {
const getOptions = (input, callback) => {
callback(null, {
options: [
{ value: 'oogah', label: 'Oogah' },
{ value: 'chaka', label: 'Chaka' }
],
complete: true
});
};

const component = shallow(<Select loadOptions={getOptions} className="foo bar" />);
assert.equal(component.type(), ReactSelect.Async);
assert(component.hasClass('foo'));
assert(component.hasClass('bar'));
assert(component.hasClass('select-async'));
});

it('should support focus', () => {
Expand Down

0 comments on commit 47d963d

Please sign in to comment.