mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
added graphiteTargetCtrl specs
This commit is contained in:
parent
a02effc32e
commit
76aab2a2ac
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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: [
|
||||||
|
@ -1,24 +1,35 @@
|
|||||||
define([
|
define([
|
||||||
], function() {
|
'./helpers',
|
||||||
|
'controllers/graphiteTarget'
|
||||||
|
], function(helpers) {
|
||||||
'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) {
|
|
||||||
_targetCtrl = $controller({
|
|
||||||
$scope: $rootScope.$new()
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('init', function() {
|
describe('init', function() {
|
||||||
beforeEach(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
43
src/test/specs/helpers.js
Normal 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
|
||||||
|
};
|
||||||
|
|
||||||
|
});
|
@ -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',
|
||||||
|
Loading…
Reference in New Issue
Block a user