eventSamples.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import usePageFilters from 'sentry/utils/usePageFilters';
  5. import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
  6. import {EventSamples} from 'sentry/views/insights/mobile/appStarts/components/eventSamples';
  7. import {
  8. MobileCursors,
  9. MobileSortKeys,
  10. } from 'sentry/views/insights/mobile/screenload/constants';
  11. jest.mock('sentry/utils/usePageFilters');
  12. jest.mock('sentry/views/insights/common/queries/useReleases');
  13. describe('ScreenLoadEventSamples', function () {
  14. const organization = OrganizationFixture();
  15. const project = ProjectFixture();
  16. let mockEventsRequest;
  17. beforeEach(function () {
  18. jest.mocked(usePageFilters).mockReturnValue({
  19. isReady: true,
  20. desyncedFilters: new Set(),
  21. pinnedFilters: new Set(),
  22. shouldPersist: true,
  23. selection: {
  24. datetime: {
  25. period: '10d',
  26. start: null,
  27. end: null,
  28. utc: false,
  29. },
  30. environments: [],
  31. projects: [parseInt(project.id, 10)],
  32. },
  33. });
  34. jest.mocked(useReleaseSelection).mockReturnValue({
  35. primaryRelease: 'com.example.vu.android@2.10.5',
  36. isLoading: false,
  37. secondaryRelease: 'com.example.vu.android@2.10.3+42',
  38. });
  39. MockApiClient.addMockResponse({
  40. url: `/organizations/${organization.slug}/releases/`,
  41. body: [
  42. {
  43. id: 970136705,
  44. version: 'com.example.vu.android@2.10.5',
  45. dateCreated: '2023-12-19T21:37:53.895495Z',
  46. },
  47. {
  48. id: 969902997,
  49. version: 'com.example.vu.android@2.10.3+42',
  50. dateCreated: '2023-12-19T18:04:06.953025Z',
  51. },
  52. ],
  53. });
  54. mockEventsRequest = MockApiClient.addMockResponse({
  55. url: `/organizations/${organization.slug}/events/`,
  56. body: {
  57. meta: {
  58. fields: {
  59. profile_id: 'string',
  60. 'transaction.id': 'string',
  61. 'span.duration': 'duration',
  62. 'project.name': 'string',
  63. id: 'string',
  64. },
  65. },
  66. data: [
  67. {
  68. profile_id: 'profile-id',
  69. 'transaction.id': '76af98a3ac9d4448b894e44b1819970e',
  70. 'span.duration': 131,
  71. 'project.name': 'sentry-cocoa',
  72. id: 'f0587aad3de14aeb',
  73. },
  74. ],
  75. },
  76. });
  77. });
  78. it('makes a request for the release and transaction passed as props', async function () {
  79. render(
  80. <EventSamples
  81. release="com.example.vu.android@2.10.5"
  82. sortKey={MobileSortKeys.RELEASE_1_EVENT_SAMPLE_TABLE}
  83. cursorName={MobileCursors.RELEASE_1_EVENT_SAMPLE_TABLE}
  84. transaction="ErrorController"
  85. showDeviceClassSelector
  86. />
  87. );
  88. // Check that headers are set properly
  89. expect(screen.getByRole('columnheader', {name: 'Event ID (R1)'})).toBeInTheDocument();
  90. expect(screen.getByRole('columnheader', {name: 'Profile'})).toBeInTheDocument();
  91. expect(screen.getByRole('columnheader', {name: 'Duration'})).toBeInTheDocument();
  92. expect(mockEventsRequest).toHaveBeenCalledTimes(1);
  93. // Check data is rendered properly
  94. // Transaction is a link
  95. expect(await screen.findByRole('link', {name: '76af98a3'})).toHaveAttribute(
  96. 'href',
  97. '/organizations/org-slug/performance/sentry-cocoa:76af98a3ac9d4448b894e44b1819970e/?'
  98. );
  99. // Profile is a button
  100. expect(screen.getByRole('button', {name: 'View Profile'})).toHaveAttribute(
  101. 'href',
  102. '/organizations/org-slug/profiling/profile/sentry-cocoa/profile-id/flamegraph/'
  103. );
  104. expect(screen.getByText('131.00ms')).toBeInTheDocument();
  105. });
  106. });