diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.test.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.test.ts index 5aa07b67f62..34dcd0db280 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.test.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.test.ts @@ -1,3 +1,4 @@ +import { defaultBucketAgg } from 'app/plugins/datasource/elasticsearch/query_def'; import { reducerTester } from 'test/core/redux/reducerTester'; import { changeMetricType } from '../../MetricAggregationsEditor/state/actions'; import { BucketAggregation, DateHistogram } from '../aggregations'; @@ -10,6 +11,7 @@ import { removeBucketAggregation, } from './actions'; import { reducer } from './reducer'; +import { initQuery } from '../../state'; describe('Bucket Aggregations Reducer', () => { it('Should correctly add new aggregations', () => { @@ -140,4 +142,11 @@ describe('Bucket Aggregations Reducer', () => { ) .thenStateShouldEqual([{ ...firstAggregation, settings: expectedSettings }, secondAggregation]); }); + + it('Should correctly initialize first Bucket Aggregation', () => { + reducerTester() + .givenReducer(reducer, []) + .whenActionIsDispatched(initQuery()) + .thenStateShouldEqual([defaultBucketAgg('2')]); + }); }); diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts index db2b17473ff..458e66568ed 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/BucketAggregationsEditor/state/reducer.ts @@ -102,7 +102,7 @@ export const reducer = ( }); case INIT: - return [defaultBucketAgg()]; + return [defaultBucketAgg('2')]; default: return state; diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.test.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.test.ts index fa2701c1466..70872c96808 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.test.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.test.ts @@ -13,6 +13,7 @@ import { import { Derivative, ExtendedStats, MetricAggregation } from '../aggregations'; import { defaultMetricAgg } from '../../../../query_def'; import { metricAggregationConfig } from '../utils'; +import { initQuery } from '../../state'; describe('Metric Aggregations Reducer', () => { it('should correctly add new aggregations', () => { @@ -219,4 +220,11 @@ describe('Metric Aggregations Reducer', () => { .whenActionIsDispatched({ type: 'THIS ACTION SHOULD NOT HAVE ANY EFFECT IN THIS REDUCER' }) .thenStateShouldEqual(initialState); }); + + it('Should correctly initialize first Metric Aggregation', () => { + reducerTester() + .givenReducer(reducer, []) + .whenActionIsDispatched(initQuery()) + .thenStateShouldEqual([defaultMetricAgg('1')]); + }); }); diff --git a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.ts b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.ts index d6ce9d1f77f..760bb171cab 100644 --- a/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.ts +++ b/public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/state/reducer.ts @@ -141,7 +141,7 @@ export const reducer = ( }); case INIT: - return [defaultMetricAgg()]; + return [defaultMetricAgg('1')]; default: return state;