eventsChart.spec.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import BaseChart from 'sentry/components/charts/baseChart';
  4. import EventsChart from 'sentry/components/charts/eventsChart';
  5. import {WorldMapChart} from 'sentry/components/charts/worldMapChart';
  6. jest.mock('sentry/components/charts/baseChart', () => {
  7. return jest.fn().mockImplementation(() => <div data-test-id="chart" />);
  8. });
  9. jest.mock(
  10. 'sentry/components/charts/eventsGeoRequest',
  11. () =>
  12. ({children}) =>
  13. children({
  14. errored: false,
  15. loading: false,
  16. reloading: false,
  17. tableData: [],
  18. })
  19. );
  20. describe('EventsChart', function () {
  21. const {router, routerContext, organization} = initializeOrg();
  22. afterEach(() => {
  23. MockApiClient.clearMockResponses();
  24. });
  25. function renderChart(props) {
  26. return render(
  27. <EventsChart
  28. api={new MockApiClient()}
  29. location={{query: {}}}
  30. organization={organization}
  31. project={[]}
  32. environment={[]}
  33. period="14d"
  34. start={null}
  35. end={null}
  36. utc={false}
  37. router={router}
  38. {...props}
  39. />,
  40. {context: routerContext}
  41. );
  42. }
  43. it('renders with World Map when given WorldMapChart chartComponent', async function () {
  44. MockApiClient.addMockResponse({
  45. url: '/organizations/org-slug/releases/stats/',
  46. body: [],
  47. });
  48. renderChart({chartComponent: WorldMapChart, yAxis: ['count()']});
  49. expect(await screen.findByTestId('chart')).toBeInTheDocument();
  50. expect(BaseChart).toHaveBeenCalledWith(
  51. expect.objectContaining({
  52. series: [
  53. expect.objectContaining({
  54. map: 'sentryWorld',
  55. }),
  56. ],
  57. }),
  58. expect.anything()
  59. );
  60. });
  61. });