graph-tooltip-specs.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. define([
  2. 'jquery',
  3. 'app/panels/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]], },
  38. { data: [[10, 2], [12, 3]], }
  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. datapoints: {
  69. pointsize: 2,
  70. points: [[10,15], [12,20]],
  71. },
  72. stack: true,
  73. },
  74. {
  75. data: [[10, 2], [12, 3]],
  76. datapoints: {
  77. pointsize: 2,
  78. points: [[10, 2], [12, 3]],
  79. },
  80. stack: true
  81. }
  82. ];
  83. ctx.scope.panel.stack = true;
  84. ctx.pos = { x: 11 };
  85. });
  86. it('should show stacked value', function() {
  87. expect(ctx.results[1].value).to.be(17);
  88. });
  89. });
  90. describeSharedTooltip("steppedLine false, stack true, individual false, series stack false", function(ctx) {
  91. ctx.setup(function() {
  92. ctx.data = [
  93. {
  94. data: [[10, 15], [12, 20]],
  95. datapoints: {
  96. pointsize: 2,
  97. points: [[10, 15], [12, 20]],
  98. },
  99. stack: true
  100. },
  101. {
  102. data: [[10, 2], [12, 3]],
  103. datapoints: {
  104. pointsize: 2,
  105. points: [[10, 2], [12, 3]],
  106. },
  107. stack: false
  108. }
  109. ];
  110. ctx.scope.panel.stack = true;
  111. ctx.pos = { x: 11 };
  112. });
  113. it('should not show stacked value', function() {
  114. expect(ctx.results[1].value).to.be(2);
  115. });
  116. });
  117. describeSharedTooltip("steppedLine false, stack true, individual true", function(ctx) {
  118. ctx.setup(function() {
  119. ctx.data = [
  120. {
  121. data: [[10, 15], [12, 20]],
  122. datapoints: {
  123. pointsize: 2,
  124. points: [[10, 15], [12, 20]],
  125. },
  126. stack: true
  127. },
  128. {
  129. data: [[10, 2], [12, 3]],
  130. datapoints: {
  131. pointsize: 2,
  132. points: [[10, 2], [12, 3]],
  133. },
  134. stack: false
  135. }
  136. ];
  137. ctx.scope.panel.stack = true;
  138. ctx.scope.panel.tooltip.value_type = 'individual';
  139. ctx.pos = { x: 11 };
  140. });
  141. it('should not show stacked value', function() {
  142. expect(ctx.results[1].value).to.be(2);
  143. });
  144. });
  145. });