templateValuesSrv-specs.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. define([
  2. '../mocks/dashboard-mock',
  3. './helpers',
  4. 'app/features/templating/templateValuesSrv'
  5. ], function(dashboardMock, helpers) {
  6. 'use strict';
  7. describe('templateValuesSrv', function() {
  8. var ctx = new helpers.ServiceTestContext();
  9. beforeEach(module('grafana.services'));
  10. beforeEach(ctx.providePhase(['datasourceSrv', 'timeSrv', 'templateSrv', '$location']));
  11. beforeEach(ctx.createService('templateValuesSrv'));
  12. describe('when template variable is present in url', function() {
  13. describe('and setting simple variable', function() {
  14. var variable = {
  15. name: 'apps',
  16. current: {text: "test", value: "test"},
  17. options: [{text: "test", value: "test"}]
  18. };
  19. beforeEach(function(done) {
  20. var dashboard = { templating: { list: [variable] } };
  21. var urlParams = {};
  22. urlParams["var-apps"] = "new";
  23. ctx.$location.search = sinon.stub().returns(urlParams);
  24. ctx.service.init(dashboard).then(function() { done(); });
  25. ctx.$rootScope.$digest();
  26. });
  27. it('should update current value', function() {
  28. expect(variable.current.value).to.be("new");
  29. expect(variable.current.text).to.be("new");
  30. });
  31. });
  32. // describe('and setting adhoc variable', function() {
  33. // var variable = {name: 'filters', type: 'adhoc'};
  34. //
  35. // beforeEach(function(done) {
  36. // var dashboard = { templating: { list: [variable] } };
  37. // var urlParams = {};
  38. // urlParams["var-filters"] = "hostname|gt|server2";
  39. // ctx.$location.search = sinon.stub().returns(urlParams);
  40. // ctx.service.init(dashboard).then(function() { done(); });
  41. // ctx.$rootScope.$digest();
  42. // });
  43. //
  44. // it('should update current value', function() {
  45. // expect(variable.tags[0]).to.eq({tag: 'hostname', value: 'server2'});
  46. // });
  47. // });
  48. });
  49. });
  50. });