shareModalCtrl-specs.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. define([
  2. './helpers',
  3. 'app/features/dashboard/shareModalCtrl',
  4. 'app/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 generate render url', function() {
  25. ctx.$location.$$absUrl = 'http://dashboards.grafana.com/dashboard/db/my-dash';
  26. ctx.scope.panel = { id: 22 };
  27. ctx.scope.init();
  28. var base = 'http://dashboards.grafana.com/render/dashboard-solo/db/my-dash';
  29. var params = '?from=1000&to=2000&panelId=22&fullscreen&width=1000&height=500';
  30. expect(ctx.scope.imageUrl).to.be(base + params);
  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. ctx.scope.init();
  37. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000');
  38. });
  39. it('should add theme when specified', function() {
  40. ctx.$location.path('/test');
  41. ctx.scope.options.theme = 'light';
  42. ctx.scope.panel = null;
  43. ctx.scope.init();
  44. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000&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.fillVariableValuesForUrl = function(params) {
  50. params['var-app'] = 'mupp';
  51. params['var-server'] = 'srv-01';
  52. };
  53. ctx.scope.buildUrl();
  54. expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=1000&to=2000&var-app=mupp&var-server=srv-01');
  55. });
  56. });
  57. });
  58. });