panelSrv-specs.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. define([
  2. 'helpers',
  3. 'features/panel/panelSrv',
  4. ], function() {
  5. 'use strict';
  6. describe('PanelSrv', function() {
  7. var _panelSrv;
  8. var _panelScope;
  9. var _datasourceSrvStub;
  10. beforeEach(module('grafana.services'));
  11. beforeEach(module(function($provide) {
  12. _datasourceSrvStub = {
  13. getMetricSources: sinon.spy(),
  14. };
  15. $provide.value('datasourceSrv', _datasourceSrvStub);
  16. }));
  17. beforeEach(inject(function(panelSrv, $rootScope) {
  18. _panelSrv = panelSrv;
  19. _panelScope = $rootScope.$new();
  20. _panelScope.panel = {
  21. targets: [],
  22. };
  23. _panelScope.dashboardViewState = {
  24. registerPanel: sinon.spy(),
  25. };
  26. }));
  27. describe('init', function() {
  28. beforeEach(function() {
  29. _panelSrv.init(_panelScope);
  30. });
  31. describe('addDataQuery', function() {
  32. it('should add target', function() {
  33. _panelScope.addDataQuery();
  34. expect(_panelScope.panel.targets.length).to.be(1);
  35. });
  36. it('should set refId', function() {
  37. _panelScope.addDataQuery();
  38. expect(_panelScope.panel.targets[0].refId).to.be('A');
  39. });
  40. it('should set refId to first available letter', function() {
  41. _panelScope.panel.targets = [{refId: 'A'}];
  42. _panelScope.addDataQuery();
  43. expect(_panelScope.panel.targets[1].refId).to.be('B');
  44. });
  45. });
  46. });
  47. });
  48. });