2019-01-15 18:53:27 -05:00
|
|
|
/**
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2018-03-28 20:41:29 -04:00
|
|
|
/* eslint-disable no-unused-expressions */
|
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
|
2020-05-07 17:18:10 -04:00
|
|
|
import MetricsControl from 'src/explore/components/controls/MetricsControl';
|
|
|
|
import { AGGREGATES } from 'src/explore/constants';
|
2020-05-19 19:59:49 -04:00
|
|
|
import OnPasteSelect from 'src/components/Select/OnPasteSelect';
|
2020-05-07 17:18:10 -04:00
|
|
|
import AdhocMetric, { EXPRESSION_TYPES } from 'src/explore/AdhocMetric';
|
2018-03-28 20:41:29 -04:00
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
name: 'metrics',
|
|
|
|
label: 'Metrics',
|
|
|
|
value: undefined,
|
|
|
|
multi: true,
|
|
|
|
columns: [
|
|
|
|
{ type: 'VARCHAR(255)', column_name: 'source' },
|
|
|
|
{ type: 'VARCHAR(255)', column_name: 'target' },
|
|
|
|
{ type: 'DOUBLE', column_name: 'value' },
|
|
|
|
],
|
|
|
|
savedMetrics: [
|
|
|
|
{ metric_name: 'sum__value', expression: 'SUM(energy_usage.value)' },
|
|
|
|
{ metric_name: 'avg__value', expression: 'AVG(energy_usage.value)' },
|
|
|
|
],
|
2018-04-02 19:08:25 -04:00
|
|
|
datasourceType: 'sqla',
|
2018-03-28 20:41:29 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
function setup(overrides) {
|
|
|
|
const onChange = sinon.spy();
|
|
|
|
const props = {
|
|
|
|
onChange,
|
|
|
|
...defaultProps,
|
|
|
|
...overrides,
|
|
|
|
};
|
|
|
|
const wrapper = shallow(<MetricsControl {...props} />);
|
|
|
|
return { wrapper, onChange };
|
|
|
|
}
|
|
|
|
|
|
|
|
const valueColumn = { type: 'DOUBLE', column_name: 'value' };
|
|
|
|
|
|
|
|
const sumValueAdhocMetric = new AdhocMetric({
|
|
|
|
column: valueColumn,
|
|
|
|
aggregate: AGGREGATES.SUM,
|
|
|
|
label: 'SUM(value)',
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('MetricsControl', () => {
|
|
|
|
it('renders an OnPasteSelect', () => {
|
|
|
|
const { wrapper } = setup();
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(OnPasteSelect)).toExist();
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('constructor', () => {
|
|
|
|
it('unifies options for the dropdown select with aggregates', () => {
|
|
|
|
const { wrapper } = setup();
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(wrapper.state('options')).toEqual([
|
2019-11-27 17:02:48 -05:00
|
|
|
{
|
|
|
|
optionName: '_col_source',
|
|
|
|
type: 'VARCHAR(255)',
|
|
|
|
column_name: 'source',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
optionName: '_col_target',
|
|
|
|
type: 'VARCHAR(255)',
|
|
|
|
column_name: 'target',
|
|
|
|
},
|
2018-03-28 20:41:29 -04:00
|
|
|
{ optionName: '_col_value', type: 'DOUBLE', column_name: 'value' },
|
2019-11-27 17:02:48 -05:00
|
|
|
...Object.keys(AGGREGATES).map(aggregate => ({
|
|
|
|
aggregate_name: aggregate,
|
2020-07-16 22:13:59 -04:00
|
|
|
optionName: `_aggregate_${aggregate}`,
|
2019-11-27 17:02:48 -05:00
|
|
|
})),
|
|
|
|
{
|
|
|
|
optionName: 'sum__value',
|
|
|
|
metric_name: 'sum__value',
|
|
|
|
expression: 'SUM(energy_usage.value)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
optionName: 'avg__value',
|
|
|
|
metric_name: 'avg__value',
|
|
|
|
expression: 'AVG(energy_usage.value)',
|
|
|
|
},
|
2018-03-28 20:41:29 -04:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2019-05-24 14:10:35 -04:00
|
|
|
it('does not show aggregates in options if no columns', () => {
|
|
|
|
const { wrapper } = setup({ columns: [] });
|
|
|
|
expect(wrapper.state('options')).toEqual([
|
2019-11-27 17:02:48 -05:00
|
|
|
{
|
|
|
|
optionName: 'sum__value',
|
|
|
|
metric_name: 'sum__value',
|
|
|
|
expression: 'SUM(energy_usage.value)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
optionName: 'avg__value',
|
|
|
|
metric_name: 'avg__value',
|
|
|
|
expression: 'AVG(energy_usage.value)',
|
|
|
|
},
|
2019-05-24 14:10:35 -04:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2018-03-28 20:41:29 -04:00
|
|
|
it('coerces Adhoc Metrics from form data into instances of the AdhocMetric class and leaves saved metrics', () => {
|
|
|
|
const { wrapper } = setup({
|
|
|
|
value: [
|
|
|
|
{
|
2018-04-13 14:20:53 -04:00
|
|
|
expressionType: EXPRESSION_TYPES.SIMPLE,
|
2018-03-28 20:41:29 -04:00
|
|
|
column: { type: 'double', column_name: 'value' },
|
|
|
|
aggregate: AGGREGATES.SUM,
|
|
|
|
label: 'SUM(value)',
|
|
|
|
optionName: 'blahblahblah',
|
|
|
|
},
|
|
|
|
'avg__value',
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const adhocMetric = wrapper.state('value')[0];
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(adhocMetric instanceof AdhocMetric).toBe(true);
|
|
|
|
expect(adhocMetric.optionName.length).toBeGreaterThan(10);
|
|
|
|
expect(wrapper.state('value')).toEqual([
|
2018-03-28 20:41:29 -04:00
|
|
|
{
|
2018-04-13 14:20:53 -04:00
|
|
|
expressionType: EXPRESSION_TYPES.SIMPLE,
|
2018-03-28 20:41:29 -04:00
|
|
|
column: { type: 'double', column_name: 'value' },
|
|
|
|
aggregate: AGGREGATES.SUM,
|
|
|
|
label: 'SUM(value)',
|
|
|
|
hasCustomLabel: false,
|
|
|
|
optionName: 'blahblahblah',
|
2018-04-13 14:20:53 -04:00
|
|
|
sqlExpression: null,
|
2020-05-19 19:59:49 -04:00
|
|
|
isNew: false,
|
2018-03-28 20:41:29 -04:00
|
|
|
},
|
|
|
|
'avg__value',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onChange', () => {
|
|
|
|
it('handles saved metrics being selected', () => {
|
|
|
|
const { wrapper, onChange } = setup();
|
|
|
|
const select = wrapper.find(OnPasteSelect);
|
|
|
|
select.simulate('change', [{ metric_name: 'sum__value' }]);
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(onChange.lastCall.args).toEqual([['sum__value']]);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles columns being selected', () => {
|
|
|
|
const { wrapper, onChange } = setup();
|
|
|
|
const select = wrapper.find(OnPasteSelect);
|
|
|
|
select.simulate('change', [valueColumn]);
|
|
|
|
|
|
|
|
const adhocMetric = onChange.lastCall.args[0][0];
|
2020-05-19 19:59:49 -04:00
|
|
|
expect(adhocMetric).toBeInstanceOf(AdhocMetric);
|
|
|
|
expect(adhocMetric.isNew).toBe(true);
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(onChange.lastCall.args).toEqual([
|
|
|
|
[
|
|
|
|
{
|
|
|
|
expressionType: EXPRESSION_TYPES.SIMPLE,
|
|
|
|
column: valueColumn,
|
|
|
|
aggregate: AGGREGATES.SUM,
|
|
|
|
label: 'SUM(value)',
|
|
|
|
hasCustomLabel: false,
|
|
|
|
optionName: adhocMetric.optionName,
|
|
|
|
sqlExpression: null,
|
2020-05-19 19:59:49 -04:00
|
|
|
isNew: true,
|
2019-11-27 17:02:48 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
]);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
|
2020-06-29 00:37:04 -04:00
|
|
|
it('handles aggregates being selected', () => {
|
|
|
|
return new Promise(done => {
|
|
|
|
const { wrapper, onChange } = setup();
|
|
|
|
const select = wrapper.find(OnPasteSelect);
|
|
|
|
|
|
|
|
// mock out the Select ref
|
|
|
|
const instance = wrapper.instance();
|
|
|
|
const handleInputChangeSpy = jest.fn();
|
|
|
|
const focusInputSpy = jest.fn();
|
|
|
|
// simulate react-select StateManager
|
|
|
|
instance.selectRef({
|
|
|
|
select: {
|
|
|
|
handleInputChange: handleInputChangeSpy,
|
|
|
|
inputRef: { value: '' },
|
|
|
|
focusInput: focusInputSpy,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
select.simulate('change', [
|
|
|
|
{ aggregate_name: 'SUM', optionName: 'SUM' },
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(instance.select.inputRef.value).toBe('SUM()');
|
|
|
|
expect(handleInputChangeSpy).toHaveBeenCalledWith({
|
|
|
|
currentTarget: { value: 'SUM()' },
|
|
|
|
});
|
|
|
|
expect(onChange.calledOnceWith([])).toBe(true);
|
|
|
|
expect(focusInputSpy).toHaveBeenCalledTimes(0);
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(focusInputSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expect(instance.select.inputRef.selectionStart).toBe(4);
|
|
|
|
expect(instance.select.inputRef.selectionEnd).toBe(4);
|
|
|
|
done();
|
|
|
|
});
|
2020-05-19 19:59:49 -04:00
|
|
|
});
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('preserves existing selected AdhocMetrics', () => {
|
|
|
|
const { wrapper, onChange } = setup();
|
|
|
|
const select = wrapper.find(OnPasteSelect);
|
2019-11-27 17:02:48 -05:00
|
|
|
select.simulate('change', [
|
|
|
|
{ metric_name: 'sum__value' },
|
|
|
|
sumValueAdhocMetric,
|
|
|
|
]);
|
|
|
|
expect(onChange.lastCall.args).toEqual([
|
|
|
|
['sum__value', sumValueAdhocMetric],
|
|
|
|
]);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onMetricEdit', () => {
|
|
|
|
it('accepts an edited metric from an AdhocMetricEditPopover', () => {
|
|
|
|
const { wrapper, onChange } = setup({
|
|
|
|
value: [sumValueAdhocMetric],
|
|
|
|
});
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
const editedMetric = sumValueAdhocMetric.duplicateWith({
|
|
|
|
aggregate: AGGREGATES.AVG,
|
|
|
|
});
|
2018-03-28 20:41:29 -04:00
|
|
|
wrapper.instance().onMetricEdit(editedMetric);
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(onChange.lastCall.args).toEqual([[editedMetric]]);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkIfAggregateInInput', () => {
|
|
|
|
it('handles an aggregate in the input', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(wrapper.state('aggregateInInput')).toBeNull();
|
2018-03-28 20:41:29 -04:00
|
|
|
wrapper.instance().checkIfAggregateInInput('AVG(');
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(wrapper.state('aggregateInInput')).toBe(AGGREGATES.AVG);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles no aggregate in the input', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(wrapper.state('aggregateInInput')).toBeNull();
|
2018-03-28 20:41:29 -04:00
|
|
|
wrapper.instance().checkIfAggregateInInput('colu');
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(wrapper.state('aggregateInInput')).toBeNull();
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('option filter', () => {
|
|
|
|
it('includes user defined metrics', () => {
|
2018-04-02 19:08:25 -04:00
|
|
|
const { wrapper } = setup({ datasourceType: 'druid' });
|
2018-03-28 20:41:29 -04:00
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
|
|
|
!!wrapper.instance().selectFilterOption(
|
|
|
|
{
|
2020-05-19 19:59:49 -04:00
|
|
|
data: {
|
|
|
|
metric_name: 'a_metric',
|
|
|
|
optionName: 'a_metric',
|
|
|
|
expression: 'SUM(FANCY(metric))',
|
|
|
|
},
|
2019-11-27 17:02:48 -05:00
|
|
|
},
|
|
|
|
'a',
|
|
|
|
),
|
|
|
|
).toBe(true);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
|
2018-04-02 19:08:25 -04:00
|
|
|
it('includes auto generated avg metrics for druid', () => {
|
|
|
|
const { wrapper } = setup({ datasourceType: 'druid' });
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
|
|
|
!!wrapper.instance().selectFilterOption(
|
|
|
|
{
|
2020-05-19 19:59:49 -04:00
|
|
|
data: {
|
|
|
|
metric_name: 'avg__metric',
|
|
|
|
optionName: 'avg__metric',
|
|
|
|
expression: 'AVG(metric)',
|
|
|
|
},
|
2019-11-27 17:02:48 -05:00
|
|
|
},
|
|
|
|
'a',
|
|
|
|
),
|
|
|
|
).toBe(true);
|
2018-04-02 19:08:25 -04:00
|
|
|
});
|
|
|
|
|
2018-03-28 20:41:29 -04:00
|
|
|
it('includes columns and aggregates', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
|
|
|
!!wrapper.instance().selectFilterOption(
|
|
|
|
{
|
2020-05-19 19:59:49 -04:00
|
|
|
data: {
|
|
|
|
type: 'VARCHAR(255)',
|
|
|
|
column_name: 'source',
|
|
|
|
optionName: '_col_source',
|
|
|
|
},
|
2019-11-27 17:02:48 -05:00
|
|
|
},
|
|
|
|
'sou',
|
|
|
|
),
|
|
|
|
).toBe(true);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
!!wrapper
|
|
|
|
.instance()
|
|
|
|
.selectFilterOption(
|
2020-05-19 19:59:49 -04:00
|
|
|
{ data: { aggregate_name: 'AVG', optionName: '_aggregate_AVG' } },
|
2019-11-27 17:02:48 -05:00
|
|
|
'av',
|
|
|
|
),
|
|
|
|
).toBe(true);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
|
2018-06-15 18:56:05 -04:00
|
|
|
it('includes columns based on verbose_name', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
|
|
|
!!wrapper.instance().selectFilterOption(
|
|
|
|
{
|
2020-05-19 19:59:49 -04:00
|
|
|
data: {
|
|
|
|
metric_name: 'sum__num',
|
|
|
|
verbose_name: 'babies',
|
|
|
|
optionName: '_col_sum_num',
|
|
|
|
},
|
2019-11-27 17:02:48 -05:00
|
|
|
},
|
|
|
|
'bab',
|
|
|
|
),
|
|
|
|
).toBe(true);
|
2018-06-15 18:56:05 -04:00
|
|
|
});
|
|
|
|
|
2018-04-02 19:08:25 -04:00
|
|
|
it('excludes auto generated avg metrics for sqla', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
|
|
|
!!wrapper.instance().selectFilterOption(
|
|
|
|
{
|
2020-05-19 19:59:49 -04:00
|
|
|
data: {
|
|
|
|
metric_name: 'avg__metric',
|
|
|
|
optionName: 'avg__metric',
|
|
|
|
expression: 'AVG(metric)',
|
|
|
|
},
|
2019-11-27 17:02:48 -05:00
|
|
|
},
|
|
|
|
'a',
|
|
|
|
),
|
|
|
|
).toBe(false);
|
2018-04-02 19:08:25 -04:00
|
|
|
});
|
|
|
|
|
2018-06-01 02:34:48 -04:00
|
|
|
it('includes custom made simple saved metrics', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
|
|
|
!!wrapper.instance().selectFilterOption(
|
|
|
|
{
|
2020-05-19 19:59:49 -04:00
|
|
|
data: {
|
|
|
|
metric_name: 'my_fancy_sum_metric',
|
|
|
|
optionName: 'my_fancy_sum_metric',
|
|
|
|
expression: 'SUM(value)',
|
|
|
|
},
|
2019-11-27 17:02:48 -05:00
|
|
|
},
|
|
|
|
'sum',
|
|
|
|
),
|
|
|
|
).toBe(true);
|
2018-06-01 02:34:48 -04:00
|
|
|
});
|
|
|
|
|
2018-03-28 20:41:29 -04:00
|
|
|
it('excludes auto generated metrics', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
|
|
|
!!wrapper.instance().selectFilterOption(
|
|
|
|
{
|
2020-05-19 19:59:49 -04:00
|
|
|
data: {
|
|
|
|
metric_name: 'sum__value',
|
|
|
|
optionName: 'sum__value',
|
|
|
|
expression: 'SUM(value)',
|
|
|
|
},
|
2019-11-27 17:02:48 -05:00
|
|
|
},
|
|
|
|
'sum',
|
|
|
|
),
|
|
|
|
).toBe(false);
|
2018-05-11 18:43:52 -04:00
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
|
|
|
!!wrapper.instance().selectFilterOption(
|
|
|
|
{
|
2020-05-19 19:59:49 -04:00
|
|
|
data: {
|
|
|
|
metric_name: 'sum__value',
|
|
|
|
optionName: 'sum__value',
|
|
|
|
expression: 'SUM("table"."value")',
|
|
|
|
},
|
2019-11-27 17:02:48 -05:00
|
|
|
},
|
|
|
|
'sum',
|
|
|
|
),
|
|
|
|
).toBe(false);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('filters out metrics if the input begins with an aggregate', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
wrapper.setState({ aggregateInInput: true });
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
2020-05-19 19:59:49 -04:00
|
|
|
!!wrapper.instance().selectFilterOption(
|
|
|
|
{
|
|
|
|
data: { metric_name: 'metric', expression: 'SUM(FANCY(metric))' },
|
|
|
|
},
|
|
|
|
'SUM(',
|
|
|
|
),
|
2019-11-27 17:02:48 -05:00
|
|
|
).toBe(false);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('includes columns if the input begins with an aggregate', () => {
|
|
|
|
const { wrapper } = setup();
|
|
|
|
wrapper.setState({ aggregateInInput: true });
|
|
|
|
|
2019-11-27 17:02:48 -05:00
|
|
|
expect(
|
|
|
|
!!wrapper
|
|
|
|
.instance()
|
2020-05-19 19:59:49 -04:00
|
|
|
.selectFilterOption(
|
|
|
|
{ data: { type: 'DOUBLE', column_name: 'value' } },
|
|
|
|
'SUM(',
|
|
|
|
),
|
2019-11-27 17:02:48 -05:00
|
|
|
).toBe(true);
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
2019-07-16 19:23:12 -04:00
|
|
|
|
|
|
|
it('Removes metrics if savedMetrics changes', () => {
|
|
|
|
const { props, wrapper, onChange } = setup({
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
expressionType: EXPRESSION_TYPES.SIMPLE,
|
|
|
|
column: { type: 'double', column_name: 'value' },
|
|
|
|
aggregate: AGGREGATES.SUM,
|
|
|
|
label: 'SUM(value)',
|
|
|
|
optionName: 'blahblahblah',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
expect(wrapper.state('value')).toHaveLength(1);
|
|
|
|
|
|
|
|
wrapper.setProps({ ...props, columns: [] });
|
|
|
|
expect(onChange.lastCall.args).toEqual([[]]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Does not remove custom sql metric if savedMetrics changes', () => {
|
|
|
|
const { props, wrapper, onChange } = setup({
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
expressionType: EXPRESSION_TYPES.SQL,
|
|
|
|
sqlExpression: 'COUNT(*)',
|
|
|
|
label: 'old label',
|
|
|
|
hasCustomLabel: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
expect(wrapper.state('value')).toHaveLength(1);
|
|
|
|
|
|
|
|
wrapper.setProps({ ...props, columns: [] });
|
|
|
|
expect(onChange.calledOnce).toEqual(false);
|
|
|
|
});
|
2019-08-15 17:13:18 -04:00
|
|
|
it('Does not fail if no columns or savedMetrics are passed', () => {
|
|
|
|
const { wrapper } = setup({
|
|
|
|
savedMetrics: null,
|
|
|
|
columns: null,
|
|
|
|
});
|
|
|
|
expect(wrapper.exists('.metrics-select')).toEqual(true);
|
|
|
|
});
|
2018-03-28 20:41:29 -04:00
|
|
|
});
|
|
|
|
});
|