|
|
@@ -1,134 +1,114 @@
|
|
|
-define([
|
|
|
- '../mocks/dashboard-mock',
|
|
|
- './helpers',
|
|
|
- 'moment',
|
|
|
- 'app/features/templating/templateValuesSrv'
|
|
|
-], function(dashboardMock, helpers, moment) {
|
|
|
- 'use strict';
|
|
|
-
|
|
|
- describe('templateValuesSrv', function() {
|
|
|
- var ctx = new helpers.ServiceTestContext();
|
|
|
-
|
|
|
- beforeEach(module('grafana.services'));
|
|
|
- beforeEach(ctx.providePhase(['datasourceSrv', 'timeSrv', 'templateSrv', '$location']));
|
|
|
- beforeEach(ctx.createService('templateValuesSrv'));
|
|
|
-
|
|
|
- describe('update interval variable options', function() {
|
|
|
- var variable = { type: 'interval', query: 'auto,1s,2h,5h,1d', name: 'test' };
|
|
|
-
|
|
|
- beforeEach(function() {
|
|
|
- ctx.service.updateOptions(variable);
|
|
|
- });
|
|
|
-
|
|
|
- it('should update options array', function() {
|
|
|
- expect(variable.options.length).to.be(5);
|
|
|
- expect(variable.options[1].text).to.be('1s');
|
|
|
- expect(variable.options[1].value).to.be('1s');
|
|
|
- });
|
|
|
+import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
|
|
|
+
|
|
|
+import '../all';
|
|
|
+
|
|
|
+import moment from 'moment';
|
|
|
+import helpers from 'test/specs/helpers';
|
|
|
+import {Emitter} from 'app/core/core';
|
|
|
+
|
|
|
+describe('VariableSrv', function() {
|
|
|
+ var ctx = new helpers.ControllerTestContext();
|
|
|
+
|
|
|
+ beforeEach(angularMocks.module('grafana.core'));
|
|
|
+ beforeEach(angularMocks.module('grafana.controllers'));
|
|
|
+ beforeEach(angularMocks.module('grafana.services'));
|
|
|
+
|
|
|
+ beforeEach(ctx.providePhase(['datasourceSrv', 'timeSrv', 'templateSrv', '$location']));
|
|
|
+ beforeEach(angularMocks.inject(($rootScope, $q, $location, $injector) => {
|
|
|
+ ctx.$q = $q;
|
|
|
+ ctx.$rootScope = $rootScope;
|
|
|
+ ctx.$location = $location;
|
|
|
+ ctx.variableSrv = $injector.get('variableSrv');
|
|
|
+ ctx.variableSrv.init({
|
|
|
+ templating: {list: []},
|
|
|
+ events: new Emitter(),
|
|
|
});
|
|
|
-
|
|
|
- describe('when template variable is present in url', function() {
|
|
|
- var variable = {
|
|
|
- name: 'apps',
|
|
|
- current: {text: "test", value: "test"},
|
|
|
- options: [{text: "test", value: "test"}]
|
|
|
+ ctx.$rootScope.$digest();
|
|
|
+ }));
|
|
|
+
|
|
|
+ function describeUpdateVariable(desc, fn) {
|
|
|
+ describe(desc, function() {
|
|
|
+ var scenario: any = {};
|
|
|
+ scenario.setup = function(setupFn) {
|
|
|
+ scenario.setupFn = setupFn;
|
|
|
};
|
|
|
|
|
|
- beforeEach(function(done) {
|
|
|
- var dashboard = { templating: { list: [variable] } };
|
|
|
- var urlParams = {};
|
|
|
- urlParams["var-apps"] = "new";
|
|
|
- ctx.$location.search = sinon.stub().returns(urlParams);
|
|
|
- ctx.service.init(dashboard).then(function() { done(); });
|
|
|
- ctx.$rootScope.$digest();
|
|
|
- });
|
|
|
-
|
|
|
- it('should update current value', function() {
|
|
|
- expect(variable.current.value).to.be("new");
|
|
|
- expect(variable.current.text).to.be("new");
|
|
|
- });
|
|
|
- });
|
|
|
+ beforeEach(function() {
|
|
|
+ scenario.setupFn();
|
|
|
+ var ds: any = {};
|
|
|
+ ds.metricFindQuery = sinon.stub().returns(ctx.$q.when(scenario.queryResult));
|
|
|
+ ctx.datasourceSrv.get = sinon.stub().returns(ctx.$q.when(ds));
|
|
|
+ ctx.datasourceSrv.getMetricSources = sinon.stub().returns(scenario.metricSources);
|
|
|
|
|
|
- describe('when template variable is present in url multiple times', function() {
|
|
|
- var variable = {
|
|
|
- name: 'apps',
|
|
|
- multi: true,
|
|
|
- current: {text: "val1", value: "val1"},
|
|
|
- options: [{text: "val1", value: "val1"}, {text: 'val2', value: 'val2'}, {text: 'val3', value: 'val3', selected: true}]
|
|
|
- };
|
|
|
|
|
|
- beforeEach(function(done) {
|
|
|
- var dashboard = { templating: { list: [variable] } };
|
|
|
- var urlParams = {};
|
|
|
- urlParams["var-apps"] = ["val2", "val1"];
|
|
|
- ctx.$location.search = sinon.stub().returns(urlParams);
|
|
|
- ctx.service.init(dashboard).then(function() { done(); });
|
|
|
+ scenario.variable = ctx.variableSrv.addVariable(scenario.variableModel);
|
|
|
+ ctx.variableSrv.updateOptions(scenario.variable);
|
|
|
ctx.$rootScope.$digest();
|
|
|
});
|
|
|
|
|
|
- it('should update current value', function() {
|
|
|
- expect(variable.current.value.length).to.be(2);
|
|
|
- expect(variable.current.value[0]).to.be("val2");
|
|
|
- expect(variable.current.value[1]).to.be("val1");
|
|
|
- expect(variable.current.text).to.be("val2 + val1");
|
|
|
- expect(variable.options[0].selected).to.be(true);
|
|
|
- expect(variable.options[1].selected).to.be(true);
|
|
|
- });
|
|
|
+ fn(scenario);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- it('should set options that are not in value to selected false', function() {
|
|
|
- expect(variable.options[2].selected).to.be(false);
|
|
|
- });
|
|
|
+ describeUpdateVariable('interval variable without auto', scenario => {
|
|
|
+ scenario.setup(() => {
|
|
|
+ scenario.variableModel = {type: 'interval', query: '1s,2h,5h,1d', name: 'test'};
|
|
|
});
|
|
|
|
|
|
- function describeUpdateVariable(desc, fn) {
|
|
|
- describe(desc, function() {
|
|
|
- var scenario = {};
|
|
|
- scenario.setup = function(setupFn) {
|
|
|
- scenario.setupFn = setupFn;
|
|
|
- };
|
|
|
+ it('should update options array', () => {
|
|
|
+ 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');
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
- beforeEach(function() {
|
|
|
- scenario.setupFn();
|
|
|
- var ds = {};
|
|
|
- ds.metricFindQuery = sinon.stub().returns(ctx.$q.when(scenario.queryResult));
|
|
|
- ctx.datasourceSrv.get = sinon.stub().returns(ctx.$q.when(ds));
|
|
|
- ctx.datasourceSrv.getMetricSources = sinon.stub().returns(scenario.metricSources);
|
|
|
+ //
|
|
|
+ // Interval variable update
|
|
|
+ //
|
|
|
+ describeUpdateVariable('interval variable with auto', scenario => {
|
|
|
+ scenario.setup(() => {
|
|
|
+ scenario.variableModel = {type: 'interval', query: '1s,2h,5h,1d', name: 'test', auto: true, auto_count: 10 };
|
|
|
|
|
|
- ctx.service.updateOptions(scenario.variable);
|
|
|
- ctx.$rootScope.$digest();
|
|
|
- });
|
|
|
+ var range = {
|
|
|
+ from: moment(new Date()).subtract(7, 'days').toDate(),
|
|
|
+ to: new Date()
|
|
|
+ };
|
|
|
|
|
|
- fn(scenario);
|
|
|
- });
|
|
|
- }
|
|
|
+ ctx.timeSrv.timeRange = sinon.stub().returns(range);
|
|
|
+ ctx.templateSrv.setGrafanaVariable = sinon.spy();
|
|
|
+ });
|
|
|
|
|
|
- describeUpdateVariable('interval variable without auto', function(scenario) {
|
|
|
- scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'interval', query: '1s,2h,5h,1d', name: 'test' };
|
|
|
- });
|
|
|
+ it('should update options array', function() {
|
|
|
+ expect(scenario.variable.options.length).to.be(5);
|
|
|
+ expect(scenario.variable.options[0].text).to.be('auto');
|
|
|
+ expect(scenario.variable.options[0].value).to.be('$__auto_interval');
|
|
|
+ });
|
|
|
|
|
|
- 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');
|
|
|
- });
|
|
|
+ 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');
|
|
|
});
|
|
|
+ });
|
|
|
|
|
|
- describeUpdateVariable('query variable with empty current object and refresh', function(scenario) {
|
|
|
- scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'query', query: '', name: 'test', current: {} };
|
|
|
- scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
- });
|
|
|
+ //
|
|
|
+ // Query variable update
|
|
|
+ //
|
|
|
+ describeUpdateVariable('query variable with empty current object and refresh', function(scenario) {
|
|
|
+ scenario.setup(function() {
|
|
|
+ scenario.variableModel = {type: 'query', query: '', name: 'test', current: {}};
|
|
|
+ scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
+ });
|
|
|
|
|
|
- it('should set current value to first option', function() {
|
|
|
- expect(scenario.variable.options.length).to.be(2);
|
|
|
- expect(scenario.variable.current.value).to.be('backend1');
|
|
|
- });
|
|
|
+ it('should set current value to first option', function() {
|
|
|
+ expect(scenario.variable.options.length).to.be(2);
|
|
|
+ expect(scenario.variable.current.value).to.be('backend1');
|
|
|
});
|
|
|
+ });
|
|
|
|
|
|
- describeUpdateVariable('query variable with multi select and new options does not contain some selected values', function(scenario) {
|
|
|
+ describeUpdateVariable('query variable with multi select and new options does not contain some selected values', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = {
|
|
|
+ scenario.variableModel = {
|
|
|
type: 'query',
|
|
|
query: '',
|
|
|
name: 'test',
|
|
|
@@ -148,7 +128,7 @@ define([
|
|
|
|
|
|
describeUpdateVariable('query variable with multi select and new options does not contain any selected values', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = {
|
|
|
+ scenario.variableModel = {
|
|
|
type: 'query',
|
|
|
query: '',
|
|
|
name: 'test',
|
|
|
@@ -168,7 +148,7 @@ define([
|
|
|
|
|
|
describeUpdateVariable('query variable with multi select and $__all selected', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = {
|
|
|
+ scenario.variableModel = {
|
|
|
type: 'query',
|
|
|
query: '',
|
|
|
name: 'test',
|
|
|
@@ -189,7 +169,7 @@ define([
|
|
|
|
|
|
describeUpdateVariable('query variable with numeric results', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'query', query: '', name: 'test', current: {} };
|
|
|
+ scenario.variableModel = { type: 'query', query: '', name: 'test', current: {} };
|
|
|
scenario.queryResult = [{text: 12, value: 12}];
|
|
|
});
|
|
|
|
|
|
@@ -200,65 +180,9 @@ define([
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describeUpdateVariable('interval variable without auto', function(scenario) {
|
|
|
- scenario.setup(function() {
|
|
|
- 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[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');
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- describeUpdateVariable('update custom variable', function(scenario) {
|
|
|
- scenario.setup(function() {
|
|
|
- scenario.variable = {type: 'custom', query: 'hej, hop, asd', name: 'test'};
|
|
|
- });
|
|
|
-
|
|
|
- it('should update options array', function() {
|
|
|
- expect(scenario.variable.options.length).to.be(3);
|
|
|
- expect(scenario.variable.options[0].text).to.be('hej');
|
|
|
- expect(scenario.variable.options[1].value).to.be('hop');
|
|
|
- });
|
|
|
-
|
|
|
- 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');
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
describeUpdateVariable('basic query variable', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
+ scenario.variableModel = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
});
|
|
|
|
|
|
@@ -276,8 +200,8 @@ define([
|
|
|
|
|
|
describeUpdateVariable('and existing value still exists in options', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
- scenario.variable.current = { value: 'backend2', text: 'backend2'};
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test'};
|
|
|
+ scenario.variableModel.current = { value: 'backend2', text: 'backend2'};
|
|
|
scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
});
|
|
|
|
|
|
@@ -288,8 +212,8 @@ define([
|
|
|
|
|
|
describeUpdateVariable('and regex pattern exists', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
- scenario.variable.regex = '/apps.*(backend_[0-9]+)/';
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test'};
|
|
|
+ scenario.variableModel.regex = '/apps.*(backend_[0-9]+)/';
|
|
|
scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
|
|
});
|
|
|
|
|
|
@@ -300,8 +224,8 @@ define([
|
|
|
|
|
|
describeUpdateVariable('and regex pattern exists and no match', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
- scenario.variable.regex = '/apps.*(backendasd[0-9]+)/';
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test'};
|
|
|
+ scenario.variableModel.regex = '/apps.*(backendasd[0-9]+)/';
|
|
|
scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
|
|
});
|
|
|
|
|
|
@@ -313,8 +237,8 @@ define([
|
|
|
|
|
|
describeUpdateVariable('regex pattern without slashes', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
- scenario.variable.regex = 'backend_01';
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test'};
|
|
|
+ scenario.variableModel.regex = 'backend_01';
|
|
|
scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
|
|
});
|
|
|
|
|
|
@@ -325,8 +249,8 @@ define([
|
|
|
|
|
|
describeUpdateVariable('regex pattern remove duplicates', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
- scenario.variable.regex = 'backend_01';
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test'};
|
|
|
+ scenario.variableModel.regex = '/backend_01/';
|
|
|
scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_01.counters.req'}];
|
|
|
});
|
|
|
|
|
|
@@ -337,7 +261,7 @@ define([
|
|
|
|
|
|
describeUpdateVariable('with include All', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = {type: 'query', query: 'apps.*', name: 'test', includeAll: true};
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test', includeAll: true};
|
|
|
scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
});
|
|
|
|
|
|
@@ -349,7 +273,7 @@ define([
|
|
|
|
|
|
describeUpdateVariable('with include all and custom value', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allValue: '*' };
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test', includeAll: true, allValue: '*'};
|
|
|
scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
});
|
|
|
|
|
|
@@ -358,37 +282,9 @@ define([
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describeUpdateVariable('datasource variable with regex filter', function(scenario) {
|
|
|
- scenario.setup(function() {
|
|
|
- scenario.variable = {
|
|
|
- type: 'datasource',
|
|
|
- query: 'graphite',
|
|
|
- name: 'test',
|
|
|
- current: {value: 'backend4_pee', text: 'backend4_pee'},
|
|
|
- regex: '/pee$/'
|
|
|
- };
|
|
|
- scenario.metricSources = [
|
|
|
- {name: 'backend1', meta: {id: 'influx'}},
|
|
|
- {name: 'backend2_pee', meta: {id: 'graphite'}},
|
|
|
- {name: 'backend3', meta: {id: 'graphite'}},
|
|
|
- {name: 'backend4_pee', meta: {id: 'graphite'}},
|
|
|
- ];
|
|
|
- });
|
|
|
-
|
|
|
- it('should set only contain graphite ds and filtered using regex', function() {
|
|
|
- expect(scenario.variable.options.length).to.be(2);
|
|
|
- expect(scenario.variable.options[0].value).to.be('backend2_pee');
|
|
|
- expect(scenario.variable.options[1].value).to.be('backend4_pee');
|
|
|
- });
|
|
|
-
|
|
|
- it('should keep current value if available', function() {
|
|
|
- expect(scenario.variable.current.value).to.be('backend4_pee');
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
describeUpdateVariable('without sort', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = {type: 'query', query: 'apps.*', name: 'test', sort: 0};
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test', sort: 0};
|
|
|
scenario.queryResult = [{text: 'bbb2'}, {text: 'aaa10'}, { text: 'ccc3'}];
|
|
|
});
|
|
|
|
|
|
@@ -401,7 +297,7 @@ define([
|
|
|
|
|
|
describeUpdateVariable('with alphabetical sort (asc)', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = {type: 'query', query: 'apps.*', name: 'test', sort: 1};
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test', sort: 1};
|
|
|
scenario.queryResult = [{text: 'bbb2'}, {text: 'aaa10'}, { text: 'ccc3'}];
|
|
|
});
|
|
|
|
|
|
@@ -414,7 +310,7 @@ define([
|
|
|
|
|
|
describeUpdateVariable('with alphabetical sort (desc)', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = {type: 'query', query: 'apps.*', name: 'test', sort: 2};
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test', sort: 2};
|
|
|
scenario.queryResult = [{text: 'bbb2'}, {text: 'aaa10'}, { text: 'ccc3'}];
|
|
|
});
|
|
|
|
|
|
@@ -427,7 +323,7 @@ define([
|
|
|
|
|
|
describeUpdateVariable('with numerical sort (asc)', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = {type: 'query', query: 'apps.*', name: 'test', sort: 3};
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test', sort: 3};
|
|
|
scenario.queryResult = [{text: 'bbb2'}, {text: 'aaa10'}, { text: 'ccc3'}];
|
|
|
});
|
|
|
|
|
|
@@ -440,7 +336,7 @@ define([
|
|
|
|
|
|
describeUpdateVariable('with numerical sort (desc)', function(scenario) {
|
|
|
scenario.setup(function() {
|
|
|
- scenario.variable = {type: 'query', query: 'apps.*', name: 'test', sort: 4};
|
|
|
+ scenario.variableModel = {type: 'query', query: 'apps.*', name: 'test', sort: 4};
|
|
|
scenario.queryResult = [{text: 'bbb2'}, {text: 'aaa10'}, { text: 'ccc3'}];
|
|
|
});
|
|
|
|
|
|
@@ -450,5 +346,50 @@ define([
|
|
|
expect(scenario.variable.options[2].text).to.be('bbb2');
|
|
|
});
|
|
|
});
|
|
|
- });
|
|
|
+
|
|
|
+ //
|
|
|
+ // datasource variable update
|
|
|
+ //
|
|
|
+ describeUpdateVariable('datasource variable with regex filter', function(scenario) {
|
|
|
+ scenario.setup(function() {
|
|
|
+ scenario.variableModel = {
|
|
|
+ type: 'datasource',
|
|
|
+ query: 'graphite',
|
|
|
+ name: 'test',
|
|
|
+ current: {value: 'backend4_pee', text: 'backend4_pee'},
|
|
|
+ regex: '/pee$/'
|
|
|
+ };
|
|
|
+ scenario.metricSources = [
|
|
|
+ {name: 'backend1', meta: {id: 'influx'}},
|
|
|
+ {name: 'backend2_pee', meta: {id: 'graphite'}},
|
|
|
+ {name: 'backend3', meta: {id: 'graphite'}},
|
|
|
+ {name: 'backend4_pee', meta: {id: 'graphite'}},
|
|
|
+ ];
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should set only contain graphite ds and filtered using regex', function() {
|
|
|
+ expect(scenario.variable.options.length).to.be(2);
|
|
|
+ expect(scenario.variable.options[0].value).to.be('backend2_pee');
|
|
|
+ expect(scenario.variable.options[1].value).to.be('backend4_pee');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should keep current value if available', function() {
|
|
|
+ expect(scenario.variable.current.value).to.be('backend4_pee');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ //
|
|
|
+ // Custom variable update
|
|
|
+ //
|
|
|
+ describeUpdateVariable('update custom variable', function(scenario) {
|
|
|
+ scenario.setup(function() {
|
|
|
+ scenario.variableModel = {type: 'custom', query: 'hej, hop, asd', name: 'test'};
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should update options array', function() {
|
|
|
+ expect(scenario.variable.options.length).to.be(3);
|
|
|
+ expect(scenario.variable.options[0].text).to.be('hej');
|
|
|
+ expect(scenario.variable.options[1].value).to.be('hop');
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|