shareModalCtrl-specs.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.timeRange = sinon.stub().returns(range);
  11. }
  12. setTime({ from: new Date(1000), to: new Date(2000) });
  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 absolute time', function() {
  19. ctx.$location.path('/test');
  20. ctx.scope.panel = { id: 22 };
  21. ctx.scope.init();
  22. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000&panelId=22&fullscreen');
  23. });
  24. it('should remove panel id when no panel in scope', function() {
  25. ctx.$location.path('/test');
  26. ctx.scope.options.forCurrent = true;
  27. ctx.scope.panel = null;
  28. ctx.scope.init();
  29. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000');
  30. });
  31. it('should add theme when specified', function() {
  32. ctx.$location.path('/test');
  33. ctx.scope.options.theme = 'light';
  34. ctx.scope.panel = null;
  35. ctx.scope.init();
  36. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000&theme=light');
  37. });
  38. it('should include template variables in url', function() {
  39. ctx.$location.path('/test');
  40. ctx.scope.options.includeTemplateVars = true;
  41. ctx.templateSrv.fillVariableValuesForUrl = function(params) {
  42. params['var-app'] = 'mupp';
  43. params['var-server'] = 'srv-01';
  44. };
  45. ctx.scope.buildUrl();
  46. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000&var-app=mupp&var-server=srv-01');
  47. });
  48. });
  49. });
  50. });