Added filter in ControlPanelsContainer for explore V2 (#1647)

* Added filter in ControlPanelsContainer

* Move function for getting url params object to utils

* Fixed python test

* Move Filter to separate component

* Added specs and made changes based on comments

* Moved specs to right folder
This commit is contained in:
vera-liu
2016-11-23 09:51:19 -08:00
committed by GitHub
parent cef4a8296a
commit 39ce4aa049
15 changed files with 354 additions and 133 deletions

View File

@@ -15,4 +15,15 @@ describe('reducers', () => {
actions.setFieldValue('table', 'show_legend'));
expect(newState.viz.form_data.show_legend).to.equal(false);
});
it('adds a filter given a new filter', () => {
const newState = exploreReducer(initialState('table'),
actions.addFilter({
id: 1,
prefix: 'flt',
col: null,
op: null,
value: null,
}));
expect(newState.viz.form_data.filters).to.have.length(1);
});
});

View File

@@ -0,0 +1,41 @@
/* eslint-disable no-unused-expressions */
import React from 'react';
import Select from 'react-select';
import { Button } from 'react-bootstrap';
import { expect } from 'chai';
import { describe, it, beforeEach } from 'mocha';
import { shallow } from 'enzyme';
import Filter from '../../../../javascripts/explorev2/components/Filter';
const defaultProps = {
actions: {},
filterColumnOpts: ['country_name'],
filter: {
id: 1,
prefix: 'flt',
col: 'country_name',
eq: 'in',
value: 'China',
},
prefix: 'flt',
};
describe('Filter', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(<Filter {...defaultProps} />);
});
it('renders Filters', () => {
expect(
React.isValidElement(<Filter {...defaultProps} />)
).to.equal(true);
});
it('renders two select, one button and one input', () => {
expect(wrapper.find(Select)).to.have.lengthOf(2);
expect(wrapper.find(Button)).to.have.lengthOf(1);
expect(wrapper.find('input')).to.have.lengthOf(1);
});
});

View File

@@ -0,0 +1,40 @@
/* eslint-disable no-unused-expressions */
import React from 'react';
import { Button } from 'react-bootstrap';
import { expect } from 'chai';
import { describe, it, beforeEach } from 'mocha';
import { shallow } from 'enzyme';
import { Filters } from '../../../../javascripts/explorev2/components/Filters';
import Filter from '../../../../javascripts/explorev2/components/Filter';
const defaultProps = {
filterColumnOpts: ['country_name'],
filters: [
{
id: 1,
prefix: 'flt',
col: 'country_name',
eq: 'in',
value: 'China',
}],
prefix: 'flt',
};
describe('Filters', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(<Filters {...defaultProps} />);
});
it('renders Filters', () => {
expect(
React.isValidElement(<Filters {...defaultProps} />)
).to.equal(true);
});
it('renders one filter', () => {
expect(wrapper.find(Filter)).to.have.lengthOf(1);
expect(wrapper.find(Button)).to.have.lengthOf(1);
});
});