mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Templating: Interval variable type for time intervals summarize/group by parameter, included auto option, and auto step counts option.
Closes #243
This commit is contained in:
@@ -74,6 +74,20 @@ define([
|
||||
expect(results[2]).to.be('target=asPercent(series1%2Cseries2)');
|
||||
});
|
||||
|
||||
it('should fix wrong minute interval parameters', function() {
|
||||
var results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{target: "summarize(prod.25m.count, '25m', 'sum')" }]
|
||||
});
|
||||
expect(results[0]).to.be('target=' + encodeURIComponent("summarize(prod.25m.count, '25min', 'sum')"));
|
||||
});
|
||||
|
||||
it('should fix wrong month interval parameters', function() {
|
||||
var results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{target: "summarize(prod.5M.count, '5M', 'sum')" }]
|
||||
});
|
||||
expect(results[0]).to.be('target=' + encodeURIComponent("summarize(prod.5M.count, '5mon', 'sum')"));
|
||||
});
|
||||
|
||||
it('should ignore empty targets', function() {
|
||||
var results = ctx.ds.buildGraphiteParams({
|
||||
targets: [{target: 'series1'}, {target: ''}]
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
define([
|
||||
'mocks/dashboard-mock',
|
||||
'./helpers',
|
||||
'moment',
|
||||
'services/templateValuesSrv'
|
||||
], function(dashboardMock, helpers) {
|
||||
], function(dashboardMock, helpers, moment) {
|
||||
'use strict';
|
||||
|
||||
describe('templateValuesSrv', function() {
|
||||
@@ -12,7 +13,7 @@ define([
|
||||
beforeEach(ctx.providePhase(['datasourceSrv', 'timeSrv', 'templateSrv']));
|
||||
beforeEach(ctx.createService('templateValuesSrv'));
|
||||
|
||||
describe('update time period variable options', function() {
|
||||
describe('update interval variable options', function() {
|
||||
var variable = { type: 'interval', query: 'auto,1s,2h,5h,1d', name: 'test' };
|
||||
|
||||
beforeEach(function() {
|
||||
@@ -47,15 +48,41 @@ define([
|
||||
});
|
||||
}
|
||||
|
||||
describeUpdateVariable('time period variable ', function(scenario) {
|
||||
describeUpdateVariable('interval variable without auto', function(scenario) {
|
||||
scenario.setup(function() {
|
||||
scenario.variable = { type: 'interval', query: 'auto,1s,2h,5h,1d', name: 'test' };
|
||||
scenario.variable = { type: 'interval', query: '1s,2h,5h,1d', name: 'test' };
|
||||
});
|
||||
|
||||
it('should update options array', function() {
|
||||
expect(scenario.variable.options.length).to.be(4);
|
||||
expect(scenario.variable.options[0].text).to.be('1s');
|
||||
expect(scenario.variable.options[0].value).to.be('1s');
|
||||
});
|
||||
});
|
||||
|
||||
describeUpdateVariable('interval variable with auto', function(scenario) {
|
||||
scenario.setup(function() {
|
||||
scenario.variable = { type: 'interval', query: '1s,2h,5h,1d', name: 'test', auto: true, auto_count: 10 };
|
||||
|
||||
var range = {
|
||||
from: moment(new Date()).subtract(7, 'days').toDate(),
|
||||
to: new Date()
|
||||
};
|
||||
|
||||
ctx.timeSrv.timeRange = sinon.stub().returns(range);
|
||||
ctx.templateSrv.setGrafanaVariable = sinon.spy();
|
||||
});
|
||||
|
||||
it('should update options array', function() {
|
||||
expect(scenario.variable.options.length).to.be(5);
|
||||
expect(scenario.variable.options[1].text).to.be('1s');
|
||||
expect(scenario.variable.options[1].value).to.be('1s');
|
||||
expect(scenario.variable.options[0].text).to.be('auto');
|
||||
expect(scenario.variable.options[0].value).to.be('$__auto_interval');
|
||||
});
|
||||
|
||||
it('should set $__auto_interval', function() {
|
||||
var call = ctx.templateSrv.setGrafanaVariable.getCall(0);
|
||||
expect(call.args[0]).to.be('$__auto_interval');
|
||||
expect(call.args[1]).to.be('12h');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user