index.spec.jsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import PanelChart from 'app/components/charts/panelChart';
  4. describe('PanelChart', function() {
  5. const SERIES = [
  6. {
  7. seriesName: 'Foo',
  8. data: [
  9. {value: 1, name: ''},
  10. {value: 2, name: ''},
  11. {value: 3, name: ''},
  12. {value: 4, name: ''},
  13. ],
  14. },
  15. {
  16. seriesName: 'Bar',
  17. data: [
  18. {value: 2, name: ''},
  19. {value: 3, name: ''},
  20. {value: 4, name: ''},
  21. {value: 5, name: ''},
  22. ],
  23. },
  24. ];
  25. const PREVIOUS = {
  26. seriesName: 'Previous',
  27. data: [
  28. {value: 2, name: ''},
  29. {value: 3, name: ''},
  30. {value: 4, name: ''},
  31. {value: 5, name: ''},
  32. ],
  33. };
  34. describe('renders', function() {
  35. let wrapper;
  36. beforeAll(function() {
  37. wrapper = mount(
  38. <PanelChart title="Panel Chart" series={SERIES} previousPeriod={PREVIOUS}>
  39. <div />
  40. </PanelChart>,
  41. TestStubs.routerContext()
  42. );
  43. });
  44. it('has title', function() {
  45. expect(wrapper.find('PanelHeader').contains('Panel Chart')).toBe(true);
  46. });
  47. it('has right legend items', function() {
  48. // Currently only support 1 line
  49. expect(wrapper.find('DottedLineIndicator')).toHaveLength(1);
  50. expect(
  51. wrapper
  52. .find('SeriesName')
  53. .at(0)
  54. .prop('children')
  55. ).toBe('Previous');
  56. expect(wrapper.find('CircleIndicator')).toHaveLength(2);
  57. expect(
  58. wrapper
  59. .find('SeriesName')
  60. .at(1)
  61. .prop('children')
  62. ).toBe('Foo');
  63. expect(
  64. wrapper
  65. .find('SeriesName')
  66. .at(2)
  67. .prop('children')
  68. ).toBe('Bar');
  69. });
  70. it('renders child', function() {
  71. expect(wrapper.find('ChartWrapper')).toHaveLength(1);
  72. });
  73. });
  74. it('shows legend without a title', function() {
  75. let wrapper = mount(
  76. <PanelChart series={SERIES} previousPeriod={PREVIOUS}>
  77. <div />
  78. </PanelChart>,
  79. TestStubs.routerContext()
  80. );
  81. // This has 2 results because of the Legend class and styled-component wrapper
  82. expect(wrapper.find('Legend')).toHaveLength(2);
  83. });
  84. });