replaysList.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. describe('ReplayList', () => {
  52. beforeEach(() => {
  53. mockUseReplayList.mockClear();
  54. });
  55. it('should render the onboarding panel when the org is on AM1', async () => {
  56. const mockOrg = getMockOrganization({features: AM1_FEATURES});
  57. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  58. fetching: false,
  59. hasSentOneReplay: false,
  60. });
  61. render(<ReplayList />, {
  62. context: getMockContext(mockOrg),
  63. });
  64. await waitFor(() =>
  65. expect(screen.getByText('Get to the root cause faster')).toBeInTheDocument()
  66. );
  67. expect(mockUseReplayList).not.toHaveBeenCalled();
  68. });
  69. it('should render the onboarding panel when the org is on AM1 and has sent some replays', async () => {
  70. const mockOrg = getMockOrganization({features: AM1_FEATURES});
  71. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  72. fetching: false,
  73. hasSentOneReplay: true,
  74. });
  75. render(<ReplayList />, {
  76. context: getMockContext(mockOrg),
  77. });
  78. await waitFor(() =>
  79. expect(screen.getByText('Get to the root cause faster')).toBeInTheDocument()
  80. );
  81. expect(mockUseReplayList).not.toHaveBeenCalled();
  82. });
  83. it('should render the onboarding panel when the org is on AM2 and has never sent a replay', async () => {
  84. const mockOrg = getMockOrganization({features: AM2_FEATURES});
  85. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  86. fetching: false,
  87. hasSentOneReplay: false,
  88. });
  89. render(<ReplayList />, {
  90. context: getMockContext(mockOrg),
  91. });
  92. await waitFor(() =>
  93. expect(screen.getByText('Get to the root cause faster')).toBeInTheDocument()
  94. );
  95. expect(mockUseReplayList).not.toHaveBeenCalled();
  96. });
  97. it('should fetch the replay table when the org is on AM2 and sent some replays', async () => {
  98. const mockOrg = getMockOrganization({features: AM2_FEATURES});
  99. mockUseHaveSelectedProjectsSentAnyReplayEvents.mockReturnValue({
  100. fetching: false,
  101. hasSentOneReplay: true,
  102. });
  103. render(<ReplayList />, {
  104. context: getMockContext(mockOrg),
  105. });
  106. await waitFor(() => expect(screen.getByTestId('replay-table')).toBeInTheDocument());
  107. expect(mockUseReplayList).toHaveBeenCalledTimes(1);
  108. });
  109. });