templateSrv-specs.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. define([
  2. 'mocks/dashboard-mock',
  3. 'lodash',
  4. 'services/templateSrv'
  5. ], function(dashboardMock) {
  6. 'use strict';
  7. describe('templateSrv', function() {
  8. var _templateSrv;
  9. var _dashboard;
  10. beforeEach(module('grafana.services'));
  11. beforeEach(module(function() {
  12. _dashboard = dashboardMock.create();
  13. }));
  14. beforeEach(inject(function(templateSrv) {
  15. _templateSrv = templateSrv;
  16. }));
  17. beforeEach(function() {
  18. _templateSrv.init(_dashboard);
  19. });
  20. describe('init', function() {
  21. beforeEach(function() {
  22. _templateSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } });
  23. });
  24. it('should initialize template data', function() {
  25. var target = _templateSrv.replace('this.[[test]].filters');
  26. expect(target).to.be('this.oogle.filters');
  27. });
  28. });
  29. describe('updateTemplateData', function() {
  30. beforeEach(function() {
  31. _templateSrv.addTemplateParameter({
  32. name: 'test',
  33. value: 'muuu',
  34. current: { value: 'muuuu' }
  35. });
  36. _templateSrv.updateTemplateData();
  37. });
  38. it('should set current value and update template data', function() {
  39. var target = _templateSrv.replace('this.[[test]].filters');
  40. expect(target).to.be('this.muuuu.filters');
  41. });
  42. });
  43. });
  44. });