sharePanelCtrl-specs.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. define([
  2. 'helpers',
  3. 'features/dashboard/sharePanelCtrl'
  4. ], function(helpers) {
  5. 'use strict';
  6. describe('SharePanelCtrl', function() {
  7. var ctx = new helpers.ControllerTestContext();
  8. function setTime(range) {
  9. ctx.timeSrv.timeRangeForUrl = sinon.stub().returns(range);
  10. }
  11. setTime({ from: 'now-1h', to: 'now' });
  12. beforeEach(module('grafana.controllers'));
  13. beforeEach(ctx.providePhase());
  14. beforeEach(ctx.createControllerPhase('SharePanelCtrl'));
  15. describe('shareUrl with current time range and panel', function() {
  16. it('should generate share url relative time', function() {
  17. ctx.$location.path('/test');
  18. ctx.scope.panel = { id: 22 };
  19. setTime({ from: 'now-1h', to: 'now' });
  20. ctx.scope.buildUrl();
  21. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&panelId=22&fullscreen');
  22. });
  23. it('should generate share url absolute time', function() {
  24. ctx.$location.path('/test');
  25. ctx.scope.panel = { id: 22 };
  26. setTime({ from: 1362178800000, to: 1396648800000 });
  27. ctx.scope.buildUrl();
  28. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1362178800000&to=1396648800000&panelId=22&fullscreen');
  29. });
  30. it('should remove panel id when toPanel is false', function() {
  31. ctx.$location.path('/test');
  32. ctx.scope.panel = { id: 22 };
  33. ctx.scope.options = { toPanel: false, forCurrent: true };
  34. setTime({ from: 'now-1h', to: 'now' });
  35. ctx.scope.buildUrl();
  36. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now');
  37. });
  38. it('should include template variables in url', function() {
  39. ctx.$location.path('/test');
  40. ctx.scope.panel = { id: 22 };
  41. ctx.scope.options = { includeTemplateVars: true, toPanel: false, forCurrent: true };
  42. ctx.templateSrv.variables = [{ name: 'app', current: {text: 'mupp' }}, {name: 'server', current: {text: 'srv-01'}}];
  43. setTime({ from: 'now-1h', to: 'now' });
  44. ctx.scope.buildUrl();
  45. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&var-app=mupp&var-server=srv-01');
  46. });
  47. });
  48. });
  49. });