Commit 76aab2a2 by Torkel Ödegaard

added graphiteTargetCtrl specs

parent a02effc3
......@@ -58,6 +58,8 @@
},
"license": "Apache License",
"dependencies": {
"grunt-jscs-checker": "^0.4.4"
"grunt-jscs-checker": "^0.4.4",
"karma-sinon": "^1.0.3",
"sinon": "^1.10.3"
}
}
......@@ -4,7 +4,7 @@ module.exports = function(config) {
config.set({
basePath: '../',
frameworks: ['mocha', 'requirejs', 'expect'],
frameworks: ['mocha', 'requirejs', 'expect', 'sinon'],
// list of files / patterns to load in the browser
files: [
......
define([
], function() {
'./helpers',
'controllers/graphiteTarget'
], function(helpers) {
'use strict';
describe('graphiteTargetCtrl', function() {
var _targetCtrl;
describe('GraphiteTargetCtrl', function() {
var ctx = new helpers.ControllerTestContext();
beforeEach(module('grafana.services'));
beforeEach(module(function($provide){
$provide.value('filterSrv',{});
}));
beforeEach(inject(function($controller, $rootScope) {
_targetCtrl = $controller({
$scope: $rootScope.$new()
});
}));
beforeEach(module('grafana.controllers'));
beforeEach(ctx.providePhase());
beforeEach(ctx.createControllerPhase('GraphiteTargetCtrl'));
describe('init', function() {
beforeEach(function() {
ctx.scope.target = {
target: 'aliasByNode(scaleToSeconds(test.prod.*,1),2)'
};
ctx.scope.datasource = ctx.datasource;
ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
ctx.scope.init();
});
it('should validate metric key exists', function() {
expect(ctx.scope.datasource.metricFindQuery.getCall(0).args[1]).to.be('test.prod.*');
});
it('should parse expression and build function model', function() {
expect(ctx.scope.functions.length).to.be(2);
});
});
});
});
define([
], function() {
'use strict';
function ControllerTestContext() {
var self = this;
this.datasource = {};
this.datasourceSrv = {
getMetricSources: function() {},
get: function() { return self.datasource; }
};
this.providePhase = function() {
return module(function($provide) {
$provide.value('datasourceSrv', self.datasourceSrv);
});
};
this.createControllerPhase = function(controllerName) {
return inject(function($controller, $rootScope, $q) {
self.scope = $rootScope.$new();
self.scope.panel = {};
self.scope.filter = {
timeRange: function() {}
};
self.$q = $q;
self.scope.skipDataOnInit = true;
self.controller = $controller(controllerName, {
$scope: self.scope
});
});
};
}
return {
ControllerTestContext: ControllerTestContext
};
});
......@@ -121,6 +121,7 @@ require([
'specs/lexer-specs',
'specs/parser-specs',
'specs/gfunc-specs',
'specs/graphiteTargetCtrl-specs',
'specs/filterSrv-specs',
'specs/kbn-format-specs',
'specs/dashboardModel-specs',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment