shareModalCtrl-specs.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. define([
  2. 'helpers',
  3. 'features/dashboard/shareModalCtrl',
  4. 'features/panellinks/linkSrv',
  5. ], function(helpers) {
  6. 'use strict';
  7. describe('ShareModalCtrl', function() {
  8. var ctx = new helpers.ControllerTestContext();
  9. function setTime(range) {
  10. ctx.timeSrv.timeRangeForUrl = sinon.stub().returns(range);
  11. }
  12. setTime({ from: 'now-1h', to: 'now' });
  13. beforeEach(module('grafana.controllers'));
  14. beforeEach(module('grafana.services'));
  15. beforeEach(ctx.providePhase());
  16. beforeEach(ctx.createControllerPhase('ShareModalCtrl'));
  17. describe('shareUrl with current time range and panel', function() {
  18. it('should generate share url relative time', function() {
  19. ctx.$location.path('/test');
  20. ctx.scope.panel = { id: 22 };
  21. setTime({ from: 'now-1h', to: 'now' });
  22. ctx.scope.init();
  23. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&panelId=22&fullscreen');
  24. });
  25. it('should generate share url absolute time', function() {
  26. ctx.$location.path('/test');
  27. ctx.scope.panel = { id: 22 };
  28. setTime({ from: 1362178800000, to: 1396648800000 });
  29. ctx.scope.init();
  30. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1362178800000&to=1396648800000&panelId=22&fullscreen');
  31. });
  32. it('should remove panel id when no panel in scope', function() {
  33. ctx.$location.path('/test');
  34. ctx.scope.options.forCurrent = true;
  35. ctx.scope.panel = null;
  36. setTime({ from: 'now-1h', to: 'now' });
  37. ctx.scope.init();
  38. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now');
  39. });
  40. it('should add theme when specified', function() {
  41. ctx.$location.path('/test');
  42. ctx.scope.options.theme = 'light';
  43. ctx.scope.panel = null;
  44. setTime({ from: 'now-1h', to: 'now' });
  45. ctx.scope.init();
  46. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&theme=light');
  47. });
  48. it('should include template variables in url', function() {
  49. ctx.$location.path('/test');
  50. ctx.scope.options.includeTemplateVars = true;
  51. setTime({ from: 'now-1h', to: 'now' });
  52. ctx.templateSrv.fillVariableValuesForUrl = function(params) {
  53. params['var-app'] = 'mupp';
  54. params['var-server'] = 'srv-01';
  55. };
  56. ctx.scope.buildUrl();
  57. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&var-app=mupp&var-server=srv-01');
  58. });
  59. });
  60. });
  61. });