Commit f144593c by Torkel Ödegaard

Merge branch 'develop' into overview

parents 53377567 c3a6ae16
...@@ -10,44 +10,44 @@ ...@@ -10,44 +10,44 @@
"url": "http://github.com/torkelo/grafana.git" "url": "http://github.com/torkelo/grafana.git"
}, },
"devDependencies": { "devDependencies": {
"rjs-build-analysis": "0.0.3", "expect.js": "~0.2.0",
"glob": "~3.2.7",
"grunt": "~0.4.0", "grunt": "~0.4.0",
"grunt-ngmin": "0.0.3", "grunt-angular-templates": "^0.5.5",
"grunt-contrib-less": "~0.7.0", "grunt-cli": "~0.1.13",
"grunt-contrib-copy": "~0.5.0",
"grunt-git-describe": "~2.3.2",
"grunt-contrib-clean": "~0.5.0", "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-cssmin": "~0.6.1",
"grunt-contrib-jshint": "~0.10.0",
"grunt-string-replace": "~0.2.4",
"grunt-contrib-htmlmin": "~0.1.3", "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-contrib-requirejs": "~0.4.1",
"grunt-angular-templates": "^0.5.5",
"grunt-contrib-compress": "~0.5.2",
"grunt-contrib-uglify": "~0.2.4", "grunt-contrib-uglify": "~0.2.4",
"load-grunt-tasks": "~0.2.0", "grunt-filerev": "^0.2.1",
"glob": "~3.2.7", "grunt-git-describe": "~2.3.2",
"grunt-contrib-connect": "~0.5.0", "grunt-karma": "~0.8.3",
"mocha": "~1.16.1", "grunt-ngmin": "0.0.3",
"expect.js": "~0.2.0", "grunt-string-replace": "~0.2.4",
"karma-script-launcher": "~0.1.0", "grunt-usemin": "^2.1.1",
"karma-firefox-launcher": "~0.1.3", "jshint-stylish": "~0.1.5",
"karma": "~0.12.16",
"karma-chrome-launcher": "~0.1.4", "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-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.2.2", "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-mocha": "~0.1.4",
"karma-expect": "~1.1.0", "karma-phantomjs-launcher": "~0.1.1",
"grunt-cli": "~0.1.13", "karma-requirejs": "~0.2.1",
"jshint-stylish": "~0.1.5", "karma-script-launcher": "~0.1.0",
"grunt-contrib-concat": "^0.4.0", "load-grunt-tasks": "~0.2.0",
"grunt-usemin": "^2.1.1", "mocha": "~1.16.1",
"grunt-filerev": "^0.2.1" "requirejs": "~2.1.14",
"rjs-build-analysis": "0.0.3"
}, },
"engines": { "engines": {
"node": "0.10.x", "node": "0.10.x",
...@@ -58,6 +58,8 @@ ...@@ -58,6 +58,8 @@
}, },
"license": "Apache License", "license": "Apache License",
"dependencies": { "dependencies": {
"grunt-jscs-checker": "^0.4.4" "grunt-jscs-checker": "^0.4.4",
"karma-sinon": "^1.0.3",
"sinon": "^1.10.3"
} }
} }
...@@ -249,7 +249,7 @@ function (angular, _, config, gfunc, Parser) { ...@@ -249,7 +249,7 @@ function (angular, _, config, gfunc, Parser) {
return; return;
} }
for(var i = 0; i < $scope.segments.length; i++) { 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.params[0] = i;
func.added = false; func.added = false;
$scope.targetChanged(); $scope.targetChanged();
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
"expect": true, "expect": true,
"it": true, "it": true,
"describe": true, "describe": true,
"sinon": true,
"define": true, "define": true,
"module": true, "module": true,
"beforeEach": true, "beforeEach": true,
...@@ -35,4 +36,4 @@ ...@@ -35,4 +36,4 @@
"require": true, "require": true,
"setImmediate": true "setImmediate": true
} }
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ module.exports = function(config) { ...@@ -4,7 +4,7 @@ module.exports = function(config) {
config.set({ config.set({
basePath: '../', basePath: '../',
frameworks: ['mocha', 'requirejs', 'expect'], frameworks: ['mocha', 'requirejs', 'expect', 'sinon'],
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files: [ files: [
...@@ -25,6 +25,6 @@ module.exports = function(config) { ...@@ -25,6 +25,6 @@ module.exports = function(config) {
autoWatch: true, autoWatch: true,
browsers: ['Chrome'], browsers: ['Chrome'],
captureTimeout: 60000, captureTimeout: 60000,
singleRun: false singleRun: false,
}); });
}; };
define([ define([
], function() { './helpers',
'services/graphite/gfunc',
'controllers/graphiteTarget'
], function(helpers, gfunc) {
'use strict'; 'use strict';
describe('graphiteTargetCtrl', function() { describe('GraphiteTargetCtrl', function() {
var _targetCtrl; var ctx = new helpers.ControllerTestContext();
beforeEach(module('grafana.services')); beforeEach(module('grafana.controllers'));
beforeEach(module(function($provide){ beforeEach(ctx.providePhase());
$provide.value('filterSrv',{}); beforeEach(ctx.createControllerPhase('GraphiteTargetCtrl'));
}));
beforeEach(inject(function($controller, $rootScope) { beforeEach(function() {
_targetCtrl = $controller({ ctx.scope.target = {
$scope: $rootScope.$new() 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() { describe('init', function() {
beforeEach(function() { beforeEach(function() {
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);
});
});
}); });
}); });
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([ ...@@ -121,6 +121,7 @@ require([
'specs/lexer-specs', 'specs/lexer-specs',
'specs/parser-specs', 'specs/parser-specs',
'specs/gfunc-specs', 'specs/gfunc-specs',
'specs/graphiteTargetCtrl-specs',
'specs/filterSrv-specs', 'specs/filterSrv-specs',
'specs/kbn-format-specs', 'specs/kbn-format-specs',
'specs/dashboardModel-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