|
@@ -3,46 +3,60 @@ define([
|
|
|
], function() {
|
|
], function() {
|
|
|
'use strict';
|
|
'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
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
describe('OverviewCtrl', function() {
|
|
describe('OverviewCtrl', function() {
|
|
|
- var _controller;
|
|
|
|
|
- var _scope;
|
|
|
|
|
- var _datasource;
|
|
|
|
|
|
|
+ var ctx = new ControllerTestContext();
|
|
|
|
|
|
|
|
beforeEach(module('grafana.services'));
|
|
beforeEach(module('grafana.services'));
|
|
|
beforeEach(module('grafana.panels.overview'));
|
|
beforeEach(module('grafana.panels.overview'));
|
|
|
|
|
|
|
|
- beforeEach(module(function($provide){
|
|
|
|
|
- $provide.value('datasourceSrv',{
|
|
|
|
|
- getMetricSources: function() {
|
|
|
|
|
- },
|
|
|
|
|
- get: function() {
|
|
|
|
|
- return _datasource;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }));
|
|
|
|
|
-
|
|
|
|
|
- beforeEach(inject(function($controller, $rootScope, $q) {
|
|
|
|
|
- _scope = $rootScope.$new();
|
|
|
|
|
- _scope.panel = { targets: [] };
|
|
|
|
|
- _scope.filter = {
|
|
|
|
|
- timeRange: function() { }
|
|
|
|
|
- };
|
|
|
|
|
- _scope.datasource = {
|
|
|
|
|
- query: function() {
|
|
|
|
|
- return $q.resolve('hej');
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- _controller = $controller('OverviewCtrl', {
|
|
|
|
|
- $scope: _scope
|
|
|
|
|
- });
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ beforeEach(ctx.providePhase());
|
|
|
|
|
+ beforeEach(ctx.createControllerPhase('OverviewCtrl'));
|
|
|
|
|
|
|
|
- describe('init', function() {
|
|
|
|
|
|
|
+ describe('when query return error', function() {
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
|
|
+ ctx.datasource.query = function() {
|
|
|
|
|
+ return ctx.$q.reject({ message: 'Some error' });
|
|
|
|
|
+ };
|
|
|
|
|
+ ctx.scope.get_data();
|
|
|
|
|
+ ctx.scope.$digest();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('description', function() {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ it('panel.error should be set', function() {
|
|
|
|
|
+ expect(ctx.scope.panel.error).to.be("Some error");
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|