chartZoom.spec.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import ChartZoom from 'app/components/charts/chartZoom';
  4. import ConfigStore from 'app/stores/configStore';
  5. describe('ChartZoom', function() {
  6. let renderFunc = jest.fn(() => null);
  7. let routerContext = TestStubs.routerContext();
  8. let axisLabelFormatter;
  9. let tooltipFormatter;
  10. const timestamp = 1531094400000;
  11. beforeAll(function() {
  12. ConfigStore.loadInitialData({
  13. user: {options: {timezone: 'America/Los_Angeles'}},
  14. });
  15. });
  16. beforeEach(function() {
  17. renderFunc.mockClear();
  18. });
  19. describe('With Period > 24h', function() {
  20. describe('Local timezone', function() {
  21. beforeEach(function() {
  22. mount(
  23. <ChartZoom period="7d" utc={false}>
  24. {renderFunc}
  25. </ChartZoom>,
  26. routerContext
  27. );
  28. axisLabelFormatter = renderFunc.mock.calls[0][0].xAxis.axisLabel.formatter;
  29. tooltipFormatter = renderFunc.mock.calls[0][0].tooltip.formatAxisLabel;
  30. });
  31. it('formats axis label for first data point', function() {
  32. expect(axisLabelFormatter(timestamp, 0)).toEqual('Jul 8, 2018 5:00 PM');
  33. });
  34. it('formats axis label for second data point', function() {
  35. expect(axisLabelFormatter(timestamp, 1)).toEqual('Jul 8, 2018 5:00 PM');
  36. });
  37. it('formats tooltip', function() {
  38. expect(tooltipFormatter(timestamp, true, false)).toEqual('Jul 8, 2018 5:00 PM');
  39. });
  40. });
  41. describe('UTC', function() {
  42. beforeEach(function() {
  43. mount(
  44. <ChartZoom period="7d" utc={true}>
  45. {renderFunc}
  46. </ChartZoom>,
  47. routerContext
  48. );
  49. axisLabelFormatter = renderFunc.mock.calls[0][0].xAxis.axisLabel.formatter;
  50. tooltipFormatter = renderFunc.mock.calls[0][0].tooltip.formatAxisLabel;
  51. });
  52. it('formats axis label for first data point', function() {
  53. expect(axisLabelFormatter(timestamp, 0)).toEqual('Jul 9, 2018 12:00 AM');
  54. });
  55. it('formats axis label for second data point', function() {
  56. expect(axisLabelFormatter(timestamp, 1)).toEqual('Jul 9, 2018 12:00 AM');
  57. });
  58. it('formats tooltip', function() {
  59. expect(tooltipFormatter(timestamp, true, true)).toEqual('Jul 9, 2018 12:00 AM');
  60. });
  61. });
  62. });
  63. describe('With Period <= 24h', function() {
  64. describe('Local timezone', function() {
  65. beforeEach(function() {
  66. mount(
  67. <ChartZoom period="24h" utc={false}>
  68. {renderFunc}
  69. </ChartZoom>,
  70. routerContext
  71. );
  72. axisLabelFormatter = renderFunc.mock.calls[0][0].xAxis.axisLabel.formatter;
  73. tooltipFormatter = renderFunc.mock.calls[0][0].tooltip.formatAxisLabel;
  74. });
  75. it('formats axis label for first data point', function() {
  76. expect(axisLabelFormatter(timestamp, 0)).toEqual('Jul 8, 2018 5:00 PM');
  77. });
  78. it('formats axis label for second data point', function() {
  79. expect(axisLabelFormatter(timestamp, 1)).toEqual('5:00 PM');
  80. });
  81. it('formats tooltip', function() {
  82. expect(tooltipFormatter(timestamp, true, false)).toEqual('Jul 8, 2018 5:00 PM');
  83. });
  84. });
  85. describe('UTC', function() {
  86. beforeEach(function() {
  87. mount(
  88. <ChartZoom period="24h" utc={true}>
  89. {renderFunc}
  90. </ChartZoom>,
  91. routerContext
  92. );
  93. axisLabelFormatter = renderFunc.mock.calls[0][0].xAxis.axisLabel.formatter;
  94. tooltipFormatter = renderFunc.mock.calls[0][0].tooltip.formatAxisLabel;
  95. });
  96. it('formats axis label for first data point', function() {
  97. expect(axisLabelFormatter(timestamp, 0)).toEqual('Jul 9, 2018 12:00 AM');
  98. });
  99. it('formats axis label for second data point', function() {
  100. expect(axisLabelFormatter(timestamp, 1)).toEqual('12:00 AM');
  101. });
  102. it('formats tooltip', function() {
  103. expect(tooltipFormatter(timestamp, true, true)).toEqual('Jul 9, 2018 12:00 AM');
  104. });
  105. });
  106. });
  107. });