replaysList.spec.tsx 4.1 KB

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