[Explore] Adding custom expressions to adhoc metrics (#4736)

* adding custom expressions to adhoc metrics

* adjusted transitions and made the box expandable
This commit is contained in:
Gabe Lyons
2018-04-13 11:20:53 -07:00
committed by Chris Williams
parent 4c268ec678
commit 8669874ec6
15 changed files with 430 additions and 55 deletions

View File

@@ -6,7 +6,7 @@ import { describe, it } from 'mocha';
import { shallow } from 'enzyme';
import { Button, FormGroup, Popover } from 'react-bootstrap';
import AdhocMetric from '../../../../javascripts/explore/AdhocMetric';
import AdhocMetric, { EXPRESSION_TYPES } from '../../../../javascripts/explore/AdhocMetric';
import AdhocMetricEditPopover from '../../../../javascripts/explore/components/AdhocMetricEditPopover';
import { AGGREGATES } from '../../../../javascripts/explore/constants';
@@ -17,10 +17,16 @@ const columns = [
];
const sumValueAdhocMetric = new AdhocMetric({
expressionType: EXPRESSION_TYPES.SIMPLE,
column: columns[2],
aggregate: AGGREGATES.SUM,
});
const sqlExpressionAdhocMetric = new AdhocMetric({
expressionType: EXPRESSION_TYPES.SQL,
sqlExpression: 'COUNT(*)',
});
function setup(overrides) {
const onChange = sinon.spy();
const onClose = sinon.spy();
@@ -39,7 +45,7 @@ describe('AdhocMetricEditPopover', () => {
it('renders a popover with edit metric form contents', () => {
const { wrapper } = setup();
expect(wrapper.find(Popover)).to.have.lengthOf(1);
expect(wrapper.find(FormGroup)).to.have.lengthOf(2);
expect(wrapper.find(FormGroup)).to.have.lengthOf(3);
expect(wrapper.find(Button)).to.have.lengthOf(2);
});
@@ -55,6 +61,12 @@ describe('AdhocMetricEditPopover', () => {
expect(wrapper.state('adhocMetric')).to.deep.equal(sumValueAdhocMetric.duplicateWith({ aggregate: AGGREGATES.AVG }));
});
it('overwrites the adhocMetric in state with onSqlExpressionChange', () => {
const { wrapper } = setup({ adhocMetric: sqlExpressionAdhocMetric });
wrapper.instance().onSqlExpressionChange('COUNT(1)');
expect(wrapper.state('adhocMetric')).to.deep.equal(sqlExpressionAdhocMetric.duplicateWith({ sqlExpression: 'COUNT(1)' }));
});
it('overwrites the adhocMetric in state with onLabelChange', () => {
const { wrapper } = setup();
wrapper.instance().onLabelChange({ target: { value: 'new label' } });
@@ -87,4 +99,15 @@ describe('AdhocMetricEditPopover', () => {
wrapper.instance().onColumnChange({ column: columns[1] });
expect(wrapper.find(Button).find({ bsStyle: 'primary' })).to.have.lengthOf(1);
});
it('will initiate a drag when clicked', () => {
const { wrapper } = setup();
wrapper.instance().onDragDown = sinon.spy();
wrapper.instance().forceUpdate();
expect(wrapper.find('i.glyphicon-resize-full')).to.have.lengthOf(1);
expect(wrapper.instance().onDragDown.calledOnce).to.be.false;
wrapper.find('i.glyphicon-resize-full').simulate('mouseDown');
expect(wrapper.instance().onDragDown.calledOnce).to.be.true;
});
});