mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(panels): fixed unit tests
This commit is contained in:
@@ -9,7 +9,8 @@ define([
|
||||
beforeEach(module('grafana.services'));
|
||||
|
||||
beforeEach(inject(function(dashboardViewStateSrv, $location, $rootScope) {
|
||||
$rootScope.onAppEvent = function(){};
|
||||
$rootScope.onAppEvent = function() {};
|
||||
$rootScope.dashboard = {meta: {}};
|
||||
viewState = dashboardViewStateSrv.create($rootScope);
|
||||
location = $location;
|
||||
}));
|
||||
@@ -19,7 +20,7 @@ define([
|
||||
var updateState = { fullscreen: true, edit: true, panelId: 1 };
|
||||
viewState.update(updateState);
|
||||
expect(location.search()).to.eql(updateState);
|
||||
expect(viewState.fullscreen).to.be(true);
|
||||
expect(viewState.dashboard.meta.fullscreen).to.be(true);
|
||||
expect(viewState.state.fullscreen).to.be(true);
|
||||
});
|
||||
});
|
||||
@@ -29,7 +30,7 @@ define([
|
||||
viewState.update({fullscreen: true, panelId: 1, edit: true});
|
||||
viewState.update({fullscreen: false});
|
||||
expect(location.search()).to.eql({});
|
||||
expect(viewState.fullscreen).to.be(false);
|
||||
expect(viewState.dashboard.meta.fullscreen).to.be(false);
|
||||
expect(viewState.state.fullscreen).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
define([
|
||||
'lodash',
|
||||
'app/core/config',
|
||||
'app/core/utils/datemath',
|
||||
], function(_, dateMath) {
|
||||
], function(_, config, dateMath) {
|
||||
'use strict';
|
||||
|
||||
function ControllerTestContext() {
|
||||
@@ -36,6 +37,28 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
this.createPanelController = function(Ctrl) {
|
||||
return inject(function($controller, $rootScope, $q, $location, $browser) {
|
||||
self.scope = $rootScope.$new();
|
||||
self.$location = $location;
|
||||
self.$browser = $browser;
|
||||
self.$q = $q;
|
||||
self.panel = {type: 'test'};
|
||||
self.dashboard = {};
|
||||
|
||||
$rootScope.appEvent = sinon.spy();
|
||||
$rootScope.onAppEvent = sinon.spy();
|
||||
$rootScope.colors = [];
|
||||
|
||||
for (var i = 0; i < 50; i++) { $rootScope.colors.push('#' + i); }
|
||||
|
||||
config.panels['test'] = {info: {}};
|
||||
self.ctrl = $controller(Ctrl, {$scope: self.scope}, {
|
||||
panel: self.panel, dashboard: self.dashboard
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.createControllerPhase = function(controllerName) {
|
||||
return inject(function($controller, $rootScope, $q, $location, $browser) {
|
||||
self.scope = $rootScope.$new();
|
||||
@@ -59,7 +82,6 @@ define([
|
||||
self.controller = $controller(controllerName, {
|
||||
$scope: self.scope
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -74,10 +96,10 @@ define([
|
||||
self.$routeParams = {};
|
||||
|
||||
this.providePhase = function(mocks) {
|
||||
return module(function($provide) {
|
||||
_.each(mocks, function(key) {
|
||||
$provide.value(key, self[key]);
|
||||
});
|
||||
return module(function($provide) {
|
||||
_.each(mocks, function(key) {
|
||||
$provide.value(key, self[key]);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -9,16 +9,25 @@ define([
|
||||
var popoverSrv = {};
|
||||
|
||||
beforeEach(module('grafana.services'));
|
||||
beforeEach(module('grafana.panels.graph'));
|
||||
beforeEach(module('grafana.controllers'));
|
||||
|
||||
beforeEach(ctx.providePhase({
|
||||
popoverSrv: popoverSrv
|
||||
}));
|
||||
|
||||
beforeEach(ctx.createControllerPhase('SeriesOverridesCtrl'));
|
||||
beforeEach(function() {
|
||||
beforeEach(inject(function($rootScope, $controller) {
|
||||
// ctx.createControllerPhase('SeriesOverridesCtrl'));
|
||||
// beforeEach(function() {
|
||||
ctx.scope = $rootScope.$new();
|
||||
ctx.scope.ctrl = {
|
||||
render: sinon.spy(),
|
||||
seriesList: []
|
||||
};
|
||||
ctx.scope.render = function() {};
|
||||
});
|
||||
ctx.controller = $controller('SeriesOverridesCtrl', {
|
||||
$scope: ctx.scope
|
||||
});
|
||||
}));
|
||||
|
||||
describe('When setting an override', function() {
|
||||
beforeEach(function() {
|
||||
|
||||
Reference in New Issue
Block a user