useReplaysForRegressionIssue.spec.tsx 5.2 KB

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