linkSrv-specs.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. define([
  2. 'lodash',
  3. 'app/features/panellinks/linkSrv'
  4. ], function(_) {
  5. 'use strict';
  6. describe('linkSrv', function() {
  7. var _linkSrv;
  8. beforeEach(module('grafana.services'));
  9. beforeEach(inject(function(linkSrv) {
  10. _linkSrv = linkSrv;
  11. }));
  12. describe('when appending query strings', function() {
  13. it('add ? to URL if not present', function() {
  14. var url = _linkSrv.appendToQueryString('http://example.com', 'foo=bar');
  15. expect(url).to.be('http://example.com?foo=bar');
  16. });
  17. it('do not add & to URL if ? is present but query string is empty', function() {
  18. var url = _linkSrv.appendToQueryString('http://example.com?', 'foo=bar');
  19. expect(url).to.be('http://example.com?foo=bar');
  20. });
  21. it('add & to URL if query string is present', function() {
  22. var url = _linkSrv.appendToQueryString('http://example.com?foo=bar', 'hello=world');
  23. expect(url).to.be('http://example.com?foo=bar&hello=world');
  24. });
  25. it('do not change the URL if there is nothing to append', function() {
  26. _.each(['', undefined, null], function(toAppend) {
  27. var url1 = _linkSrv.appendToQueryString('http://example.com', toAppend);
  28. expect(url1).to.be('http://example.com');
  29. var url2 = _linkSrv.appendToQueryString('http://example.com?', toAppend);
  30. expect(url2).to.be('http://example.com?');
  31. var url3 = _linkSrv.appendToQueryString('http://example.com?foo=bar', toAppend);
  32. expect(url3).to.be('http://example.com?foo=bar');
  33. });
  34. });
  35. });
  36. });
  37. });