onboardingStatus.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {UserFixture} from 'sentry-fixture/user';
  3. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import {OnboardingStatus} from 'sentry/components/sidebar/onboardingStatus';
  5. import {SidebarPanelKey} from 'sentry/components/sidebar/types';
  6. import {OnboardingTaskKey} from 'sentry/types/onboarding';
  7. import type {Organization} from 'sentry/types/organization';
  8. function renderMockRequests(organization: Organization) {
  9. const getOnboardingTasksMock = MockApiClient.addMockResponse({
  10. url: `/organizations/${organization.slug}/onboarding-tasks/`,
  11. method: 'GET',
  12. body: {
  13. onboardingTasks: organization.onboardingTasks,
  14. },
  15. });
  16. return {getOnboardingTasksMock};
  17. }
  18. describe('Onboarding Status', function () {
  19. it('panel is collapsed and has pending tasks to be seen', async function () {
  20. const organization = OrganizationFixture({
  21. features: ['onboarding'],
  22. onboardingTasks: [
  23. {
  24. task: OnboardingTaskKey.FIRST_PROJECT,
  25. status: 'complete',
  26. user: UserFixture(),
  27. completionSeen: undefined,
  28. dateCompleted: undefined,
  29. },
  30. ],
  31. });
  32. const {getOnboardingTasksMock} = renderMockRequests(organization);
  33. const handleShowPanel = jest.fn();
  34. render(
  35. <OnboardingStatus
  36. currentPanel=""
  37. onShowPanel={handleShowPanel}
  38. hidePanel={jest.fn()}
  39. collapsed
  40. orientation="left"
  41. />,
  42. {
  43. organization,
  44. }
  45. );
  46. expect(screen.getByText('1 completed task')).toBeInTheDocument();
  47. expect(screen.getByTestId('pending-seen-indicator')).toBeInTheDocument();
  48. // By hovering over the button, we should refetch the data
  49. await userEvent.hover(screen.getByRole('button', {name: 'Onboarding'}));
  50. await waitFor(() => expect(getOnboardingTasksMock).toHaveBeenCalled());
  51. // Open the panel
  52. await userEvent.click(screen.getByRole('button', {name: 'Onboarding'}));
  53. await waitFor(() => expect(getOnboardingTasksMock).toHaveBeenCalled());
  54. expect(handleShowPanel).toHaveBeenCalled();
  55. });
  56. it('panel is expanded and has no pending tasks to be seen', async function () {
  57. const organization = OrganizationFixture({
  58. features: ['onboarding'],
  59. onboardingTasks: [
  60. {
  61. task: OnboardingTaskKey.FIRST_PROJECT,
  62. status: 'complete',
  63. user: UserFixture(),
  64. completionSeen: '2024-12-16T14:52:01.385227Z',
  65. dateCompleted: '2024-12-13T09:35:05.010028Z',
  66. },
  67. ],
  68. });
  69. const {getOnboardingTasksMock} = renderMockRequests(organization);
  70. const handleHidePanel = jest.fn();
  71. render(
  72. <OnboardingStatus
  73. currentPanel={SidebarPanelKey.ONBOARDING_WIZARD}
  74. onShowPanel={jest.fn()}
  75. hidePanel={handleHidePanel}
  76. collapsed={false}
  77. orientation="left"
  78. />,
  79. {
  80. organization,
  81. }
  82. );
  83. expect(screen.getByText('1 completed task')).toBeInTheDocument();
  84. // Do not show the pending indicator
  85. expect(screen.queryByTestId('pending-seen-indicator')).not.toBeInTheDocument();
  86. // Shows the panel
  87. expect(screen.getByText('Quick Setup')).toBeInTheDocument();
  88. // Triggers a fetch request
  89. expect(getOnboardingTasksMock).toHaveBeenCalled();
  90. // Hide Panel
  91. await userEvent.click(screen.getByLabelText('Close Panel'));
  92. await waitFor(() => expect(handleHidePanel).toHaveBeenCalled());
  93. });
  94. });