Skip to content

Commit

Permalink
Add more tests to Filter spec (#2315)
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-liu authored and mistercrunch committed Mar 9, 2017
1 parent 422d1fe commit e817382
Showing 1 changed file with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import SelectControl from '../../../../javascripts/explorev2/components/controls

const defaultProps = {
choices: ['country_name'],
opChoices: ['in', 'not in'],
changeFilter: sinon.spy(),
removeFilter: () => {
// noop
},
filter: {
col: null,
op: 'in',
value: '',
value: ['val'],
},
datasource: {
id: 1,
Expand All @@ -45,6 +44,25 @@ describe('Filter', () => {
expect(wrapper.find(Select)).to.have.lengthOf(2);
expect(wrapper.find(Button)).to.have.lengthOf(1);
expect(wrapper.find(SelectControl)).to.have.lengthOf(1);
expect(wrapper.find('#select-op').prop('options')).to.have.lengthOf(2);
});

it('renders five op choices for table datasource', () => {
const props = defaultProps;
props.datasource = {
id: 1,
type: 'druid',
filter_select: false,
};
const druidWrapper = shallow(<Filter {...props} />);
expect(druidWrapper.find('#select-op').prop('options')).to.have.lengthOf(5);
});

it('renders six op choices for having filter', () => {
const props = defaultProps;
props.having = true;
const havingWrapper = shallow(<Filter {...props} />);
expect(havingWrapper.find('#select-op').prop('options')).to.have.lengthOf(6);
});

it('calls changeFilter when select is changed', () => {
Expand All @@ -56,4 +74,15 @@ describe('Filter', () => {
selectVal.simulate('change', { value: 'x' });
expect(defaultProps.changeFilter).to.have.property('callCount', 3);
});

it('renders input for regex filters', () => {
const props = defaultProps;
props.filter = {
col: null,
op: 'regex',
value: 'val',
};
const regexWrapper = shallow(<Filter {...props} />);
expect(regexWrapper.find('input')).to.have.lengthOf(1);
});
});

0 comments on commit e817382

Please sign in to comment.