graph-tooltip-specs.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. define([
  2. 'jquery',
  3. 'app/plugins/panel/graph/graph.tooltip'
  4. ], function($, GraphTooltip) {
  5. 'use strict';
  6. var scope = {
  7. appEvent: sinon.spy(),
  8. onAppEvent: sinon.spy(),
  9. };
  10. var elem = $('<div></div>');
  11. var dashboard = { };
  12. function describeSharedTooltip(desc, fn) {
  13. var ctx = {};
  14. ctx.scope = scope;
  15. ctx.scope.panel = {
  16. tooltip: {
  17. shared: true
  18. },
  19. legend: { },
  20. stack: false
  21. };
  22. ctx.setup = function(setupFn) {
  23. ctx.setupFn = setupFn;
  24. };
  25. describe(desc, function() {
  26. beforeEach(function() {
  27. ctx.setupFn();
  28. var tooltip = new GraphTooltip(elem, dashboard, scope);
  29. ctx.results = tooltip.getMultiSeriesPlotHoverInfo(ctx.data, ctx.pos);
  30. });
  31. fn(ctx);
  32. });
  33. }
  34. describeSharedTooltip("steppedLine false, stack false", function(ctx) {
  35. ctx.setup(function() {
  36. ctx.data = [
  37. { data: [[10, 15], [12, 20]], lines: {} },
  38. { data: [[10, 2], [12, 3]], lines: {} }
  39. ];
  40. ctx.pos = { x: 11 };
  41. });
  42. it('should return 2 series', function() {
  43. expect(ctx.results.length).to.be(2);
  44. });
  45. it('should add time to results array', function() {
  46. expect(ctx.results.time).to.be(10);
  47. });
  48. it('should set value and hoverIndex', function() {
  49. expect(ctx.results[0].value).to.be(15);
  50. expect(ctx.results[1].value).to.be(2);
  51. expect(ctx.results[0].hoverIndex).to.be(0);
  52. });
  53. });
  54. describeSharedTooltip("one series is hidden", function(ctx) {
  55. ctx.setup(function() {
  56. ctx.data = [
  57. { data: [[10, 15], [12, 20]], },
  58. { data: [] }
  59. ];
  60. ctx.pos = { x: 11 };
  61. });
  62. });
  63. describeSharedTooltip("steppedLine false, stack true, individual false", function(ctx) {
  64. ctx.setup(function() {
  65. ctx.data = [
  66. {
  67. data: [[10, 15], [12, 20]],
  68. lines: {},
  69. datapoints: {
  70. pointsize: 2,
  71. points: [[10,15], [12,20]],
  72. },
  73. stack: true,
  74. },
  75. {
  76. data: [[10, 2], [12, 3]],
  77. lines: {},
  78. datapoints: {
  79. pointsize: 2,
  80. points: [[10, 2], [12, 3]],
  81. },
  82. stack: true
  83. }
  84. ];
  85. ctx.scope.panel.stack = true;
  86. ctx.pos = { x: 11 };
  87. });
  88. it('should show stacked value', function() {
  89. expect(ctx.results[1].value).to.be(17);
  90. });
  91. });
  92. describeSharedTooltip("steppedLine false, stack true, individual false, series stack false", function(ctx) {
  93. ctx.setup(function() {
  94. ctx.data = [
  95. {
  96. data: [[10, 15], [12, 20]],
  97. lines: {},
  98. datapoints: {
  99. pointsize: 2,
  100. points: [[10, 15], [12, 20]],
  101. },
  102. stack: true
  103. },
  104. {
  105. data: [[10, 2], [12, 3]],
  106. lines: {},
  107. datapoints: {
  108. pointsize: 2,
  109. points: [[10, 2], [12, 3]],
  110. },
  111. stack: false
  112. }
  113. ];
  114. ctx.scope.panel.stack = true;
  115. ctx.pos = { x: 11 };
  116. });
  117. it('should not show stacked value', function() {
  118. expect(ctx.results[1].value).to.be(2);
  119. });
  120. });
  121. describeSharedTooltip("steppedLine false, stack true, individual true", function(ctx) {
  122. ctx.setup(function() {
  123. ctx.data = [
  124. {
  125. data: [[10, 15], [12, 20]],
  126. lines: {},
  127. datapoints: {
  128. pointsize: 2,
  129. points: [[10, 15], [12, 20]],
  130. },
  131. stack: true
  132. },
  133. {
  134. data: [[10, 2], [12, 3]],
  135. lines: {},
  136. datapoints: {
  137. pointsize: 2,
  138. points: [[10, 2], [12, 3]],
  139. },
  140. stack: false
  141. }
  142. ];
  143. ctx.scope.panel.stack = true;
  144. ctx.scope.panel.tooltip.value_type = 'individual';
  145. ctx.pos = { x: 11 };
  146. });
  147. it('should not show stacked value', function() {
  148. expect(ctx.results[1].value).to.be(2);
  149. });
  150. });
  151. });