shareModalCtrl-specs.js 2.6 KB

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