influxdbQueryCtrl-specs.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. define([
  2. 'helpers',
  3. 'plugins/datasource/influxdb/queryCtrl'
  4. ], function(helpers) {
  5. 'use strict';
  6. describe('InfluxDBQueryCtrl', function() {
  7. var ctx = new helpers.ControllerTestContext();
  8. beforeEach(module('grafana.controllers'));
  9. beforeEach(ctx.providePhase());
  10. beforeEach(ctx.createControllerPhase('InfluxQueryCtrl'));
  11. beforeEach(function() {
  12. ctx.scope.target = {};
  13. ctx.scope.$parent = { get_data: sinon.spy() };
  14. ctx.scope.datasource = ctx.datasource;
  15. ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
  16. });
  17. describe('init', function() {
  18. beforeEach(function() {
  19. ctx.scope.init();
  20. });
  21. it('should init tagSegments', function() {
  22. expect(ctx.scope.tagSegments.length).to.be(1);
  23. });
  24. it('should init measurementSegment', function() {
  25. expect(ctx.scope.measurementSegment.value).to.be('select measurement');
  26. });
  27. });
  28. describe('when first tag segment is updated', function() {
  29. beforeEach(function() {
  30. ctx.scope.init();
  31. ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
  32. });
  33. it('should update tag key', function() {
  34. expect(ctx.scope.target.tags[0].key).to.be('asd');
  35. expect(ctx.scope.tagSegments[0].type).to.be('key');
  36. });
  37. it('should add tagSegments', function() {
  38. expect(ctx.scope.tagSegments.length).to.be(3);
  39. });
  40. });
  41. describe('when last tag value segment is updated', function() {
  42. beforeEach(function() {
  43. ctx.scope.init();
  44. ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button'}, 0);
  45. ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
  46. });
  47. it('should update tag value', function() {
  48. expect(ctx.scope.target.tags[0].value).to.be('server1');
  49. });
  50. it('should add plus button for another filter', function() {
  51. expect(ctx.scope.tagSegments[3].fake).to.be(true);
  52. });
  53. });
  54. describe('when second tag key is added', function() {
  55. beforeEach(function() {
  56. ctx.scope.init();
  57. ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
  58. ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
  59. ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
  60. });
  61. it('should update tag key', function() {
  62. expect(ctx.scope.target.tags[1].key).to.be('key2');
  63. });
  64. it('should add AND segment', function() {
  65. expect(ctx.scope.tagSegments[3].value).to.be('AND');
  66. });
  67. });
  68. describe('when condition is changed', function() {
  69. beforeEach(function() {
  70. ctx.scope.init();
  71. ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
  72. ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
  73. ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
  74. ctx.scope.tagSegmentUpdated({value: 'OR', type: 'condition'}, 3);
  75. });
  76. it('should update tag condition', function() {
  77. expect(ctx.scope.target.tags[1].condition).to.be('OR');
  78. });
  79. it('should update AND segment', function() {
  80. expect(ctx.scope.tagSegments[3].value).to.be('OR');
  81. expect(ctx.scope.tagSegments.length).to.be(7);
  82. });
  83. });
  84. describe('when deleting first tag filter after value is selected', function() {
  85. beforeEach(function() {
  86. ctx.scope.init();
  87. ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
  88. ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
  89. ctx.scope.tagSegmentUpdated(ctx.scope.removeTagFilterSegment, 0);
  90. });
  91. it('should remove tags', function() {
  92. expect(ctx.scope.target.tags.length).to.be(0);
  93. });
  94. it('should remove all segment after 2 and replace with plus button', function() {
  95. expect(ctx.scope.tagSegments.length).to.be(1);
  96. expect(ctx.scope.tagSegments[0].type).to.be('plus-button');
  97. });
  98. });
  99. describe('when deleting second tag value before second tag value is complete', function() {
  100. beforeEach(function() {
  101. ctx.scope.init();
  102. ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
  103. ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
  104. ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
  105. ctx.scope.tagSegmentUpdated(ctx.scope.removeTagFilterSegment, 4);
  106. });
  107. it('should remove all segment after 2 and replace with plus button', function() {
  108. expect(ctx.scope.tagSegments.length).to.be(4);
  109. expect(ctx.scope.tagSegments[3].type).to.be('plus-button');
  110. });
  111. });
  112. describe('when deleting second tag value before second tag value is complete', function() {
  113. beforeEach(function() {
  114. ctx.scope.init();
  115. ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
  116. ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
  117. ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
  118. ctx.scope.tagSegmentUpdated(ctx.scope.removeTagFilterSegment, 4);
  119. });
  120. it('should remove all segment after 2 and replace with plus button', function() {
  121. expect(ctx.scope.tagSegments.length).to.be(4);
  122. expect(ctx.scope.tagSegments[3].type).to.be('plus-button');
  123. });
  124. });
  125. describe('when deleting second tag value after second tag filter is complete', function() {
  126. beforeEach(function() {
  127. ctx.scope.init();
  128. ctx.scope.tagSegmentUpdated({value: 'asd', type: 'plus-button' }, 0);
  129. ctx.scope.tagSegmentUpdated({value: 'server1', type: 'value'}, 2);
  130. ctx.scope.tagSegmentUpdated({value: 'key2', type: 'plus-button'}, 3);
  131. ctx.scope.tagSegmentUpdated({value: 'value', type: 'value'}, 6);
  132. ctx.scope.tagSegmentUpdated(ctx.scope.removeTagFilterSegment, 4);
  133. });
  134. it('should remove all segment after 2 and replace with plus button', function() {
  135. expect(ctx.scope.tagSegments.length).to.be(4);
  136. expect(ctx.scope.tagSegments[3].type).to.be('plus-button');
  137. });
  138. });
  139. describe('when adding group by', function() {
  140. beforeEach(function() {
  141. ctx.scope.init();
  142. ctx.scope.groupByTagUpdated({value: 'host', type: 'plus-button' }, 0);
  143. });
  144. it('should add group by', function() {
  145. expect(ctx.scope.target.groupByTags.length).to.be(1);
  146. expect(ctx.scope.target.groupByTags[0]).to.be('host');
  147. });
  148. it('should add another plus button segment', function() {
  149. expect(ctx.scope.groupBySegments[1].type).to.be('plus-button');
  150. });
  151. });
  152. describe('when removing group by', function() {
  153. beforeEach(function() {
  154. ctx.scope.init();
  155. ctx.scope.groupByTagUpdated({value: 'host', type: 'plus-button' }, 0);
  156. ctx.scope.groupByTagUpdated(ctx.scope.removeGroupBySegment, 0);
  157. });
  158. it('should add group by', function() {
  159. expect(ctx.scope.target.groupByTags.length).to.be(0);
  160. });
  161. it('should remove segment', function() {
  162. expect(ctx.scope.groupBySegments.length).to.be(1);
  163. expect(ctx.scope.groupBySegments[0].type).to.be('plus-button');
  164. });
  165. });
  166. });
  167. });