share_modal_ctrl_specs.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { describe, beforeEach, it, expect, sinon, angularMocks } from 'test/lib/common';
  2. import helpers from 'test/specs/helpers';
  3. import '../shareModalCtrl';
  4. import config from 'app/core/config';
  5. import 'app/features/panellinks/link_srv';
  6. describe('ShareModalCtrl', function() {
  7. var ctx = new helpers.ControllerTestContext();
  8. function setTime(range) {
  9. ctx.timeSrv.timeRange = sinon.stub().returns(range);
  10. }
  11. beforeEach(function() {
  12. config.bootData = {
  13. user: {
  14. orgId: 1,
  15. },
  16. };
  17. });
  18. setTime({ from: new Date(1000), to: new Date(2000) });
  19. beforeEach(angularMocks.module('grafana.controllers'));
  20. beforeEach(angularMocks.module('grafana.services'));
  21. beforeEach(
  22. angularMocks.module(function($compileProvider) {
  23. $compileProvider.preAssignBindingsEnabled(true);
  24. })
  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(
  82. 'http://server/#!/test?from=1000&to=2000&orgId=1&var-app=mupp&var-server=srv-01'
  83. );
  84. });
  85. });
  86. });