graph-tooltip-specs.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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("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. { data: [[10, 15], [12, 20]], },
  67. { data: [[10, 2], [12, 3]], }
  68. ];
  69. ctx.scope.panel.stack = true;
  70. ctx.pos = { x: 11 };
  71. });
  72. it('should show stacked value', function() {
  73. expect(ctx.results[1].value).to.be(17);
  74. });
  75. });
  76. describeSharedTooltip("steppedLine false, stack true, individual true", function(ctx) {
  77. ctx.setup(function() {
  78. ctx.data = [
  79. { data: [[10, 15], [12, 20]], },
  80. { data: [[10, 2], [12, 3]], }
  81. ];
  82. ctx.scope.panel.stack = true;
  83. ctx.scope.panel.tooltip.value_type = 'individual';
  84. ctx.pos = { x: 11 };
  85. });
  86. it('should not show stacked value', function() {
  87. expect(ctx.results[1].value).to.be(2);
  88. });
  89. });
  90. });