listContent.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import {Organization} from 'sentry/types';
  3. import useReplayList from 'sentry/utils/replays/hooks/useReplayList';
  4. import {
  5. useHaveSelectedProjectsSentAnyReplayEvents,
  6. useReplayOnboardingSidebarPanel,
  7. } from 'sentry/utils/replays/hooks/useReplayOnboarding';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import ListPage from 'sentry/views/replays/list/listContent';
  10. jest.mock('sentry/utils/replays/hooks/useReplayPageview');
  11. jest.mock('sentry/utils/useOrganization');
  12. jest.mock('sentry/utils/replays/hooks/useReplayOnboarding');
  13. jest.mock('sentry/utils/replays/hooks/useReplayList', () => {
  14. return {
  15. __esModule: true,
  16. default: jest.fn(() => {
  17. return {
  18. fetchError: undefined,
  19. isFetching: false,
  20. pageLinks: null,
  21. replays: [],
  22. };
  23. }),
  24. };
  25. });
  26. const mockUseReplayList = jest.mocked(useReplayList);
  27. const mockUseHaveSelectedProjectsSentAnyReplayEvents = jest.mocked(
  28. useHaveSelectedProjectsSentAnyReplayEvents
  29. );
  30. const mockUseReplayOnboardingSidebarPanel = jest.mocked(useReplayOnboardingSidebarPanel);
  31. mockUseReplayOnboardingSidebarPanel.mockReturnValue({activateSidebar: jest.fn()});
  32. const AM1_FEATURES = [];
  33. const AM2_FEATURES = ['session-replay'];
  34. function getMockOrganization({features}: {features: string[]}) {
  35. const mockOrg = TestStubs.Organization({
  36. features,
  37. access: [],
  38. });
  39. jest.mocked(useOrganization).mockReturnValue(mockOrg);
  40. return mockOrg;
  41. }
  42. function getMockContext(mockOrg: Organization) {
  43. return TestStubs.routerContext([{organization: mockOrg}]);
  44. }
  45. describe('ReplayList', () => {
  46. beforeEach(() => {
  47. mockUseReplayList.mockClear();
  48. MockApiClient.clearMockResponses();
  49. MockApiClient.addMockResponse({
  50. url: '/organizations/org-slug/sdk-updates/',
  51. body: [],
  52. });
  53. MockApiClient.addMockResponse({
  54. url: '/organizations/org-slug/tags/',
  55. body: [],
  56. });
  57. });
  58. it('should render the onboarding panel when the org is on AM1', async () => {
  59. const mockOrg = getMockOrganization({features: AM1_FEATURES});
  60. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  61. fetching: false,
  62. hasSentOneReplay: false,
  63. });
  64. render(<ListPage />, {
  65. context: getMockContext(mockOrg),
  66. });
  67. await waitFor(() =>
  68. expect(screen.getByText('Get to the root cause faster')).toBeInTheDocument()
  69. );
  70. expect(mockUseReplayList).not.toHaveBeenCalled();
  71. });
  72. it('should render the onboarding panel when the org is on AM1 and has sent some replays', async () => {
  73. const mockOrg = getMockOrganization({features: AM1_FEATURES});
  74. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  75. fetching: false,
  76. hasSentOneReplay: true,
  77. });
  78. render(<ListPage />, {
  79. context: getMockContext(mockOrg),
  80. });
  81. await waitFor(() =>
  82. expect(screen.getByText('Get to the root cause faster')).toBeInTheDocument()
  83. );
  84. expect(mockUseReplayList).not.toHaveBeenCalled();
  85. });
  86. it('should render the onboarding panel when the org is on AM2 and has never sent a replay', async () => {
  87. const mockOrg = getMockOrganization({features: AM2_FEATURES});
  88. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  89. fetching: false,
  90. hasSentOneReplay: false,
  91. });
  92. render(<ListPage />, {
  93. context: getMockContext(mockOrg),
  94. });
  95. await waitFor(() =>
  96. expect(screen.getByText('Get to the root cause faster')).toBeInTheDocument()
  97. );
  98. expect(mockUseReplayList).not.toHaveBeenCalled();
  99. });
  100. it('should fetch the replay table when the org is on AM2 and sent some replays', async () => {
  101. const mockOrg = getMockOrganization({features: AM2_FEATURES});
  102. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  103. fetching: false,
  104. hasSentOneReplay: true,
  105. });
  106. render(<ListPage />, {
  107. context: getMockContext(mockOrg),
  108. });
  109. await waitFor(() => expect(screen.queryAllByTestId('replay-table')).toHaveLength(3));
  110. expect(mockUseReplayList).toHaveBeenCalled();
  111. });
  112. });