Renamed filterSrv to timeSrv and made it a service again

This commit is contained in:
Torkel Ödegaard
2014-08-27 16:29:48 +02:00
parent bb3b31829f
commit 1929490deb
19 changed files with 89 additions and 92 deletions

View File

@@ -15,6 +15,9 @@ define([
describe(desc, function() {
var ctx = {};
ctx.setup = function (setupFunc) {
beforeEach(module(function($provide) {
$provide.value("timeSrv", new helpers.TimeSrvStub());
}));
beforeEach(inject(function($rootScope, $compile) {
var scope = $rootScope.$new();
var element = angular.element("<div style='width:500px' grafana-graph><div>");

View File

@@ -28,7 +28,7 @@ define([
});
it('should validate metric key exists', function() {
expect(ctx.scope.datasource.metricFindQuery.getCall(0).args[1]).to.be('test.prod.*');
expect(ctx.scope.datasource.metricFindQuery.getCall(0).args[0]).to.be('test.prod.*');
});
it('should delete last segment if no metrics are found', function() {

View File

@@ -8,6 +8,7 @@ define([
this.datasource = {};
this.annotationsSrv = {};
this.timeSrv = new TimeSrvStub();
this.datasourceSrv = {
getMetricSources: function() {},
get: function() { return self.datasource; }
@@ -17,6 +18,7 @@ define([
return module(function($provide) {
$provide.value('datasourceSrv', self.datasourceSrv);
$provide.value('annotationsSrv', self.annotationsSrv);
$provide.value('timeSrv', self.timeSrv);
});
};
@@ -25,7 +27,6 @@ define([
self.scope = $rootScope.$new();
self.scope.panel = {};
self.scope.row = { panels:[] };
self.scope.filter = new FilterSrvStub();
self.scope.dashboard = {};
self.scope.dashboardViewState = new DashboardViewStateStub();
@@ -50,7 +51,6 @@ define([
self.service = InfluxDatasource;
self.$q = $q;
self.$rootScope = $rootScope;
self.filterSrv = new FilterSrvStub();
self.$httpBackend = $httpBackend;
}]);
};
@@ -61,7 +61,7 @@ define([
};
}
function FilterSrvStub() {
function TimeSrvStub() {
this.time = { from:'now-1h', to: 'now'};
this.timeRange = function(parse) {
if (parse === false) {
@@ -81,7 +81,7 @@ define([
return {
ControllerTestContext: ControllerTestContext,
FilterSrvStub: FilterSrvStub,
TimeSrvStub: TimeSrvStub,
ServiceTestContext: ServiceTestContext
};

View File

@@ -29,7 +29,7 @@ define([
var ds = new ctx.service({ urls: [''], user: 'test', password: 'mupp' });
ctx.$httpBackend.expect('GET', urlExpected).respond(response);
ds.query(ctx.filterSrv, query).then(function(data) { results = data; });
ds.query(query).then(function(data) { results = data; });
ctx.$httpBackend.flush();
});
@@ -59,7 +59,7 @@ define([
var ds = new ctx.service({ urls: [''], user: 'test', password: 'mupp' });
ctx.$httpBackend.expect('GET', urlExpected).respond(response);
ds.query(ctx.filterSrv, query).then(function(data) { results = data; });
ds.query(query).then(function(data) { results = data; });
ctx.$httpBackend.flush();
});

View File

@@ -1,12 +1,12 @@
define([
'mocks/dashboard-mock',
'lodash',
'services/filterSrv'
'services/timeSrv'
], function(dashboardMock, _) {
'use strict';
describe('filterSrv', function() {
var _filterSrv;
describe('timeSrv', function() {
var _timeSrv;
var _dashboard;
beforeEach(module('grafana.services'));
@@ -14,52 +14,52 @@ define([
_dashboard = dashboardMock.create();
}));
beforeEach(inject(function(filterSrv) {
_filterSrv = filterSrv;
beforeEach(inject(function(timeSrv) {
_timeSrv = timeSrv;
}));
beforeEach(function() {
_filterSrv.init(_dashboard);
_timeSrv.init(_dashboard);
});
describe('init', function() {
beforeEach(function() {
_filterSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } });
_timeSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } });
});
it('should initialize template data', function() {
var target = _filterSrv.applyTemplateToTarget('this.[[test]].filters');
var target = _timeSrv.applyTemplateToTarget('this.[[test]].filters');
expect(target).to.be('this.oogle.filters');
});
});
describe('updateTemplateData', function() {
beforeEach(function() {
_filterSrv.addTemplateParameter({
_timeSrv.addTemplateParameter({
name: 'test',
value: 'muuu',
current: { value: 'muuuu' }
});
_filterSrv.updateTemplateData();
_timeSrv.updateTemplateData();
});
it('should set current value and update template data', function() {
var target = _filterSrv.applyTemplateToTarget('this.[[test]].filters');
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() {
_filterSrv.setTime({from: 'now', to: 'now-1h' });
var time = _filterSrv.timeRange(false);
_timeSrv.setTime({from: 'now', to: 'now-1h' });
var time = _timeSrv.timeRange(false);
expect(time.from).to.be('now');
expect(time.to).to.be('now-1h');
});
it('should return parsed when parse is true', function() {
_filterSrv.setTime({from: 'now', to: 'now-1h' });
var time = _filterSrv.timeRange(true);
_timeSrv.setTime({from: 'now', to: 'now-1h' });
var time = _timeSrv.timeRange(true);
expect(_.isDate(time.from)).to.be(true);
expect(_.isDate(time.to)).to.be(true);
});
@@ -69,15 +69,15 @@ define([
it('should return disable refresh for absolute times', function() {
_dashboard.refresh = true;
_filterSrv.setTime({from: '2011-01-01', to: '2015-01-01' });
_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;
_filterSrv.setTime({from: '2011-01-01', to: '2015-01-01' });
_timeSrv.setTime({from: '2011-01-01', to: '2015-01-01' });
expect(_dashboard.refresh).to.be(false);
_filterSrv.setTime({from: '2011-01-01', to: 'now' });
_timeSrv.setTime({from: '2011-01-01', to: 'now' });
expect(_dashboard.refresh).to.be(true);
});
});

View File

@@ -125,7 +125,7 @@ require([
'specs/graph-ctrl-specs',
'specs/grafanaGraph-specs',
'specs/seriesOverridesCtrl-specs',
'specs/filterSrv-specs',
'specs/timeSrv-specs',
'specs/kbn-format-specs',
'specs/dashboardSrv-specs',
'specs/dashboardViewStateSrv-specs',