Avoid removing custom sql adhoc metric when columns change (#7877)

* Avoid removing custom sql adhoc metric when columns change

* Add tests to confirm sql metric does not get removed
This commit is contained in:
michellethomas
2019-07-16 16:23:12 -07:00
committed by GitHub
parent a36c136f4a
commit 86fdceb236
2 changed files with 36 additions and 1 deletions

View File

@@ -333,5 +333,40 @@ describe('MetricsControl', () => {
'SUM(',
)).toBe(true);
});
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);
});
});
});