chart.spec.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. describe('Chart', function () {
  16. test('it shows an error panel if an error prop is supplied', function () {
  17. const parsingError = new Error('Could not parse chart data');
  18. render(
  19. <Chart error={parsingError} data={[]} loading={false} type={ChartType.LINE} />
  20. );
  21. expect(screen.getByTestId('chart-error-panel')).toBeInTheDocument();
  22. });
  23. it('does not propagate mark line to the incomplete series', function () {
  24. const start = Date.now();
  25. const mockedSeries: Series[] = [
  26. {
  27. seriesName: 'series',
  28. data: [
  29. {name: start - 120_000, value: 5},
  30. {name: start - 90_000, value: 4},
  31. {name: start - 60_000, value: 3},
  32. {name: start - 30_000, value: 2},
  33. {name: start, value: 1},
  34. ],
  35. markLine: MarkLine({
  36. data: [
  37. {
  38. type: 'average',
  39. yAxis: 3,
  40. },
  41. ],
  42. }),
  43. },
  44. ];
  45. render(<Chart data={mockedSeries} loading={false} type={ChartType.LINE} />);
  46. expect(jest.mocked(BaseChart).mock.calls[0][0].series?.[0]).toHaveProperty(
  47. 'markLine'
  48. );
  49. expect(jest.mocked(BaseChart).mock.calls[0][0].series?.[1]).not.toHaveProperty(
  50. 'markLine'
  51. );
  52. });
  53. });