added graphiteTargetCtrl specs

This commit is contained in:
Torkel Ödegaard 2014-08-07 10:42:05 +02:00
parent a02effc32e
commit 76aab2a2ac
5 changed files with 72 additions and 15 deletions

View File

@ -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"
}
}

View File

@ -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: [

View File

@ -1,24 +1,35 @@
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);
});
});
});
});

43
src/test/specs/helpers.js Normal file
View File

@ -0,0 +1,43 @@
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
};
});

View File

@ -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',