Commit c3a6ae16 by Torkel Ödegaard

added more graphite target controller tests

parent 76aab2a2
......@@ -10,44 +10,44 @@
"url": "http://github.com/torkelo/grafana.git"
},
"devDependencies": {
"rjs-build-analysis": "0.0.3",
"expect.js": "~0.2.0",
"glob": "~3.2.7",
"grunt": "~0.4.0",
"grunt-ngmin": "0.0.3",
"grunt-contrib-less": "~0.7.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-git-describe": "~2.3.2",
"grunt-angular-templates": "^0.5.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-compress": "~0.5.2",
"grunt-contrib-concat": "^0.4.0",
"grunt-contrib-connect": "~0.5.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-cssmin": "~0.6.1",
"grunt-contrib-jshint": "~0.10.0",
"grunt-string-replace": "~0.2.4",
"grunt-contrib-htmlmin": "~0.1.3",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-less": "~0.7.0",
"grunt-contrib-requirejs": "~0.4.1",
"grunt-angular-templates": "^0.5.5",
"grunt-contrib-compress": "~0.5.2",
"grunt-contrib-uglify": "~0.2.4",
"load-grunt-tasks": "~0.2.0",
"glob": "~3.2.7",
"grunt-contrib-connect": "~0.5.0",
"mocha": "~1.16.1",
"expect.js": "~0.2.0",
"karma-script-launcher": "~0.1.0",
"karma-firefox-launcher": "~0.1.3",
"grunt-filerev": "^0.2.1",
"grunt-git-describe": "~2.3.2",
"grunt-karma": "~0.8.3",
"grunt-ngmin": "0.0.3",
"grunt-string-replace": "~0.2.4",
"grunt-usemin": "^2.1.1",
"jshint-stylish": "~0.1.5",
"karma": "~0.12.16",
"karma-chrome-launcher": "~0.1.4",
"karma-coffee-preprocessor": "~0.1.2",
"karma-expect": "~1.1.0",
"karma-firefox-launcher": "~0.1.3",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.2.2",
"requirejs": "~2.1.14",
"karma-requirejs": "~0.2.1",
"karma-coffee-preprocessor": "~0.1.2",
"karma-phantomjs-launcher": "~0.1.1",
"karma": "~0.12.16",
"grunt-karma": "~0.8.3",
"karma-mocha": "~0.1.4",
"karma-expect": "~1.1.0",
"grunt-cli": "~0.1.13",
"jshint-stylish": "~0.1.5",
"grunt-contrib-concat": "^0.4.0",
"grunt-usemin": "^2.1.1",
"grunt-filerev": "^0.2.1"
"karma-phantomjs-launcher": "~0.1.1",
"karma-requirejs": "~0.2.1",
"karma-script-launcher": "~0.1.0",
"load-grunt-tasks": "~0.2.0",
"mocha": "~1.16.1",
"requirejs": "~2.1.14",
"rjs-build-analysis": "0.0.3"
},
"engines": {
"node": "0.10.x",
......
......@@ -249,7 +249,7 @@ function (angular, _, config, gfunc, Parser) {
return;
}
for(var i = 0; i < $scope.segments.length; i++) {
if ($scope.segments[i].val.indexOf('*') >= 0) {
if ($scope.segments[i].value.indexOf('*') >= 0) {
func.params[0] = i;
func.added = false;
$scope.targetChanged();
......
......@@ -28,6 +28,7 @@
"expect": true,
"it": true,
"describe": true,
"sinon": true,
"define": true,
"module": true,
"beforeEach": true,
......@@ -35,4 +36,4 @@
"require": true,
"setImmediate": true
}
}
\ No newline at end of file
}
......@@ -25,6 +25,6 @@ module.exports = function(config) {
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 60000,
singleRun: false
singleRun: false,
});
};
define([
'./helpers',
'services/graphite/gfunc',
'controllers/graphiteTarget'
], function(helpers) {
], function(helpers, gfunc) {
'use strict';
describe('GraphiteTargetCtrl', function() {
......@@ -11,25 +12,78 @@ define([
beforeEach(ctx.providePhase());
beforeEach(ctx.createControllerPhase('GraphiteTargetCtrl'));
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([]));
});
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();
ctx.scope.$digest();
});
it('should validate metric key exists', function() {
expect(ctx.scope.datasource.metricFindQuery.getCall(0).args[1]).to.be('test.prod.*');
});
it('should delete last segment if no metrics are found', function() {
expect(ctx.scope.segments[2].value).to.be('select metric');
});
it('should parse expression and build function model', function() {
expect(ctx.scope.functions.length).to.be(2);
});
});
describe('when adding function', function() {
beforeEach(function() {
ctx.scope.target.target = 'test.prod.*.count';
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}]));
ctx.scope.init();
ctx.scope.$digest();
ctx.scope.$parent = { get_data: sinon.spy() };
ctx.scope.addFunction(gfunc.getFuncDef('aliasByNode'));
});
it('should add function with correct node number', function() {
expect(ctx.scope.functions[0].params[0]).to.be(2);
});
it('should update target', function() {
expect(ctx.scope.target.target).to.be('aliasByNode(test.prod.*.count,2)');
});
it('should call get_data', function() {
expect(ctx.scope.$parent.get_data.called).to.be(true);
});
});
describe('targetChanged', function() {
beforeEach(function() {
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}]));
ctx.scope.init();
ctx.scope.$digest();
ctx.scope.$parent = { get_data: sinon.spy() };
ctx.scope.target.target = '';
ctx.scope.targetChanged();
});
it('should rebuld target after expression model', function() {
expect(ctx.scope.target.target).to.be('aliasByNode(scaleToSeconds(test.prod.*,1),2)');
});
it('should call get_data', function() {
expect(ctx.scope.$parent.get_data.called).to.be(true);
});
});
});
});
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