index.spec.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import {Event as EventFixture} from 'sentry-fixture/event';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {RRWebInitFrameEvents} from 'sentry-fixture/replay/rrweb';
  4. import {ReplayRecordFixture} from 'sentry-fixture/replayRecord';
  5. import {render, screen} from 'sentry-test/reactTestingLibrary';
  6. import EventReplay from 'sentry/components/events/eventReplay';
  7. import {
  8. useHasOrganizationSentAnyReplayEvents,
  9. useReplayOnboardingSidebarPanel,
  10. } from 'sentry/utils/replays/hooks/useReplayOnboarding';
  11. import useReplayReader from 'sentry/utils/replays/hooks/useReplayReader';
  12. import ReplayReader from 'sentry/utils/replays/replayReader';
  13. import useProjects from 'sentry/utils/useProjects';
  14. jest.mock('sentry/utils/replays/hooks/useReplayOnboarding');
  15. jest.mock('sentry/utils/replays/hooks/useReplayReader');
  16. jest.mock('sentry/utils/useProjects');
  17. const now = new Date();
  18. const mockReplay = ReplayReader.factory(
  19. {
  20. replayRecord: ReplayRecordFixture({started_at: now}),
  21. errors: [],
  22. attachments: RRWebInitFrameEvents({timestamp: now}),
  23. },
  24. {}
  25. );
  26. jest.mocked(useReplayReader).mockImplementation(() => {
  27. return {
  28. attachments: [],
  29. errors: [],
  30. fetchError: undefined,
  31. fetching: false,
  32. onRetry: jest.fn(),
  33. projectSlug: TestStubs.Project().slug,
  34. replay: mockReplay,
  35. replayId: ReplayRecordFixture({}).id,
  36. replayRecord: ReplayRecordFixture(),
  37. };
  38. });
  39. describe('EventReplay', function () {
  40. const MockUseReplayOnboardingSidebarPanel = jest.mocked(
  41. useReplayOnboardingSidebarPanel
  42. );
  43. const MockUseHasOrganizationSentAnyReplayEvents = jest.mocked(
  44. useHasOrganizationSentAnyReplayEvents
  45. );
  46. const organization = Organization({
  47. features: ['session-replay'],
  48. });
  49. const defaultProps = {
  50. event: EventFixture({
  51. entries: [],
  52. tags: [],
  53. platform: 'javascript',
  54. }),
  55. projectSlug: 'project-slug',
  56. };
  57. beforeEach(function () {
  58. const project = TestStubs.Project({platform: 'javascript'});
  59. jest.mocked(useProjects).mockReturnValue({
  60. fetchError: null,
  61. fetching: false,
  62. hasMore: false,
  63. initiallyLoaded: false,
  64. onSearch: () => Promise.resolve(),
  65. placeholders: [],
  66. projects: [project],
  67. });
  68. MockUseHasOrganizationSentAnyReplayEvents.mockReturnValue({
  69. hasOrgSentReplays: false,
  70. fetching: false,
  71. });
  72. MockUseReplayOnboardingSidebarPanel.mockReturnValue({
  73. activateSidebar: jest.fn(),
  74. });
  75. });
  76. it('should render the replay inline onboarding component when replays are enabled and the project supports replay', async function () {
  77. MockUseHasOrganizationSentAnyReplayEvents.mockReturnValue({
  78. hasOrgSentReplays: false,
  79. fetching: false,
  80. });
  81. MockUseReplayOnboardingSidebarPanel.mockReturnValue({
  82. activateSidebar: jest.fn(),
  83. });
  84. render(<EventReplay {...defaultProps} />, {organization});
  85. expect(await screen.findByText('Configure Session Replay')).toBeInTheDocument();
  86. });
  87. it('should not render the replay inline onboarding component when the project is not JS', function () {
  88. MockUseHasOrganizationSentAnyReplayEvents.mockReturnValue({
  89. hasOrgSentReplays: false,
  90. fetching: false,
  91. });
  92. MockUseReplayOnboardingSidebarPanel.mockReturnValue({
  93. activateSidebar: jest.fn(),
  94. });
  95. render(
  96. <EventReplay
  97. {...defaultProps}
  98. event={EventFixture({
  99. entries: [],
  100. tags: [],
  101. })}
  102. />,
  103. {organization}
  104. );
  105. expect(screen.queryByText('Configure Session Replay')).not.toBeInTheDocument();
  106. expect(screen.queryByTestId('player-container')).not.toBeInTheDocument();
  107. });
  108. it('should render a replay when there is a replayId from tags', async function () {
  109. MockUseHasOrganizationSentAnyReplayEvents.mockReturnValue({
  110. hasOrgSentReplays: true,
  111. fetching: false,
  112. });
  113. MockUseReplayOnboardingSidebarPanel.mockReturnValue({
  114. activateSidebar: jest.fn(),
  115. });
  116. render(
  117. <EventReplay
  118. {...defaultProps}
  119. event={EventFixture({
  120. entries: [],
  121. tags: [{key: 'replayId', value: '761104e184c64d439ee1014b72b4d83b'}],
  122. platform: 'javascript',
  123. })}
  124. />,
  125. {organization}
  126. );
  127. expect(await screen.findByTestId('player-container')).toBeInTheDocument();
  128. });
  129. it('should render a replay when there is a replay_id from contexts', async function () {
  130. MockUseHasOrganizationSentAnyReplayEvents.mockReturnValue({
  131. hasOrgSentReplays: true,
  132. fetching: false,
  133. });
  134. MockUseReplayOnboardingSidebarPanel.mockReturnValue({
  135. activateSidebar: jest.fn(),
  136. });
  137. render(
  138. <EventReplay
  139. {...defaultProps}
  140. event={EventFixture({
  141. entries: [],
  142. tags: [],
  143. contexts: {
  144. replay: {
  145. replay_id: '761104e184c64d439ee1014b72b4d83b',
  146. },
  147. },
  148. platform: 'javascript',
  149. })}
  150. />,
  151. {organization}
  152. );
  153. expect(await screen.findByTestId('player-container')).toBeInTheDocument();
  154. });
  155. });