onboarding.spec.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import OrganizationStore from 'sentry/stores/organizationStore';
  4. import {PersistedStoreProvider} from 'sentry/stores/persistedStore';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import Onboarding from 'sentry/views/onboarding/onboarding';
  7. import {OrganizationContext} from 'sentry/views/organizationContext';
  8. describe('Onboarding', function () {
  9. afterEach(function () {
  10. MockApiClient.clearMockResponses();
  11. });
  12. it('renders the welcome page', function () {
  13. const {organization, router, routerContext} = initializeOrg({
  14. router: {
  15. params: {
  16. step: 'welcome',
  17. },
  18. },
  19. });
  20. render(
  21. <OrganizationContext.Provider value={organization}>
  22. <PersistedStoreProvider>
  23. <Onboarding {...router} />
  24. </PersistedStoreProvider>
  25. </OrganizationContext.Provider>,
  26. {
  27. context: routerContext,
  28. }
  29. );
  30. expect(screen.getByLabelText('Start')).toBeInTheDocument();
  31. expect(screen.getByLabelText('Invite Team')).toBeInTheDocument();
  32. });
  33. it('renders the select platform step', async () => {
  34. const {organization, router, routerContext} = initializeOrg({
  35. router: {
  36. params: {
  37. step: 'select-platform',
  38. },
  39. },
  40. });
  41. MockApiClient.addMockResponse({
  42. url: `/organizations/${organization.slug}/client-state/`,
  43. body: {},
  44. });
  45. OrganizationStore.onUpdate(organization);
  46. render(
  47. <OrganizationContext.Provider value={organization}>
  48. <PersistedStoreProvider>
  49. <Onboarding {...router} />
  50. </PersistedStoreProvider>
  51. </OrganizationContext.Provider>,
  52. {
  53. context: routerContext,
  54. }
  55. );
  56. expect(
  57. await screen.findByText('Select the platforms you want to monitor')
  58. ).toBeInTheDocument();
  59. });
  60. it('renders the setup docs step', async () => {
  61. const projects = [
  62. TestStubs.Project({
  63. platform: 'javascript-react',
  64. id: '4',
  65. slug: 'javascript-reactslug',
  66. }),
  67. TestStubs.Project({platform: 'ruby', id: '5', slug: 'ruby-slug'}),
  68. TestStubs.Project({
  69. platform: 'javascript-nextjs',
  70. id: '6',
  71. slug: 'javascript-nextslug',
  72. }),
  73. ];
  74. const {organization, router, routerContext} = initializeOrg({
  75. projects,
  76. router: {
  77. params: {
  78. step: 'setup-docs',
  79. },
  80. },
  81. });
  82. MockApiClient.addMockResponse({
  83. url: `/organizations/${organization.slug}/client-state/`,
  84. body: {
  85. onboarding: {
  86. platformToProjectIdMap: {
  87. 'javascript-react': projects[0].slug,
  88. ruby: projects[1].slug,
  89. 'javascript-nextjs': projects[2].slug,
  90. },
  91. selectedPlatforms: ['ruby', 'javascript-nextjs'],
  92. },
  93. },
  94. });
  95. MockApiClient.addMockResponse({
  96. url: `/projects/${organization.slug}/ruby-slug/`,
  97. body: {
  98. firstEvent: false,
  99. },
  100. });
  101. MockApiClient.addMockResponse({
  102. url: `/projects/${organization.slug}/javascript-nextslug/docs/javascript-nextjs/`,
  103. body: null,
  104. });
  105. MockApiClient.addMockResponse({
  106. url: `/projects/${organization.slug}/ruby-slug/docs/ruby/`,
  107. body: null,
  108. });
  109. MockApiClient.addMockResponse({
  110. url: `/projects/${organization.slug}/ruby-slug/issues/`,
  111. body: [],
  112. });
  113. ProjectsStore.loadInitialData(projects);
  114. OrganizationStore.onUpdate(organization);
  115. render(
  116. <OrganizationContext.Provider value={organization}>
  117. <PersistedStoreProvider>
  118. <Onboarding {...router} />
  119. </PersistedStoreProvider>
  120. </OrganizationContext.Provider>,
  121. {
  122. context: routerContext,
  123. }
  124. );
  125. expect(await screen.findAllByTestId('sidebar-error-indicator')).toHaveLength(2);
  126. });
  127. });