sharePanelCtrl-specs.js 2.5 KB

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