shareModalCtrl-specs.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. define([
  2. './helpers',
  3. 'app/features/dashboard/shareModalCtrl',
  4. 'app/features/panellinks/linkSrv',
  5. 'app/core/config',
  6. ], function(helpers, shareModalCtrl, linkSrv, config) {
  7. 'use strict';
  8. describe('ShareModalCtrl', function() {
  9. var ctx = new helpers.ControllerTestContext();
  10. function setTime(range) {
  11. ctx.timeSrv.timeRange = sinon.stub().returns(range);
  12. }
  13. beforeEach(function() {
  14. config.bootData = {
  15. user: {
  16. orgId: 1
  17. }
  18. };
  19. });
  20. setTime({ from: new Date(1000), to: new Date(2000) });
  21. beforeEach(module('grafana.controllers'));
  22. beforeEach(module('grafana.services'));
  23. beforeEach(module(function($compileProvider) {
  24. $compileProvider.preAssignBindingsEnabled(true);
  25. }));
  26. beforeEach(ctx.providePhase());
  27. beforeEach(ctx.createControllerPhase('ShareModalCtrl'));
  28. describe('shareUrl with current time range and panel', function() {
  29. it('should generate share url absolute time', function() {
  30. ctx.$location.path('/test');
  31. ctx.scope.panel = { id: 22 };
  32. ctx.scope.init();
  33. expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&panelId=22&fullscreen');
  34. });
  35. it('should generate render url', function() {
  36. ctx.$location.$$absUrl = 'http://dashboards.grafana.com/dashboard/db/my-dash';
  37. ctx.scope.panel = { id: 22 };
  38. ctx.scope.init();
  39. var base = 'http://dashboards.grafana.com/render/dashboard-solo/db/my-dash';
  40. var params = '?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
  41. expect(ctx.scope.imageUrl).to.contain(base + params);
  42. });
  43. it('should remove panel id when no panel in scope', function() {
  44. ctx.$location.path('/test');
  45. ctx.scope.options.forCurrent = true;
  46. ctx.scope.panel = null;
  47. ctx.scope.init();
  48. expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1');
  49. });
  50. it('should add theme when specified', function() {
  51. ctx.$location.path('/test');
  52. ctx.scope.options.theme = 'light';
  53. ctx.scope.panel = null;
  54. ctx.scope.init();
  55. expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&theme=light');
  56. });
  57. it('should remove fullscreen from image url when is first param in querystring and modeSharePanel is true', function() {
  58. ctx.$location.url('/test?fullscreen&edit');
  59. ctx.scope.modeSharePanel = true;
  60. ctx.scope.panel = { id: 1 };
  61. ctx.scope.buildUrl();
  62. expect(ctx.scope.shareUrl).to.contain('?fullscreen&edit&from=1000&to=2000&orgId=1&panelId=1');
  63. expect(ctx.scope.imageUrl).to.contain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');
  64. });
  65. it('should remove edit from image url when is first param in querystring and modeSharePanel is true', function() {
  66. ctx.$location.url('/test?edit&fullscreen');
  67. ctx.scope.modeSharePanel = true;
  68. ctx.scope.panel = { id: 1 };
  69. ctx.scope.buildUrl();
  70. expect(ctx.scope.shareUrl).to.contain('?edit&fullscreen&from=1000&to=2000&orgId=1&panelId=1');
  71. expect(ctx.scope.imageUrl).to.contain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');
  72. });
  73. it('should include template variables in url', function() {
  74. ctx.$location.path('/test');
  75. ctx.scope.options.includeTemplateVars = true;
  76. ctx.templateSrv.fillVariableValuesForUrl = function(params) {
  77. params['var-app'] = 'mupp';
  78. params['var-server'] = 'srv-01';
  79. };
  80. ctx.scope.buildUrl();
  81. expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&var-app=mupp&var-server=srv-01');
  82. });
  83. });
  84. });
  85. });