listContent.spec.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import useDeadRageSelectors from 'sentry/utils/replays/hooks/useDeadRageSelectors';
  4. import {
  5. useHaveSelectedProjectsSentAnyReplayEvents,
  6. useReplayOnboardingSidebarPanel,
  7. } from 'sentry/utils/replays/hooks/useReplayOnboarding';
  8. import useProjectSdkNeedsUpdate from 'sentry/utils/useProjectSdkNeedsUpdate';
  9. import useAllMobileProj from 'sentry/views/replays/detail/useAllMobileProj';
  10. import ListPage from 'sentry/views/replays/list/listContent';
  11. jest.mock('sentry/utils/replays/hooks/useDeadRageSelectors');
  12. jest.mock('sentry/utils/replays/hooks/useReplayOnboarding');
  13. jest.mock('sentry/utils/replays/hooks/useReplayPageview');
  14. jest.mock('sentry/utils/useProjectSdkNeedsUpdate');
  15. jest.mock('sentry/views/replays/detail/useAllMobileProj');
  16. const mockUseDeadRageSelectors = jest.mocked(useDeadRageSelectors);
  17. mockUseDeadRageSelectors.mockReturnValue({
  18. isLoading: false,
  19. isError: false,
  20. data: [],
  21. pageLinks: undefined,
  22. });
  23. const mockUseHaveSelectedProjectsSentAnyReplayEvents = jest.mocked(
  24. useHaveSelectedProjectsSentAnyReplayEvents
  25. );
  26. const mockUseProjectSdkNeedsUpdate = jest.mocked(useProjectSdkNeedsUpdate);
  27. const mockUseReplayOnboardingSidebarPanel = jest.mocked(useReplayOnboardingSidebarPanel);
  28. mockUseReplayOnboardingSidebarPanel.mockReturnValue({activateSidebar: jest.fn()});
  29. const mockUseAllMobileProj = jest.mocked(useAllMobileProj);
  30. mockUseAllMobileProj.mockReturnValue({allMobileProj: false});
  31. const AM1_FEATURES: string[] = [];
  32. const AM2_FEATURES: string[] = ['session-replay'];
  33. function getMockOrganizationFixture({features}: {features: string[]}) {
  34. const mockOrg = OrganizationFixture({
  35. features,
  36. access: [],
  37. });
  38. return mockOrg;
  39. }
  40. describe('ReplayList', () => {
  41. let mockFetchReplayListRequest: jest.Mock;
  42. beforeEach(() => {
  43. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockClear();
  44. mockUseProjectSdkNeedsUpdate.mockClear();
  45. mockUseDeadRageSelectors.mockClear();
  46. // mockUseAllMobileProj.mockClear();
  47. MockApiClient.clearMockResponses();
  48. MockApiClient.addMockResponse({
  49. url: '/organizations/org-slug/tags/',
  50. body: [],
  51. });
  52. mockFetchReplayListRequest = MockApiClient.addMockResponse({
  53. url: `/organizations/org-slug/replays/`,
  54. body: {},
  55. });
  56. // Request made by SearchQueryBuilder:
  57. MockApiClient.addMockResponse({
  58. url: '/organizations/org-slug/recent-searches/',
  59. method: 'GET',
  60. body: [],
  61. });
  62. });
  63. it('should render the onboarding panel when the org is on AM1', async () => {
  64. const mockOrg = getMockOrganizationFixture({features: AM1_FEATURES});
  65. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  66. fetching: false,
  67. hasSentOneReplay: false,
  68. });
  69. mockUseProjectSdkNeedsUpdate.mockReturnValue({
  70. isError: false,
  71. isFetching: false,
  72. needsUpdate: false,
  73. });
  74. render(<ListPage />, {
  75. organization: mockOrg,
  76. });
  77. await screen.findByText('Get to the root cause faster');
  78. expect(mockFetchReplayListRequest).not.toHaveBeenCalled();
  79. });
  80. it('should render the onboarding panel when the org is on AM1 and has sent some replays', async () => {
  81. const mockOrg = getMockOrganizationFixture({features: AM1_FEATURES});
  82. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  83. fetching: false,
  84. hasSentOneReplay: true,
  85. });
  86. mockUseProjectSdkNeedsUpdate.mockReturnValue({
  87. isError: false,
  88. isFetching: false,
  89. needsUpdate: false,
  90. });
  91. render(<ListPage />, {
  92. organization: mockOrg,
  93. });
  94. await screen.findByText('Get to the root cause faster');
  95. expect(mockFetchReplayListRequest).not.toHaveBeenCalled();
  96. });
  97. it('should render the onboarding panel when the org is on AM2 and has never sent a replay', async () => {
  98. const mockOrg = getMockOrganizationFixture({features: AM2_FEATURES});
  99. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  100. fetching: false,
  101. hasSentOneReplay: false,
  102. });
  103. mockUseProjectSdkNeedsUpdate.mockReturnValue({
  104. isError: false,
  105. isFetching: false,
  106. needsUpdate: false,
  107. });
  108. render(<ListPage />, {
  109. organization: mockOrg,
  110. });
  111. await screen.findByText('Get to the root cause faster');
  112. expect(mockFetchReplayListRequest).not.toHaveBeenCalled();
  113. });
  114. it('should render the rage-click sdk update banner when the org is AM2, has sent replays, but the sdk version is low', async () => {
  115. const mockOrg = getMockOrganizationFixture({features: AM2_FEATURES});
  116. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  117. fetching: false,
  118. hasSentOneReplay: true,
  119. });
  120. mockUseProjectSdkNeedsUpdate.mockReturnValue({
  121. isError: false,
  122. isFetching: false,
  123. needsUpdate: true,
  124. });
  125. render(<ListPage />, {
  126. organization: mockOrg,
  127. });
  128. await waitFor(() => {
  129. expect(screen.getByText('Introducing Rage and Dead Clicks')).toBeInTheDocument();
  130. });
  131. expect(screen.getByTestId('replay-table')).toBeInTheDocument();
  132. expect(mockFetchReplayListRequest).toHaveBeenCalled();
  133. });
  134. it('should fetch the replay table when the org is on AM2, has sent some replays, and has a newer SDK version', async () => {
  135. const mockOrg = getMockOrganizationFixture({features: AM2_FEATURES});
  136. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  137. fetching: false,
  138. hasSentOneReplay: true,
  139. });
  140. mockUseProjectSdkNeedsUpdate.mockReturnValue({
  141. isError: false,
  142. isFetching: false,
  143. needsUpdate: false,
  144. });
  145. render(<ListPage />, {
  146. organization: mockOrg,
  147. });
  148. await waitFor(() => expect(screen.queryAllByTestId('replay-table')).toHaveLength(1));
  149. expect(mockFetchReplayListRequest).toHaveBeenCalled();
  150. });
  151. });