mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
continued large refactoring of filterSrv, timeSrv and templating
This commit is contained in:
@@ -5,9 +5,6 @@ define([],
|
||||
return {
|
||||
create: function() {
|
||||
return {
|
||||
emit_refresh: function() {},
|
||||
set_interval: function(value) { this.refresh = value; },
|
||||
|
||||
title: "",
|
||||
tags: [],
|
||||
style: "dark",
|
||||
@@ -18,11 +15,11 @@ define([],
|
||||
rows: [],
|
||||
pulldowns: [ { type: 'templating' }, { type: 'annotations' } ],
|
||||
nav: [ { type: 'timepicker' } ],
|
||||
time: {},
|
||||
time: {from: '1h', to: 'now'},
|
||||
templating: {
|
||||
list: []
|
||||
},
|
||||
refresh: true
|
||||
refresh: '10s',
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@ define([
|
||||
};
|
||||
};
|
||||
|
||||
this.applyTemplateToTarget = function(target) {
|
||||
this.replace = function(target) {
|
||||
return target;
|
||||
};
|
||||
}
|
||||
|
||||
55
src/test/specs/templateSrv-specs.js
Normal file
55
src/test/specs/templateSrv-specs.js
Normal file
@@ -0,0 +1,55 @@
|
||||
define([
|
||||
'mocks/dashboard-mock',
|
||||
'lodash',
|
||||
'services/templateSrv'
|
||||
], function(dashboardMock) {
|
||||
'use strict';
|
||||
|
||||
describe('templateSrv', function() {
|
||||
var _templateSrv;
|
||||
var _dashboard;
|
||||
|
||||
beforeEach(module('grafana.services'));
|
||||
beforeEach(module(function() {
|
||||
_dashboard = dashboardMock.create();
|
||||
}));
|
||||
|
||||
beforeEach(inject(function(templateSrv) {
|
||||
_templateSrv = templateSrv;
|
||||
}));
|
||||
|
||||
beforeEach(function() {
|
||||
_templateSrv.init(_dashboard);
|
||||
});
|
||||
|
||||
describe('init', function() {
|
||||
beforeEach(function() {
|
||||
_templateSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } });
|
||||
});
|
||||
|
||||
it('should initialize template data', function() {
|
||||
var target = _templateSrv.replace('this.[[test]].filters');
|
||||
expect(target).to.be('this.oogle.filters');
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateTemplateData', function() {
|
||||
beforeEach(function() {
|
||||
_templateSrv.addTemplateParameter({
|
||||
name: 'test',
|
||||
value: 'muuu',
|
||||
current: { value: 'muuuu' }
|
||||
});
|
||||
|
||||
_templateSrv.updateTemplateData();
|
||||
});
|
||||
|
||||
it('should set current value and update template data', function() {
|
||||
var target = _templateSrv.replace('this.[[test]].filters');
|
||||
expect(target).to.be('this.muuuu.filters');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -10,45 +10,15 @@ define([
|
||||
var _dashboard;
|
||||
|
||||
beforeEach(module('grafana.services'));
|
||||
beforeEach(module(function() {
|
||||
_dashboard = dashboardMock.create();
|
||||
}));
|
||||
|
||||
beforeEach(inject(function(timeSrv) {
|
||||
_timeSrv = timeSrv;
|
||||
_dashboard = dashboardMock.create();
|
||||
}));
|
||||
|
||||
beforeEach(function() {
|
||||
_timeSrv.init(_dashboard);
|
||||
});
|
||||
|
||||
describe('init', function() {
|
||||
beforeEach(function() {
|
||||
_timeSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } });
|
||||
});
|
||||
|
||||
it('should initialize template data', function() {
|
||||
var target = _timeSrv.applyTemplateToTarget('this.[[test]].filters');
|
||||
expect(target).to.be('this.oogle.filters');
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateTemplateData', function() {
|
||||
beforeEach(function() {
|
||||
_timeSrv.addTemplateParameter({
|
||||
name: 'test',
|
||||
value: 'muuu',
|
||||
current: { value: 'muuuu' }
|
||||
});
|
||||
|
||||
_timeSrv.updateTemplateData();
|
||||
});
|
||||
it('should set current value and update template data', function() {
|
||||
var target = _timeSrv.applyTemplateToTarget('this.[[test]].filters');
|
||||
expect(target).to.be('this.muuuu.filters');
|
||||
});
|
||||
});
|
||||
|
||||
describe('timeRange', function() {
|
||||
it('should return unparsed when parse is false', function() {
|
||||
_timeSrv.setTime({from: 'now', to: 'now-1h' });
|
||||
@@ -67,18 +37,18 @@ define([
|
||||
|
||||
describe('setTime', function() {
|
||||
it('should return disable refresh for absolute times', function() {
|
||||
_dashboard.refresh = true;
|
||||
_dashboard.refresh = false;
|
||||
|
||||
_timeSrv.setTime({from: '2011-01-01', to: '2015-01-01' });
|
||||
expect(_dashboard.refresh).to.be(false);
|
||||
});
|
||||
|
||||
it('should restore refresh after relative time range is set', function() {
|
||||
_dashboard.refresh = true;
|
||||
_dashboard.refresh = '10s';
|
||||
_timeSrv.setTime({from: '2011-01-01', to: '2015-01-01' });
|
||||
expect(_dashboard.refresh).to.be(false);
|
||||
_timeSrv.setTime({from: '2011-01-01', to: 'now' });
|
||||
expect(_dashboard.refresh).to.be(true);
|
||||
expect(_dashboard.refresh).to.be('10s');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ require([
|
||||
'specs/grafanaGraph-specs',
|
||||
'specs/seriesOverridesCtrl-specs',
|
||||
'specs/timeSrv-specs',
|
||||
'specs/templateSrv-specs',
|
||||
'specs/kbn-format-specs',
|
||||
'specs/dashboardSrv-specs',
|
||||
'specs/dashboardViewStateSrv-specs',
|
||||
|
||||
Reference in New Issue
Block a user