mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SharePanelModal: working on share feature, #864
This commit is contained in:
@@ -8,6 +8,7 @@ define([
|
||||
var self = this;
|
||||
|
||||
this.datasource = {};
|
||||
this.$element = {};
|
||||
this.annotationsSrv = {};
|
||||
this.timeSrv = new TimeSrvStub();
|
||||
this.templateSrv = new TemplateSrvStub();
|
||||
@@ -16,18 +17,23 @@ define([
|
||||
get: function() { return self.datasource; }
|
||||
};
|
||||
|
||||
this.providePhase = function() {
|
||||
this.providePhase = function(mocks) {
|
||||
return module(function($provide) {
|
||||
$provide.value('datasourceSrv', self.datasourceSrv);
|
||||
$provide.value('annotationsSrv', self.annotationsSrv);
|
||||
$provide.value('timeSrv', self.timeSrv);
|
||||
$provide.value('templateSrv', self.templateSrv);
|
||||
$provide.value('$element', self.$element);
|
||||
_.each(mocks, function(key, value) {
|
||||
$provide.value(key, value);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.createControllerPhase = function(controllerName) {
|
||||
return inject(function($controller, $rootScope, $q) {
|
||||
return inject(function($controller, $rootScope, $q, $location) {
|
||||
self.scope = $rootScope.$new();
|
||||
self.$location = $location;
|
||||
self.scope.panel = {};
|
||||
self.scope.row = { panels:[] };
|
||||
self.scope.dashboard = {};
|
||||
|
||||
59
src/test/specs/sharePanelCtrl-specs.js
Normal file
59
src/test/specs/sharePanelCtrl-specs.js
Normal file
@@ -0,0 +1,59 @@
|
||||
define([
|
||||
'./helpers',
|
||||
'controllers/sharePanelCtrl'
|
||||
], function(helpers) {
|
||||
'use strict';
|
||||
|
||||
describe('SharePanelCtrl', function() {
|
||||
var ctx = new helpers.ControllerTestContext();
|
||||
|
||||
beforeEach(module('grafana.controllers'));
|
||||
|
||||
beforeEach(ctx.providePhase());
|
||||
beforeEach(ctx.createControllerPhase('SharePanelCtrl'));
|
||||
|
||||
describe('shareUrl with current time range and panel', function() {
|
||||
|
||||
it('should generate share url relative time', function() {
|
||||
ctx.$location.path('/test');
|
||||
ctx.scope.panel = { id: 22 };
|
||||
ctx.timeSrv.time = { from: 'now-1h', to: 'now' };
|
||||
|
||||
ctx.scope.buildUrl();
|
||||
expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&panelId=22&fullscreen');
|
||||
});
|
||||
|
||||
it('should generate share url absolute time', function() {
|
||||
ctx.$location.path('/test');
|
||||
ctx.scope.panel = { id: 22 };
|
||||
ctx.timeSrv.time = { from: new Date(2012,1,1), to: new Date(2014,3,5) };
|
||||
|
||||
ctx.scope.buildUrl();
|
||||
expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1328050800000&to=1396648800000&panelId=22&fullscreen');
|
||||
});
|
||||
|
||||
it('should generate share url with time as JSON strings', function() {
|
||||
ctx.$location.path('/test');
|
||||
ctx.scope.panel = { id: 22 };
|
||||
ctx.timeSrv.time = { from: new Date(2012,1,1).toJSON(), to: new Date(2014,3,5).toJSON() };
|
||||
|
||||
ctx.scope.buildUrl();
|
||||
expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1328050800000&to=1396648800000&panelId=22&fullscreen');
|
||||
});
|
||||
|
||||
it('should remove panel id when toPanel is false', function() {
|
||||
ctx.$location.path('/test');
|
||||
ctx.scope.panel = { id: 22 };
|
||||
ctx.scope.toPanel = false;
|
||||
ctx.timeSrv.time = { from: 'now-1h', to: 'now' };
|
||||
|
||||
ctx.scope.buildUrl();
|
||||
expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -131,6 +131,7 @@ require([
|
||||
'specs/grafanaGraph-specs',
|
||||
'specs/graph-tooltip-specs',
|
||||
'specs/seriesOverridesCtrl-specs',
|
||||
'specs/sharePanelCtrl-specs',
|
||||
'specs/timeSrv-specs',
|
||||
'specs/templateSrv-specs',
|
||||
'specs/templateValuesSrv-specs',
|
||||
|
||||
Reference in New Issue
Block a user