graph-tooltip-specs.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. define([
  2. 'jquery',
  3. '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("point count missmatch", function(ctx) {
  55. ctx.setup(function() {
  56. ctx.data = [
  57. { data: [[10, 15], [12, 20]], },
  58. { data: [[10, 2]] }
  59. ];
  60. ctx.pos = { x: 11 };
  61. });
  62. it('should set pointCountMismatch to true', function() {
  63. expect(ctx.results.pointCountMismatch).to.be(true);
  64. });
  65. });
  66. describeSharedTooltip("one series is hidden", function(ctx) {
  67. ctx.setup(function() {
  68. ctx.data = [
  69. { data: [[10, 15], [12, 20]], },
  70. { data: [] }
  71. ];
  72. ctx.pos = { x: 11 };
  73. });
  74. it('should set pointCountMismatch to false', function() {
  75. expect(ctx.results.pointCountMismatch).to.be(undefined);
  76. });
  77. });
  78. describeSharedTooltip("steppedLine false, stack true, individual false", function(ctx) {
  79. ctx.setup(function() {
  80. ctx.data = [
  81. { data: [[10, 15], [12, 20]], },
  82. { data: [[10, 2], [12, 3]], }
  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 true", function(ctx) {
  92. ctx.setup(function() {
  93. ctx.data = [
  94. { data: [[10, 15], [12, 20]], },
  95. { data: [[10, 2], [12, 3]], }
  96. ];
  97. ctx.scope.panel.stack = true;
  98. ctx.scope.panel.tooltip.value_type = 'individual';
  99. ctx.pos = { x: 11 };
  100. });
  101. it('should not show stacked value', function() {
  102. expect(ctx.results[1].value).to.be(2);
  103. });
  104. });
  105. });