stackedBarChart.spec.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import StackedBarChart from 'app/components/stackedBarChart';
  4. import ConfigStore from 'app/stores/configStore';
  5. describe('StackedBarChart', function() {
  6. describe('render()', function() {
  7. it('renders with points data', function() {
  8. const points = [
  9. {x: 1439766000, y: [10]},
  10. {x: 1439769600, y: [20]},
  11. {x: 1439773200, y: [30]},
  12. ];
  13. const wrapper = mountWithTheme(<StackedBarChart points={points} />);
  14. const columns = wrapper.find('[data-test-id="chart-column"]');
  15. expect(columns).toHaveProperty('length', 3);
  16. expect(columns.at(0).text()).toEqual('10'); // check y values
  17. expect(columns.at(1).text()).toEqual('20');
  18. expect(columns.at(2).text()).toEqual('30');
  19. });
  20. it('renders with points and markers', function() {
  21. const points = [
  22. {x: 1439769600, y: [10]},
  23. {x: 1439773200, y: [20]},
  24. {x: 1439776800, y: [30]},
  25. ];
  26. const markers = [
  27. {x: 1439769600, className: 'first-seen', label: 'first seen'}, // matches first point
  28. {x: 1439776800, className: 'last-seen', label: 'last seen'}, // matches last point
  29. ];
  30. const wrapper = mountWithTheme(
  31. <StackedBarChart points={points} markers={markers} />
  32. );
  33. const columns = wrapper.find('[data-test-id="chart-column"]');
  34. expect(columns).toHaveProperty('length', 5);
  35. expect(columns.at(0).text()).toEqual('10');
  36. expect(columns.at(1).text()).toEqual('20');
  37. expect(columns.at(2).text()).toEqual('30');
  38. expect(columns.at(3).text()).toEqual('first seen');
  39. expect(columns.at(4).text()).toEqual('last seen');
  40. });
  41. it('renders with points and markers, when first and last seen are same data point', function() {
  42. const points = [{x: 1439776800, y: [30]}];
  43. const markers = [
  44. {x: 1439776800, className: 'first-seen', label: 'first seen'},
  45. {x: 1439776800, className: 'last-seen', label: 'last seen'},
  46. ];
  47. const wrapper = mountWithTheme(
  48. <StackedBarChart points={points} markers={markers} />
  49. );
  50. const columns = wrapper.find('[data-test-id="chart-column"]');
  51. expect(columns).toHaveProperty('length', 3);
  52. expect(columns.at(0).text()).toEqual('30');
  53. expect(columns.at(1).text()).toEqual('first seen');
  54. expect(columns.at(2).text()).toEqual('last seen');
  55. });
  56. it('creates an AM/PM time label if use24Hours is disabled', function() {
  57. const marker = {x: 1439776800, className: 'first-seen', label: 'first seen'};
  58. const user = TestStubs.User();
  59. user.options.clock24Hours = false;
  60. ConfigStore.set('user', user);
  61. const wrapper = mountWithTheme(<StackedBarChart />);
  62. expect(wrapper.instance().timeLabelAsFull(marker)).toMatch(/[A|P]M/);
  63. });
  64. it('creates a 24h time label if use24Hours is enabled', function() {
  65. const marker = {x: 1439776800, className: 'first-seen', label: 'first seen'};
  66. const user = TestStubs.User();
  67. user.options.clock24Hours = true;
  68. ConfigStore.set('user', user);
  69. const wrapper = mountWithTheme(<StackedBarChart />);
  70. expect(wrapper.instance().timeLabelAsFull(marker)).not.toMatch(/[A|P]M/);
  71. });
  72. });
  73. });