chart.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import BaseChart from 'sentry/components/charts/baseChart';
  3. import MarkLine from 'sentry/components/charts/components/markLine';
  4. import type {Series} from 'sentry/types/echarts';
  5. import Chart, {ChartType} from 'sentry/views/insights/common/components/chart';
  6. jest.mock('sentry/components/charts/baseChart', () => {
  7. return jest.fn().mockImplementation(() => <div />);
  8. });
  9. jest.mock('react', () => {
  10. return {
  11. ...jest.requireActual('react'),
  12. useRef: jest.fn(),
  13. };
  14. });
  15. // XXX: Mocking useRef throws an error for AnimatePrecense, so it must be mocked as well
  16. jest.mock('framer-motion', () => {
  17. return {
  18. ...jest.requireActual('framer-motion'),
  19. AnimatePresence: jest.fn().mockImplementation(({children}) => <div>{children}</div>),
  20. };
  21. });
  22. describe('Chart', function () {
  23. test('it shows an error panel if an error prop is supplied', function () {
  24. const parsingError = new Error('Could not parse chart data');
  25. render(
  26. <Chart error={parsingError} data={[]} loading={false} type={ChartType.LINE} />
  27. );
  28. expect(screen.getByTestId('chart-error-panel')).toBeInTheDocument();
  29. });
  30. it('does not propagate mark line to the incomplete series', function () {
  31. const start = Date.now();
  32. const mockedSeries: Series[] = [
  33. {
  34. seriesName: 'series',
  35. data: [
  36. {name: start - 120_000, value: 5},
  37. {name: start - 90_000, value: 4},
  38. {name: start - 60_000, value: 3},
  39. {name: start - 30_000, value: 2},
  40. {name: start, value: 1},
  41. ],
  42. markLine: MarkLine({
  43. data: [
  44. {
  45. type: 'average',
  46. yAxis: 3,
  47. },
  48. ],
  49. }),
  50. },
  51. ];
  52. render(<Chart data={mockedSeries} loading={false} type={ChartType.LINE} />);
  53. expect(jest.mocked(BaseChart).mock.calls[0][0].series?.[0]).toHaveProperty(
  54. 'markLine'
  55. );
  56. expect(jest.mocked(BaseChart).mock.calls[0][0].series?.[1]).not.toHaveProperty(
  57. 'markLine'
  58. );
  59. });
  60. });