samplesTables.spec.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
  3. import {SamplesTables} from 'sentry/views/insights/mobile/common/components/tables/samplesTables';
  4. jest.mock('sentry/views/insights/common/queries/useReleases');
  5. jest.mocked(useReleaseSelection).mockReturnValue({
  6. primaryRelease: 'com.example.vu.android@2.10.5-alpha.1+42',
  7. isLoading: false,
  8. secondaryRelease: 'com.example.vu.android@2.10.3+42',
  9. });
  10. describe('SamplesTables', () => {
  11. beforeEach(() => {
  12. MockApiClient.addMockResponse({
  13. url: `/organizations/org-slug/events/`,
  14. method: 'GET',
  15. match: [
  16. MockApiClient.matchQuery({
  17. referrer: 'api.insights.user-geo-subregion-selector',
  18. }),
  19. ],
  20. body: {
  21. data: [
  22. {'user.geo.subregion': '21', 'count()': 123},
  23. {'user.geo.subregion': '155', 'count()': 123},
  24. ],
  25. meta: {
  26. fields: {'user.geo.subregion': 'string', 'count()': 'integer'},
  27. },
  28. },
  29. });
  30. });
  31. it('accepts components for event samples and span operation table', async () => {
  32. render(
  33. <SamplesTables
  34. EventSamples={({release}) => (
  35. <div>{`This is a custom Event Samples table for release: ${release}`}</div>
  36. )}
  37. SpanOperationTable={_props => <div>This is a custom Span Operation table</div>}
  38. transactionName={''}
  39. />
  40. );
  41. // The span operation table is rendered first
  42. expect(
  43. await screen.findByText('This is a custom Span Operation table')
  44. ).toBeInTheDocument();
  45. await userEvent.click(screen.getByRole('radio', {name: 'By Event'}));
  46. expect(
  47. await screen.findByText(
  48. 'This is a custom Event Samples table for release: com.example.vu.android@2.10.5-alpha.1+42'
  49. )
  50. ).toBeInTheDocument();
  51. expect(
  52. screen.getByText(
  53. 'This is a custom Event Samples table for release: com.example.vu.android@2.10.3+42'
  54. )
  55. ).toBeInTheDocument();
  56. });
  57. });