stackedBarChart.spec.jsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import {shallow} from 'sentry-test/enzyme';
  3. import StackedBarChart from 'app/components/stackedBarChart';
  4. describe('StackedBarChart', function() {
  5. describe('render()', function() {
  6. it('renders with points data', function() {
  7. const points = [
  8. {x: 1439766000, y: [10]},
  9. {x: 1439769600, y: [20]},
  10. {x: 1439773200, y: [30]},
  11. ];
  12. const wrapper = shallow(<StackedBarChart points={points} />);
  13. const columns = wrapper.find('[data-test-id="chart-column"]');
  14. expect(columns).toHaveProperty('length', 3);
  15. expect(columns.at(0).text()).toEqual('10'); // check y values
  16. expect(columns.at(1).text()).toEqual('20');
  17. expect(columns.at(2).text()).toEqual('30');
  18. });
  19. it('renders with points and markers', function() {
  20. const points = [
  21. {x: 1439769600, y: [10]},
  22. {x: 1439773200, y: [20]},
  23. {x: 1439776800, y: [30]},
  24. ];
  25. const markers = [
  26. {x: 1439769600, className: 'first-seen', label: 'first seen'}, // matches first point
  27. {x: 1439776800, className: 'last-seen', label: 'last seen'}, // matches last point
  28. ];
  29. const wrapper = shallow(<StackedBarChart points={points} markers={markers} />);
  30. const columns = wrapper.find('[data-test-id="chart-column"]');
  31. expect(columns).toHaveProperty('length', 5);
  32. expect(columns.at(0).text()).toEqual('10');
  33. expect(columns.at(1).text()).toEqual('20');
  34. expect(columns.at(2).text()).toEqual('30');
  35. expect(columns.at(3).text()).toEqual('first seen');
  36. expect(columns.at(4).text()).toEqual('last seen');
  37. });
  38. it('renders with points and markers, when first and last seen are same data point', function() {
  39. const points = [{x: 1439776800, y: [30]}];
  40. const markers = [
  41. {x: 1439776800, className: 'first-seen', label: 'first seen'},
  42. {x: 1439776800, className: 'last-seen', label: 'last seen'},
  43. ];
  44. const wrapper = shallow(<StackedBarChart points={points} markers={markers} />);
  45. const columns = wrapper.find('[data-test-id="chart-column"]');
  46. expect(columns).toHaveProperty('length', 3);
  47. expect(columns.at(0).text()).toEqual('30');
  48. expect(columns.at(1).text()).toEqual('first seen');
  49. expect(columns.at(2).text()).toEqual('last seen');
  50. });
  51. });
  52. });