index.spec.tsx 4.9 KB

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