share_modal_ctrl_specs.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/linkSrv';
  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(angularMocks.module(function($compileProvider) {
  22. $compileProvider.preAssignBindingsEnabled(true);
  23. }));
  24. beforeEach(ctx.providePhase());
  25. beforeEach(ctx.createControllerPhase('ShareModalCtrl'));
  26. describe('shareUrl with current time range and panel', function() {
  27. it('should generate share url absolute time', function() {
  28. ctx.$location.path('/test');
  29. ctx.scope.panel = { id: 22 };
  30. ctx.scope.init();
  31. expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&panelId=22&fullscreen');
  32. });
  33. it('should generate render url', function() {
  34. ctx.$location.$$absUrl = 'http://dashboards.grafana.com/dashboard/db/my-dash';
  35. ctx.scope.panel = { id: 22 };
  36. ctx.scope.init();
  37. var base = 'http://dashboards.grafana.com/render/dashboard-solo/db/my-dash';
  38. var params = '?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
  39. expect(ctx.scope.imageUrl).to.contain(base + params);
  40. });
  41. it('should remove panel id when no panel in scope', function() {
  42. ctx.$location.path('/test');
  43. ctx.scope.options.forCurrent = true;
  44. ctx.scope.panel = null;
  45. ctx.scope.init();
  46. expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1');
  47. });
  48. it('should add theme when specified', function() {
  49. ctx.$location.path('/test');
  50. ctx.scope.options.theme = 'light';
  51. ctx.scope.panel = null;
  52. ctx.scope.init();
  53. expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&theme=light');
  54. });
  55. it('should remove fullscreen from image url when is first param in querystring and modeSharePanel is true', function() {
  56. ctx.$location.url('/test?fullscreen&edit');
  57. ctx.scope.modeSharePanel = true;
  58. ctx.scope.panel = { id: 1 };
  59. ctx.scope.buildUrl();
  60. expect(ctx.scope.shareUrl).to.contain('?fullscreen&edit&from=1000&to=2000&orgId=1&panelId=1');
  61. expect(ctx.scope.imageUrl).to.contain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');
  62. });
  63. it('should remove edit from image url when is first param in querystring and modeSharePanel is true', function() {
  64. ctx.$location.url('/test?edit&fullscreen');
  65. ctx.scope.modeSharePanel = true;
  66. ctx.scope.panel = { id: 1 };
  67. ctx.scope.buildUrl();
  68. expect(ctx.scope.shareUrl).to.contain('?edit&fullscreen&from=1000&to=2000&orgId=1&panelId=1');
  69. expect(ctx.scope.imageUrl).to.contain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');
  70. });
  71. it('should include template variables in url', function() {
  72. ctx.$location.path('/test');
  73. ctx.scope.options.includeTemplateVars = true;
  74. ctx.templateSrv.fillVariableValuesForUrl = function(params) {
  75. params['var-app'] = 'mupp';
  76. params['var-server'] = 'srv-01';
  77. };
  78. ctx.scope.buildUrl();
  79. expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&var-app=mupp&var-server=srv-01');
  80. });
  81. });
  82. });