From ad9a35198d7f936a4d40deca5a99524a4407bda0 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Wed, 12 Dec 2018 12:57:57 +0100 Subject: [PATCH] update failing tests --- .../stackdriver/query_aggregation_ctrl.ts | 6 +- .../stackdriver/query_filter_ctrl.ts | 14 +---- .../specs/query_aggregation_ctrl.test.ts | 57 +++++++++++++++++-- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts index f5ff3ad3143..d4478c6214c 100644 --- a/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts @@ -52,6 +52,7 @@ export class StackdriverAggregationCtrl { } setAlignOptions() { + console.log('this.target.metricKind', this.target.metricKind); const alignments = getAlignmentOptionsByMetric(this.target.valueType, this.target.metricKind).map(a => ({ ...a, label: a.text, @@ -78,7 +79,7 @@ export class StackdriverAggregationCtrl { } if (this.target.aggregation.groupBys.length > 0) { - aggregations = this.aggOptions.filter(o => o.value !== 'REDUCE_NONE'); + aggregations = aggregations.filter(o => o.value !== 'REDUCE_NONE'); this.deselectAggregationOption('REDUCE_NONE'); } this.aggOptions = [ @@ -116,7 +117,8 @@ export class StackdriverAggregationCtrl { } deselectAggregationOption(notValidOptionValue: string) { - const newValue = this.aggOptions.find(o => o.value !== notValidOptionValue); + const aggregations = getAggregationOptionsByMetric(this.target.valueType, this.target.metricKind); + const newValue = aggregations.find(o => o.value !== notValidOptionValue); this.target.aggregation.crossSeriesReducer = newValue ? newValue.value : ''; } diff --git a/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts index ba96cfc5a60..74ca2c9b067 100644 --- a/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts @@ -160,23 +160,11 @@ export class StackdriverFilterCtrl { options: this.templateSrv.variables.map(v => ({ label: `$${v.name}`, value: `$${v.name}`, - description: `$${v.definition}`, + // description: `$${v.definition}`, })), }; } - insertTemplateVariables(options) { - const templateVariables = { - label: 'Template Variables', - options: this.templateSrv.variables.map(v => ({ - label: `$${v.name}`, - value: `$${v.name}`, - description: `$${v.definition}`, - })), - }; - return [templateVariables, { label: 'Metrics', options }]; - } - getMetricsList() { const metrics = this.metricDescriptors.map(m => { return { diff --git a/public/app/plugins/datasource/stackdriver/specs/query_aggregation_ctrl.test.ts b/public/app/plugins/datasource/stackdriver/specs/query_aggregation_ctrl.test.ts index 81011f5dfe0..6e83824d504 100644 --- a/public/app/plugins/datasource/stackdriver/specs/query_aggregation_ctrl.test.ts +++ b/public/app/plugins/datasource/stackdriver/specs/query_aggregation_ctrl.test.ts @@ -17,27 +17,68 @@ describe('StackdriverAggregationCtrl', () => { }, { replace: s => s, + variables: [{ name: 'someVariable1' }, { name: 'someVariable2' }], } ); }); it('should populate all aggregate options except two', () => { ctrl.setAggOptions(); - expect(ctrl.aggOptions.length).toBe(11); - expect(ctrl.aggOptions.map(o => o.value)).toEqual( + expect(ctrl.aggOptions.length).toBe(2); + const [templateVariableGroup, aggOptionsGroup] = ctrl.aggOptions; + expect(templateVariableGroup.options.length).toBe(2); + expect(aggOptionsGroup.options.length).toBe(11); + expect(aggOptionsGroup.options.map(o => o.value)).toEqual( expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE']) ); }); it('should populate all alignment options except two', () => { ctrl.setAlignOptions(); - expect(ctrl.alignOptions.length).toBe(9); - expect(ctrl.alignOptions.map(o => o.value)).toEqual( + const [templateVariableGroup, alignOptionGroup] = ctrl.aggOptions; + expect(templateVariableGroup.options.length).toBe(2); + expect(alignOptionGroup.options.length).toBe(11); + expect(alignOptionGroup.options.map(o => o.value)).toEqual( expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE']) ); }); }); + describe('and result is double and delta and no group by is used', () => { + beforeEach(async () => { + ctrl = new StackdriverAggregationCtrl( + { + $on: () => {}, + target: { + valueType: 'DOUBLE', + metricKind: 'DELTA', + aggregation: { crossSeriesReducer: '', groupBys: [] }, + }, + }, + { + replace: s => s, + variables: [{ name: 'someVariable1' }, { name: 'someVariable2' }], + } + ); + }); + + it('should populate all alignment options except four', () => { + ctrl.setAlignOptions(); + const [templateVariableGroup, alignOptionGroup] = ctrl.alignOptions; + expect(templateVariableGroup.options.length).toBe(2); + expect(alignOptionGroup.options.length).toBe(9); + expect(alignOptionGroup.options.map(o => o.value)).toEqual( + expect['not'].arrayContaining([ + 'ALIGN_NEXT_OLDER', + 'ALIGN_INTERPOLATE', + 'ALIGN_COUNT_TRUE', + 'ALIGN_COUNT_FALSE', + 'ALIGN_FRACTION_TRUE', + ]) + ); + }); + }); + describe('and result is double and gauge and a group by is used', () => { beforeEach(async () => { ctrl = new StackdriverAggregationCtrl( @@ -51,14 +92,18 @@ describe('StackdriverAggregationCtrl', () => { }, { replace: s => s, + variables: [{ name: 'someVariable1' }], } ); }); it('should populate all aggregate options except three', () => { ctrl.setAggOptions(); - expect(ctrl.aggOptions.length).toBe(10); - expect(ctrl.aggOptions.map(o => o.value)).toEqual( + const [templateVariableGroup, aggOptionsGroup] = ctrl.aggOptions; + expect(ctrl.aggOptions.length).toBe(2); + expect(templateVariableGroup.options.length).toBe(1); + expect(aggOptionsGroup.options.length).toBe(10); + expect(aggOptionsGroup.options.map(o => o.value)).toEqual( expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE', 'REDUCE_NONE']) ); });