mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: unit test group by and aggregation dropdown changes
This commit is contained in:
parent
3572692fd5
commit
db8bbe3cad
@ -62,14 +62,12 @@ export class StackdriverAggregationCtrl {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!this.aggOptions.find(o => o.value === this.target.aggregation.crossSeriesReducer)) {
|
if (!this.aggOptions.find(o => o.value === this.target.aggregation.crossSeriesReducer)) {
|
||||||
const newValue = this.aggOptions.find(o => o.value !== 'REDUCE_NONE');
|
this.deselectAggregationOption('REDUCE_NONE');
|
||||||
this.target.aggregation.crossSeriesReducer = newValue ? newValue.value : '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.target.aggregation.groupBys.length > 0) {
|
if (this.target.aggregation.groupBys.length > 0) {
|
||||||
this.aggOptions = this.aggOptions.filter(o => o.value !== 'REDUCE_NONE');
|
this.aggOptions = this.aggOptions.filter(o => o.value !== 'REDUCE_NONE');
|
||||||
const newValue = this.aggOptions.find(o => o.value !== 'REDUCE_NONE');
|
this.deselectAggregationOption('REDUCE_NONE');
|
||||||
this.target.aggregation.crossSeriesReducer = newValue ? newValue.value : '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +75,11 @@ export class StackdriverAggregationCtrl {
|
|||||||
const selectedAlignment = this.alignOptions.find(ap => ap.value === this.target.aggregation.perSeriesAligner);
|
const selectedAlignment = this.alignOptions.find(ap => ap.value === this.target.aggregation.perSeriesAligner);
|
||||||
return `${kbn.secondsToHms(this.$scope.alignmentPeriod)} interval (${selectedAlignment.text})`;
|
return `${kbn.secondsToHms(this.$scope.alignmentPeriod)} interval (${selectedAlignment.text})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deselectAggregationOption(notValidOptionValue: string) {
|
||||||
|
const newValue = this.aggOptions.find(o => o.value !== notValidOptionValue);
|
||||||
|
this.target.aggregation.crossSeriesReducer = newValue ? newValue.value : '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
angular.module('grafana.controllers').directive('stackdriverAggregation', StackdriverAggregation);
|
angular.module('grafana.controllers').directive('stackdriverAggregation', StackdriverAggregation);
|
||||||
|
@ -4,11 +4,11 @@ describe('StackdriverAggregationCtrl', () => {
|
|||||||
let ctrl;
|
let ctrl;
|
||||||
describe('aggregation and alignment options', () => {
|
describe('aggregation and alignment options', () => {
|
||||||
describe('when new query result is returned from the server', () => {
|
describe('when new query result is returned from the server', () => {
|
||||||
describe('and result is double and gauge', () => {
|
describe('and result is double and gauge and no group by is used', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
ctrl = new StackdriverAggregationCtrl({
|
ctrl = new StackdriverAggregationCtrl({
|
||||||
$on: () => {},
|
$on: () => {},
|
||||||
target: { valueType: 'DOUBLE', metricKind: 'GAUGE', aggregation: { crossSeriesReducer: '' } },
|
target: { valueType: 'DOUBLE', metricKind: 'GAUGE', aggregation: { crossSeriesReducer: '', groupBys: [] } },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -28,6 +28,33 @@ describe('StackdriverAggregationCtrl', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('and result is double and gauge and a group by is used', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
ctrl = new StackdriverAggregationCtrl({
|
||||||
|
$on: () => {},
|
||||||
|
target: {
|
||||||
|
valueType: 'DOUBLE',
|
||||||
|
metricKind: 'GAUGE',
|
||||||
|
aggregation: { crossSeriesReducer: 'REDUCE_NONE', groupBys: ['resource.label.projectid'] },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should populate all aggregate options except three', () => {
|
||||||
|
ctrl.setAggOptions();
|
||||||
|
expect(ctrl.aggOptions.length).toBe(10);
|
||||||
|
expect(ctrl.aggOptions.map(o => o.value)).toEqual(
|
||||||
|
expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE', 'REDUCE_NONE'])
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should select some other reducer than REDUCE_NONE', () => {
|
||||||
|
ctrl.setAggOptions();
|
||||||
|
expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('');
|
||||||
|
expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('REDUCE_NONE');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user