index.spec.tsx 4.9 KB

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