replaysList.spec.tsx 3.9 KB

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