shareModalCtrl-specs.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 include template variables in url', function() {
  58. ctx.$location.path('/test');
  59. ctx.scope.options.includeTemplateVars = true;
  60. ctx.templateSrv.fillVariableValuesForUrl = function(params) {
  61. params['var-app'] = 'mupp';
  62. params['var-server'] = 'srv-01';
  63. };
  64. ctx.scope.buildUrl();
  65. expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&var-app=mupp&var-server=srv-01');
  66. });
  67. });
  68. });
  69. });