shareModalCtrl-specs.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. define([
  2. 'helpers',
  3. 'features/dashboard/shareModalCtrl'
  4. ], function(helpers) {
  5. 'use strict';
  6. describe('ShareModalCtrl', 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('ShareModalCtrl'));
  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.init();
  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.init();
  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 no panel in scope', function() {
  31. ctx.$location.path('/test');
  32. ctx.scope.options.forCurrent = true;
  33. ctx.scope.panel = null;
  34. setTime({ from: 'now-1h', to: 'now' });
  35. ctx.scope.init();
  36. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now');
  37. });
  38. it('should add theme when specified', function() {
  39. ctx.$location.path('/test');
  40. ctx.scope.options.theme = 'light';
  41. ctx.scope.panel = null;
  42. setTime({ from: 'now-1h', to: 'now' });
  43. ctx.scope.init();
  44. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&theme=light');
  45. });
  46. it('should include template variables in url', function() {
  47. ctx.$location.path('/test');
  48. ctx.scope.options.includeTemplateVars = true;
  49. ctx.templateSrv.variables = [{ name: 'app', current: {text: 'mupp' }}, {name: 'server', current: {text: 'srv-01'}}];
  50. setTime({ from: 'now-1h', to: 'now' });
  51. ctx.scope.buildUrl();
  52. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&var-app=mupp&var-server=srv-01');
  53. });
  54. });
  55. });
  56. });