useReplaysForRegressionIssue.spec.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import type {Location} from 'history';
  2. import {EventFixture} from 'sentry-fixture/event';
  3. import {GroupFixture} from 'sentry-fixture/group';
  4. import {OrganizationFixture} from 'sentry-fixture/organization';
  5. import {act, renderHook, waitFor} from 'sentry-test/reactTestingLibrary';
  6. import type {EventOccurrence} from 'sentry/types';
  7. import {IssueCategory} from 'sentry/types/group';
  8. import {useLocation} from 'sentry/utils/useLocation';
  9. import useReplaysForRegressionIssue from 'sentry/views/issueDetails/groupReplays/useReplaysForRegressionIssue';
  10. jest.mock('sentry/utils/useLocation');
  11. describe('useReplaysForRegressionIssue', () => {
  12. const location: Location = {
  13. pathname: '',
  14. search: '',
  15. query: {},
  16. hash: '',
  17. state: undefined,
  18. action: 'PUSH',
  19. key: '',
  20. };
  21. jest.mocked(useLocation).mockReturnValue(location);
  22. const organization = OrganizationFixture({
  23. features: ['session-replay'],
  24. });
  25. const mockEvent = {
  26. ...EventFixture(),
  27. occurrence: {
  28. evidenceDisplay: {} as EventOccurrence['evidenceDisplay'],
  29. detectionTime: 'mock-detection-time',
  30. eventId: 'eventId',
  31. fingerprint: ['fingerprint'],
  32. id: 'id',
  33. issueTitle: 'Transaction Duration Regression',
  34. subtitle: 'Increased from 20.64ms to 36.24ms (P95)',
  35. resourceId: '',
  36. type: 1017,
  37. evidenceData: {
  38. transaction: 'mock-transaction',
  39. aggregateRange2: 100,
  40. breakpoint: Date.now() / 1000, // The breakpoint is stored in seconds
  41. },
  42. },
  43. };
  44. it('should fetch a list of replay ids', async () => {
  45. const MOCK_GROUP = GroupFixture({issueCategory: IssueCategory.PERFORMANCE});
  46. MockApiClient.addMockResponse({
  47. url: `/organizations/${organization.slug}/replay-count/`,
  48. method: 'GET',
  49. body: {
  50. ['mock-transaction']: ['replay42', 'replay256'],
  51. },
  52. });
  53. const {result} = renderHook(useReplaysForRegressionIssue, {
  54. initialProps: {
  55. group: MOCK_GROUP,
  56. location,
  57. organization,
  58. event: mockEvent,
  59. },
  60. });
  61. expect(result.current).toEqual({
  62. eventView: null,
  63. fetchError: undefined,
  64. pageLinks: null,
  65. });
  66. await waitFor(() =>
  67. expect(result.current).toEqual({
  68. eventView: expect.objectContaining({
  69. query: 'id:[replay42,replay256]',
  70. }),
  71. fetchError: undefined,
  72. pageLinks: null,
  73. })
  74. );
  75. });
  76. it('should return an empty EventView when there are no replay_ids returned from the count endpoint', async () => {
  77. const MOCK_GROUP = GroupFixture({issueCategory: IssueCategory.PERFORMANCE});
  78. MockApiClient.addMockResponse({
  79. url: `/organizations/${organization.slug}/replay-count/`,
  80. method: 'GET',
  81. body: {},
  82. });
  83. const {result} = renderHook(useReplaysForRegressionIssue, {
  84. initialProps: {
  85. group: MOCK_GROUP,
  86. location,
  87. organization,
  88. event: mockEvent,
  89. },
  90. });
  91. expect(result.current).toEqual({
  92. eventView: null,
  93. fetchError: undefined,
  94. pageLinks: null,
  95. });
  96. await waitFor(() =>
  97. expect(result.current).toEqual({
  98. eventView: expect.objectContaining({
  99. query: 'id:[]',
  100. }),
  101. fetchError: undefined,
  102. pageLinks: null,
  103. })
  104. );
  105. });
  106. it('queries using start and end date strings if passed in', async () => {
  107. const MOCK_GROUP = GroupFixture({issueCategory: IssueCategory.PERFORMANCE});
  108. const replayCountRequest = MockApiClient.addMockResponse({
  109. url: `/organizations/${organization.slug}/replay-count/`,
  110. method: 'GET',
  111. body: {
  112. ['mock_transaction']: ['replay42', 'replay256'],
  113. },
  114. });
  115. renderHook(useReplaysForRegressionIssue, {
  116. initialProps: {
  117. group: MOCK_GROUP,
  118. location,
  119. organization,
  120. event: mockEvent,
  121. },
  122. });
  123. expect(replayCountRequest).toHaveBeenCalledWith(
  124. '/organizations/org-slug/replay-count/',
  125. expect.objectContaining({
  126. query: expect.objectContaining({
  127. start: new Date(
  128. mockEvent.occurrence.evidenceData.breakpoint * 1000
  129. ).toISOString(),
  130. end: new Date().toISOString(),
  131. }),
  132. })
  133. );
  134. await act(tick);
  135. });
  136. it('queries the transaction name with event type and duration filters', async () => {
  137. const MOCK_GROUP = GroupFixture({issueCategory: IssueCategory.PERFORMANCE});
  138. const replayCountRequest = MockApiClient.addMockResponse({
  139. url: `/organizations/${organization.slug}/replay-count/`,
  140. method: 'GET',
  141. body: {
  142. ['mock_transaction']: ['replay42', 'replay256'],
  143. },
  144. });
  145. renderHook(useReplaysForRegressionIssue, {
  146. initialProps: {
  147. group: MOCK_GROUP,
  148. location,
  149. organization,
  150. event: mockEvent,
  151. },
  152. });
  153. expect(replayCountRequest).toHaveBeenCalledWith(
  154. '/organizations/org-slug/replay-count/',
  155. expect.objectContaining({
  156. query: expect.objectContaining({
  157. query:
  158. 'event.type:transaction transaction:["mock-transaction"] transaction.duration:>=50ms',
  159. }),
  160. })
  161. );
  162. await act(tick);
  163. });
  164. });