onboarding.spec.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import {OnboardingContextProvider} from 'sentry/components/onboarding/onboardingContext';
  9. import {PlatformKey} from 'sentry/data/platformCategories';
  10. import OrganizationStore from 'sentry/stores/organizationStore';
  11. import ProjectsStore from 'sentry/stores/projectsStore';
  12. import {OnboardingProjectStatus, Project} from 'sentry/types';
  13. import Onboarding from 'sentry/views/onboarding/onboarding';
  14. describe('Onboarding', function () {
  15. afterEach(function () {
  16. MockApiClient.clearMockResponses();
  17. });
  18. it('renders the welcome page', function () {
  19. const routeParams = {
  20. step: 'welcome',
  21. };
  22. const {router, route, routerContext} = initializeOrg({
  23. ...initializeOrg(),
  24. router: {
  25. params: routeParams,
  26. },
  27. });
  28. render(
  29. <OnboardingContextProvider>
  30. <Onboarding
  31. router={router}
  32. location={router.location}
  33. params={routeParams}
  34. routes={router.routes}
  35. routeParams={router.params}
  36. route={route}
  37. />
  38. </OnboardingContextProvider>,
  39. {
  40. context: routerContext,
  41. }
  42. );
  43. expect(screen.getByLabelText('Start')).toBeInTheDocument();
  44. expect(screen.getByLabelText('Invite Team')).toBeInTheDocument();
  45. });
  46. it('renders the select platform step', async function () {
  47. const routeParams = {
  48. step: 'select-platform',
  49. };
  50. const {router, route, routerContext, organization} = initializeOrg({
  51. ...initializeOrg(),
  52. router: {
  53. params: routeParams,
  54. },
  55. });
  56. OrganizationStore.onUpdate(organization);
  57. render(
  58. <OnboardingContextProvider>
  59. <Onboarding
  60. router={router}
  61. location={router.location}
  62. params={routeParams}
  63. routes={router.routes}
  64. routeParams={router.params}
  65. route={route}
  66. />
  67. </OnboardingContextProvider>,
  68. {
  69. context: routerContext,
  70. }
  71. );
  72. expect(
  73. await screen.findByText('Select the platform you want to monitor')
  74. ).toBeInTheDocument();
  75. });
  76. it('renders the setup docs step', async function () {
  77. const nextJsProject: Project = TestStubs.Project({
  78. platform: 'javascript-nextjs',
  79. id: '2',
  80. slug: 'javascript-nextjs-slug',
  81. });
  82. const routeParams = {
  83. step: 'setup-docs',
  84. };
  85. const {router, route, routerContext, organization} = initializeOrg({
  86. ...initializeOrg(),
  87. router: {
  88. params: routeParams,
  89. },
  90. });
  91. MockApiClient.addMockResponse({
  92. url: `/projects/${organization.slug}/${nextJsProject.slug}/docs/javascript-nextjs-with-error-monitoring/`,
  93. body: null,
  94. });
  95. MockApiClient.addMockResponse({
  96. url: `/projects/org-slug/${nextJsProject.slug}/`,
  97. body: [nextJsProject],
  98. });
  99. MockApiClient.addMockResponse({
  100. url: `/projects/${organization.slug}/${nextJsProject.slug}/issues/`,
  101. body: [],
  102. });
  103. ProjectsStore.loadInitialData([nextJsProject]);
  104. OrganizationStore.onUpdate(organization);
  105. render(
  106. <OnboardingContextProvider
  107. value={{
  108. selectedSDK: {
  109. key: nextJsProject.slug as PlatformKey,
  110. type: 'framework',
  111. language: 'javascript',
  112. category: 'browser',
  113. },
  114. projects: {
  115. [nextJsProject.id]: {
  116. slug: nextJsProject.slug,
  117. status: OnboardingProjectStatus.WAITING,
  118. firstIssueId: undefined,
  119. },
  120. },
  121. }}
  122. >
  123. <Onboarding
  124. router={router}
  125. location={router.location}
  126. params={routeParams}
  127. routes={router.routes}
  128. routeParams={router.params}
  129. route={route}
  130. />
  131. </OnboardingContextProvider>,
  132. {
  133. context: routerContext,
  134. }
  135. );
  136. expect(await screen.findByText('Configure Next.js SDK')).toBeInTheDocument();
  137. });
  138. it('renders framework selection modal if vanilla js is selected', async function () {
  139. const routeParams = {
  140. step: 'select-platform',
  141. };
  142. const {router, route, routerContext, organization} = initializeOrg({
  143. ...initializeOrg(),
  144. organization: {
  145. ...initializeOrg().organization,
  146. features: ['onboarding-sdk-selection'],
  147. },
  148. router: {
  149. params: routeParams,
  150. },
  151. });
  152. render(
  153. <OnboardingContextProvider>
  154. <Onboarding
  155. router={router}
  156. location={router.location}
  157. params={routeParams}
  158. routes={router.routes}
  159. routeParams={router.params}
  160. route={route}
  161. />
  162. </OnboardingContextProvider>,
  163. {
  164. context: routerContext,
  165. organization,
  166. }
  167. );
  168. renderGlobalModal();
  169. // Select the JavaScript platform
  170. await userEvent.click(screen.getByTestId('platform-javascript'));
  171. // Click on create project button
  172. await userEvent.click(screen.getByRole('button', {name: 'Create Project'}));
  173. // Modal is open
  174. await screen.findByText('Do you use a framework?');
  175. // Close modal
  176. await userEvent.click(screen.getByRole('button', {name: 'Skip'}));
  177. });
  178. it('does not render framework selection modal if vanilla js is NOT selected', async function () {
  179. const routeParams = {
  180. step: 'select-platform',
  181. };
  182. const {router, route, routerContext, organization} = initializeOrg({
  183. ...initializeOrg(),
  184. organization: {
  185. ...initializeOrg().organization,
  186. features: ['onboarding-sdk-selection'],
  187. },
  188. router: {
  189. params: routeParams,
  190. },
  191. });
  192. render(
  193. <OnboardingContextProvider>
  194. <Onboarding
  195. router={router}
  196. location={router.location}
  197. params={routeParams}
  198. routes={router.routes}
  199. routeParams={router.params}
  200. route={route}
  201. />
  202. </OnboardingContextProvider>,
  203. {
  204. context: routerContext,
  205. organization,
  206. }
  207. );
  208. // Select the React platform
  209. await userEvent.click(screen.getByTestId('platform-javascript-react'));
  210. // Click on create project button
  211. await userEvent.click(screen.getByRole('button', {name: 'Create Project'}));
  212. // Modal shall not be open
  213. expect(screen.queryByText('Do you use a framework?')).not.toBeInTheDocument();
  214. });
  215. });