1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import {render, screen} from 'sentry-test/reactTestingLibrary';
- import BaseChart from 'sentry/components/charts/baseChart';
- import MarkLine from 'sentry/components/charts/components/markLine';
- import type {Series} from 'sentry/types/echarts';
- import Chart, {ChartType} from 'sentry/views/insights/common/components/chart';
- jest.mock('sentry/components/charts/baseChart', () => {
- return jest.fn().mockImplementation(() => <div />);
- });
- jest.mock('react', () => {
- return {
- ...jest.requireActual('react'),
- useRef: jest.fn(),
- };
- });
- describe('Chart', function () {
- test('it shows an error panel if an error prop is supplied', function () {
- const parsingError = new Error('Could not parse chart data');
- render(
- <Chart error={parsingError} data={[]} loading={false} type={ChartType.LINE} />
- );
- expect(screen.getByTestId('chart-error-panel')).toBeInTheDocument();
- });
- it('does not propagate mark line to the incomplete series', function () {
- const start = Date.now();
- const mockedSeries: Series[] = [
- {
- seriesName: 'series',
- data: [
- {name: start - 120_000, value: 5},
- {name: start - 90_000, value: 4},
- {name: start - 60_000, value: 3},
- {name: start - 30_000, value: 2},
- {name: start, value: 1},
- ],
- markLine: MarkLine({
- data: [
- {
- type: 'average',
- yAxis: 3,
- },
- ],
- }),
- },
- ];
- render(<Chart data={mockedSeries} loading={false} type={ChartType.LINE} />);
- expect(jest.mocked(BaseChart).mock.calls[0][0].series?.[0]).toHaveProperty(
- 'markLine'
- );
- expect(jest.mocked(BaseChart).mock.calls[0][0].series?.[1]).not.toHaveProperty(
- 'markLine'
- );
- });
- });
|