grafana/src/test/specs/helpers.js

80 lines
2.0 KiB
JavaScript
Raw Normal View History

2014-08-07 03:42:05 -05:00
define([
'kbn'
], function(kbn) {
2014-08-07 03:42:05 -05:00
'use strict';
function ControllerTestContext() {
var self = this;
this.datasource = {};
this.annotationsSrv = {};
2014-08-07 03:42:05 -05:00
this.datasourceSrv = {
getMetricSources: function() {},
get: function() { return self.datasource; }
};
this.providePhase = function() {
return module(function($provide) {
$provide.value('datasourceSrv', self.datasourceSrv);
$provide.value('annotationsSrv', self.annotationsSrv);
2014-08-07 03:42:05 -05:00
});
};
this.createControllerPhase = function(controllerName) {
return inject(function($controller, $rootScope, $q) {
self.scope = $rootScope.$new();
self.scope.panel = {};
2014-08-08 10:33:00 -05:00
self.scope.filter = new FilterSrvStub();
$rootScope.colors = [];
for (var i = 0; i < 50; i++) { $rootScope.colors.push('#' + i); }
2014-08-07 03:42:05 -05:00
self.$q = $q;
self.scope.skipDataOnInit = true;
self.controller = $controller(controllerName, {
$scope: self.scope
});
});
};
}
2014-08-08 10:33:00 -05:00
function ServiceTestContext() {
var self = this;
this.createService = function(name) {
return inject([name, '$q', '$rootScope', '$httpBackend', function(InfluxDatasource, $q, $rootScope, $httpBackend) {
self.service = InfluxDatasource;
self.$q = $q;
self.$rootScope = $rootScope;
self.filterSrv = new FilterSrvStub();
self.$httpBackend = $httpBackend;
}]);
};
}
function FilterSrvStub() {
this.time = { from:'now-1h', to: 'now'};
this.timeRange = function(parse) {
if (!parse) {
return this.time;
}
return {
from : kbn.parseDate(this.time.from),
to : kbn.parseDate(this.time.to)
};
};
this.applyTemplateToTarget = function(target) {
return target;
};
}
2014-08-07 03:42:05 -05:00
return {
2014-08-08 10:33:00 -05:00
ControllerTestContext: ControllerTestContext,
FilterSrvStub: FilterSrvStub,
ServiceTestContext: ServiceTestContext
2014-08-07 03:42:05 -05:00
};
});