Commit 599fe499 by Torkel Ödegaard

fix(templating): fix to datasource variable, was not updated on dashboard load,…

fix(templating): fix to datasource variable, was not updated on dashboard load, added unit test for case as well
parent 68370ba2
...@@ -10,6 +10,7 @@ export class DatasourceVariable implements Variable { ...@@ -10,6 +10,7 @@ export class DatasourceVariable implements Variable {
query: string; query: string;
options: any; options: any;
current: any; current: any;
refresh: any;
defaults = { defaults = {
type: 'datasource', type: 'datasource',
...@@ -20,11 +21,13 @@ export class DatasourceVariable implements Variable { ...@@ -20,11 +21,13 @@ export class DatasourceVariable implements Variable {
regex: '', regex: '',
options: [], options: [],
query: '', query: '',
refresh: 1,
}; };
/** @ngInject **/ /** @ngInject **/
constructor(private model, private datasourceSrv, private variableSrv) { constructor(private model, private datasourceSrv, private variableSrv) {
assignModelProperties(this, model, this.defaults); assignModelProperties(this, model, this.defaults);
this.refresh = 1;
} }
getModel() { getModel() {
......
...@@ -62,6 +62,7 @@ describe('VariableSrv init', function() { ...@@ -62,6 +62,7 @@ describe('VariableSrv init', function() {
options: [{text: "test", value: "test"}] options: [{text: "test", value: "test"}]
}]; }];
scenario.urlParams["var-apps"] = "new"; scenario.urlParams["var-apps"] = "new";
scenario.metricSources = [];
}); });
it('should update current value', () => { it('should update current value', () => {
...@@ -110,6 +111,30 @@ describe('VariableSrv init', function() { ...@@ -110,6 +111,30 @@ describe('VariableSrv init', function() {
}); });
}); });
describeInitScenario('when datasource variable is initialized', scenario => {
scenario.setup(() => {
scenario.variables = [{
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 update current value', function() {
var variable = ctx.variableSrv.variables[0];
expect(variable.options.length).to.be(2);
});
});
describeInitScenario('when template variable is present in url multiple times', scenario => { describeInitScenario('when template variable is present in url multiple times', scenario => {
scenario.setup(() => { scenario.setup(() => {
scenario.variables = [{ scenario.variables = [{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment