mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tests: migrated tests for link_srv to jest, #9666
This commit is contained in:
parent
f097bce565
commit
ec94dfa890
@ -5,8 +5,7 @@ import kbn from 'app/core/utils/kbn';
|
|||||||
export class LinkSrv {
|
export class LinkSrv {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private templateSrv, private timeSrv) {
|
constructor(private templateSrv, private timeSrv) {}
|
||||||
}
|
|
||||||
|
|
||||||
getLinkUrl(link) {
|
getLinkUrl(link) {
|
||||||
var url = this.templateSrv.replace(link.url || '');
|
var url = this.templateSrv.replace(link.url || '');
|
||||||
@ -29,7 +28,9 @@ export class LinkSrv {
|
|||||||
var paramsArray = [];
|
var paramsArray = [];
|
||||||
|
|
||||||
_.each(params, function(value, key) {
|
_.each(params, function(value, key) {
|
||||||
if (value === null) { return; }
|
if (value === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (value === true) {
|
if (value === true) {
|
||||||
paramsArray.push(key);
|
paramsArray.push(key);
|
||||||
} else if (_.isArray(value)) {
|
} else if (_.isArray(value)) {
|
||||||
@ -107,7 +108,6 @@ export class LinkSrv {
|
|||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
angular.module('grafana.services').service('linkSrv', LinkSrv);
|
angular.module('grafana.services').service('linkSrv', LinkSrv);
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
import {describe, beforeEach, it, expect, angularMocks} from 'test/lib/common';
|
|
||||||
import 'app/features/panellinks/link_srv';
|
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
describe('linkSrv', function() {
|
|
||||||
var _linkSrv;
|
|
||||||
|
|
||||||
beforeEach(angularMocks.module('grafana.core'));
|
|
||||||
beforeEach(angularMocks.module('grafana.services'));
|
|
||||||
|
|
||||||
beforeEach(angularMocks.inject(function(linkSrv) {
|
|
||||||
_linkSrv = linkSrv;
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('when appending query strings', function() {
|
|
||||||
|
|
||||||
it('add ? to URL if not present', function() {
|
|
||||||
var url = _linkSrv.appendToQueryString('http://example.com', 'foo=bar');
|
|
||||||
expect(url).to.be('http://example.com?foo=bar');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('do not add & to URL if ? is present but query string is empty', function() {
|
|
||||||
var url = _linkSrv.appendToQueryString('http://example.com?', 'foo=bar');
|
|
||||||
expect(url).to.be('http://example.com?foo=bar');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('add & to URL if query string is present', function() {
|
|
||||||
var url = _linkSrv.appendToQueryString('http://example.com?foo=bar', 'hello=world');
|
|
||||||
expect(url).to.be('http://example.com?foo=bar&hello=world');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('do not change the URL if there is nothing to append', function() {
|
|
||||||
_.each(['', undefined, null], function(toAppend) {
|
|
||||||
var url1 = _linkSrv.appendToQueryString('http://example.com', toAppend);
|
|
||||||
expect(url1).to.be('http://example.com');
|
|
||||||
|
|
||||||
var url2 = _linkSrv.appendToQueryString('http://example.com?', toAppend);
|
|
||||||
expect(url2).to.be('http://example.com?');
|
|
||||||
|
|
||||||
var url3 = _linkSrv.appendToQueryString('http://example.com?foo=bar', toAppend);
|
|
||||||
expect(url3).to.be('http://example.com?foo=bar');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user