tooltip_specs.ts 3.7 KB

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