baseChartHeightResize.spec.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. function TestContainer({children}) {
  17. return (
  18. <div style={{height: '500px', background: 'yellow', padding: '20px'}}>{children}</div>
  19. );
  20. }
  21. describe('BaseChart', function () {
  22. it('can scale to full parent height when given autoHeightResize', () => {
  23. render(
  24. <TestContainer>
  25. <BaseChart autoHeightResize />
  26. </TestContainer>
  27. );
  28. });
  29. it('renders with default height when autoHeightResize not provided', () => {
  30. render(
  31. <TestContainer>
  32. <BaseChart />
  33. </TestContainer>
  34. );
  35. });
  36. });