2014-08-07 03:42:05 -05:00
|
|
|
define([
|
2015-09-17 04:21:38 -05:00
|
|
|
'lodash',
|
|
|
|
'app/core/utils/datemath',
|
2015-10-30 08:44:40 -05:00
|
|
|
], function(_, dateMath) {
|
2014-08-07 03:42:05 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function ControllerTestContext() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.datasource = {};
|
2014-09-30 07:42:59 -05:00
|
|
|
this.$element = {};
|
2014-08-07 11:17:26 -05:00
|
|
|
this.annotationsSrv = {};
|
2014-08-27 09:29:48 -05:00
|
|
|
this.timeSrv = new TimeSrvStub();
|
2014-08-28 09:03:13 -05:00
|
|
|
this.templateSrv = new TemplateSrvStub();
|
2014-08-07 03:42:05 -05:00
|
|
|
this.datasourceSrv = {
|
|
|
|
getMetricSources: function() {},
|
2015-02-27 15:29:00 -06:00
|
|
|
get: function() {
|
|
|
|
return {
|
|
|
|
then: function(callback) {
|
|
|
|
callback(self.datasource);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2014-08-07 03:42:05 -05:00
|
|
|
};
|
|
|
|
|
2014-09-30 07:42:59 -05:00
|
|
|
this.providePhase = function(mocks) {
|
2014-08-07 03:42:05 -05:00
|
|
|
return module(function($provide) {
|
|
|
|
$provide.value('datasourceSrv', self.datasourceSrv);
|
2014-08-07 11:17:26 -05:00
|
|
|
$provide.value('annotationsSrv', self.annotationsSrv);
|
2014-08-27 09:29:48 -05:00
|
|
|
$provide.value('timeSrv', self.timeSrv);
|
2014-08-28 09:03:13 -05:00
|
|
|
$provide.value('templateSrv', self.templateSrv);
|
2014-09-30 07:42:59 -05:00
|
|
|
$provide.value('$element', self.$element);
|
2014-10-01 06:49:36 -05:00
|
|
|
_.each(mocks, function(value, key) {
|
2014-09-30 07:42:59 -05:00
|
|
|
$provide.value(key, value);
|
|
|
|
});
|
2014-08-07 03:42:05 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.createControllerPhase = function(controllerName) {
|
2015-10-10 13:38:22 -05:00
|
|
|
return inject(function($controller, $rootScope, $q, $location, $browser) {
|
2014-08-07 03:42:05 -05:00
|
|
|
self.scope = $rootScope.$new();
|
2014-09-30 07:42:59 -05:00
|
|
|
self.$location = $location;
|
2015-10-10 13:38:22 -05:00
|
|
|
self.$browser = $browser;
|
2015-02-08 02:00:58 -06:00
|
|
|
self.scope.contextSrv = {};
|
2014-08-07 03:42:05 -05:00
|
|
|
self.scope.panel = {};
|
2014-08-11 08:59:03 -05:00
|
|
|
self.scope.row = { panels:[] };
|
2014-08-13 09:35:34 -05:00
|
|
|
self.scope.dashboard = {};
|
2015-03-29 08:01:27 -05:00
|
|
|
self.scope.dashboardMeta = {};
|
2014-08-13 08:17:01 -05:00
|
|
|
self.scope.dashboardViewState = new DashboardViewStateStub();
|
2014-10-01 06:49:36 -05:00
|
|
|
self.scope.appEvent = sinon.spy();
|
|
|
|
self.scope.onAppEvent = sinon.spy();
|
2014-08-11 08:59:03 -05:00
|
|
|
|
2014-08-08 07:10:35 -05:00
|
|
|
$rootScope.colors = [];
|
|
|
|
for (var i = 0; i < 50; i++) { $rootScope.colors.push('#' + i); }
|
2014-08-07 11:17:26 -05:00
|
|
|
|
2014-08-07 03:42:05 -05:00
|
|
|
self.$q = $q;
|
|
|
|
self.scope.skipDataOnInit = true;
|
2014-10-01 06:49:36 -05:00
|
|
|
self.scope.skipAutoInit = true;
|
2014-08-07 03:42:05 -05:00
|
|
|
self.controller = $controller(controllerName, {
|
|
|
|
$scope: self.scope
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-08-08 10:33:00 -05:00
|
|
|
function ServiceTestContext() {
|
|
|
|
var self = this;
|
2014-09-02 00:05:24 -05:00
|
|
|
self.templateSrv = new TemplateSrvStub();
|
2014-09-05 05:07:48 -05:00
|
|
|
self.timeSrv = new TimeSrvStub();
|
|
|
|
self.datasourceSrv = {};
|
2015-04-07 02:25:00 -05:00
|
|
|
self.backendSrv = {};
|
2015-05-04 03:13:12 -05:00
|
|
|
self.$location = {};
|
2014-09-07 04:55:26 -05:00
|
|
|
self.$routeParams = {};
|
2014-09-02 00:05:24 -05:00
|
|
|
|
2014-09-05 05:07:48 -05:00
|
|
|
this.providePhase = function(mocks) {
|
2014-09-02 00:05:24 -05:00
|
|
|
return module(function($provide) {
|
2014-09-05 05:07:48 -05:00
|
|
|
_.each(mocks, function(key) {
|
|
|
|
$provide.value(key, self[key]);
|
|
|
|
});
|
2014-09-02 00:05:24 -05:00
|
|
|
});
|
|
|
|
};
|
2014-08-08 10:33:00 -05:00
|
|
|
|
|
|
|
this.createService = function(name) {
|
2014-09-05 05:07:48 -05:00
|
|
|
return inject(function($q, $rootScope, $httpBackend, $injector) {
|
2014-08-08 10:33:00 -05:00
|
|
|
self.$q = $q;
|
|
|
|
self.$rootScope = $rootScope;
|
|
|
|
self.$httpBackend = $httpBackend;
|
2014-09-05 05:07:48 -05:00
|
|
|
|
|
|
|
self.$rootScope.onAppEvent = function() {};
|
2014-09-24 09:26:39 -05:00
|
|
|
self.$rootScope.appEvent = function() {};
|
2014-09-05 05:07:48 -05:00
|
|
|
|
|
|
|
self.service = $injector.get(name);
|
|
|
|
});
|
2014-08-08 10:33:00 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-08-13 08:17:01 -05:00
|
|
|
function DashboardViewStateStub() {
|
|
|
|
this.registerPanel = function() {
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-08-27 09:29:48 -05:00
|
|
|
function TimeSrvStub() {
|
2014-10-01 06:49:36 -05:00
|
|
|
this.init = sinon.spy();
|
2014-08-08 10:33:00 -05:00
|
|
|
this.time = { from:'now-1h', to: 'now'};
|
|
|
|
this.timeRange = function(parse) {
|
2014-08-20 05:11:14 -05:00
|
|
|
if (parse === false) {
|
2014-08-08 10:33:00 -05:00
|
|
|
return this.time;
|
|
|
|
}
|
|
|
|
return {
|
2015-09-17 04:21:38 -05:00
|
|
|
from : dateMath.parse(this.time.from, false),
|
|
|
|
to : dateMath.parse(this.time.to, true)
|
2014-08-08 10:33:00 -05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-08-27 10:58:49 -05:00
|
|
|
this.replace = function(target) {
|
2014-08-08 10:33:00 -05:00
|
|
|
return target;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-04-06 04:22:35 -05:00
|
|
|
function ContextSrvStub() {
|
|
|
|
this.hasRole = function() {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-08-28 09:03:13 -05:00
|
|
|
function TemplateSrvStub() {
|
|
|
|
this.variables = [];
|
2014-09-02 00:05:24 -05:00
|
|
|
this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g };
|
|
|
|
this.data = {};
|
|
|
|
this.replace = function(text) {
|
|
|
|
return _.template(text, this.data, this.templateSettings);
|
|
|
|
};
|
2014-09-07 04:55:26 -05:00
|
|
|
this.init = function() {};
|
2015-05-08 03:56:54 -05:00
|
|
|
this.fillVariableValuesForUrl = function() {};
|
2014-09-05 05:07:48 -05:00
|
|
|
this.updateTemplateData = function() { };
|
2014-09-05 01:26:50 -05:00
|
|
|
this.variableExists = function() { return false; };
|
|
|
|
this.highlightVariablesAsHtml = function(str) { return str; };
|
2014-09-02 00:05:24 -05:00
|
|
|
this.setGrafanaVariable = function(name, value) {
|
|
|
|
this.data[name] = value;
|
|
|
|
};
|
2014-08-28 09:03:13 -05:00
|
|
|
}
|
|
|
|
|
2014-08-07 03:42:05 -05:00
|
|
|
return {
|
2014-08-08 10:33:00 -05:00
|
|
|
ControllerTestContext: ControllerTestContext,
|
2014-08-27 09:29:48 -05:00
|
|
|
TimeSrvStub: TimeSrvStub,
|
2015-04-06 04:22:35 -05:00
|
|
|
ContextSrvStub: ContextSrvStub,
|
2014-08-08 10:33:00 -05:00
|
|
|
ServiceTestContext: ServiceTestContext
|
2014-08-07 03:42:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
});
|