graph-tooltip-specs.js 2.9 KB

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