useReplaysForRegressionIssue.spec.tsx 5.2 KB

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