share_modal_ctrl_specs.ts 3.9 KB

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