baseChartHeightResize.spec.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {render} from 'sentry-test/reactTestingLibrary';
  2. import BaseChart from 'sentry/components/charts/baseChart';
  3. jest.mock('echarts-for-react/lib/core', () => {
  4. // We need to do this because `jest.mock` gets hoisted by babel and `React` is not
  5. // guaranteed to be in scope
  6. const ReactActual = require('react');
  7. // We need a class component here because `BaseChart` passes `ref` which will
  8. // error if we return a stateless/functional component
  9. return class extends ReactActual.Component {
  10. render() {
  11. // ReactEchartsCore accepts a style prop that determines height
  12. return <div style={{...this.props.style, background: 'green'}}>echarts mock</div>;
  13. }
  14. };
  15. });
  16. const TestContainer = ({children}) => (
  17. <div style={{height: '500px', background: 'yellow', padding: '20px'}}>{children}</div>
  18. );
  19. describe('BaseChart', function () {
  20. it('can scale to full parent height when given autoHeightResize', () => {
  21. const {container} = render(
  22. <TestContainer>
  23. <BaseChart autoHeightResize />
  24. </TestContainer>
  25. );
  26. expect(container).toSnapshot();
  27. });
  28. it('renders with default height when autoHeightResize not provided', () => {
  29. const {container} = render(
  30. <TestContainer>
  31. <BaseChart />
  32. </TestContainer>
  33. );
  34. expect(container).toSnapshot();
  35. });
  36. });