2014-08-07 03:42:05 -05:00
|
|
|
define([
|
2015-09-17 04:21:38 -05:00
|
|
|
'lodash',
|
2016-01-27 11:51:01 -06:00
|
|
|
'app/core/config',
|
2015-09-17 04:21:38 -05:00
|
|
|
'app/core/utils/datemath',
|
2016-01-27 11:51:01 -06:00
|
|
|
], function(_, config, 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
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-01-27 11:51:01 -06:00
|
|
|
this.createPanelController = function(Ctrl) {
|
|
|
|
return inject(function($controller, $rootScope, $q, $location, $browser) {
|
|
|
|
self.scope = $rootScope.$new();
|
|
|
|
self.$location = $location;
|
|
|
|
self.$browser = $browser;
|
|
|
|
self.$q = $q;
|
|
|
|
self.panel = {type: 'test'};
|
2016-01-28 18:07:53 -06:00
|
|
|
self.dashboard = {meta: {}};
|
2016-01-27 11:51:01 -06:00
|
|
|
|
|
|
|
$rootScope.appEvent = sinon.spy();
|
|
|
|
$rootScope.onAppEvent = sinon.spy();
|
|
|
|
$rootScope.colors = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < 50; i++) { $rootScope.colors.push('#' + i); }
|
|
|
|
|
|
|
|
config.panels['test'] = {info: {}};
|
|
|
|
self.ctrl = $controller(Ctrl, {$scope: self.scope}, {
|
2016-03-06 05:34:47 -06:00
|
|
|
panel: self.panel, dashboard: self.dashboard, row: {}
|
2016-01-27 11:51:01 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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:[] };
|
2016-01-28 18:07:53 -06:00
|
|
|
self.scope.dashboard = {meta: {}};
|
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 = {};
|
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) {
|
2016-01-27 11:51:01 -06:00
|
|
|
return module(function($provide) {
|
|
|
|
_.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) {
|
2017-01-13 10:37:53 -06:00
|
|
|
return inject(function($q, $rootScope, $httpBackend, $injector, $location) {
|
2014-08-08 10:33:00 -05:00
|
|
|
self.$q = $q;
|
|
|
|
self.$rootScope = $rootScope;
|
|
|
|
self.$httpBackend = $httpBackend;
|
2017-01-13 10:37:53 -06:00
|
|
|
self.$location = $location;
|
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;
|
|
|
|
};
|
2016-05-18 00:56:23 -05:00
|
|
|
|
|
|
|
this.setTime = function(time) {
|
|
|
|
this.time = time;
|
|
|
|
};
|
2014-08-08 10:33:00 -05:00
|
|
|
}
|
|
|
|
|
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) {
|
2016-09-13 15:10:44 -05:00
|
|
|
return _.template(text, this.templateSettings)(this.data);
|
2014-09-02 00:05:24 -05:00
|
|
|
};
|
2014-09-07 04:55:26 -05:00
|
|
|
this.init = function() {};
|
2016-09-21 01:46:59 -05:00
|
|
|
this.getAdhocFilters = function() { return []; };
|
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; };
|
2017-01-16 15:27:35 -06:00
|
|
|
this.variableInitialized = function() { };
|
2014-09-05 01:26:50 -05:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
});
|