onboarding.spec.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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 * as useRecentCreatedProjectHook from 'sentry/components/onboarding/useRecentCreatedProject';
  10. import {PlatformKey} from 'sentry/data/platformCategories';
  11. import {OnboardingProjectStatus, Project} from 'sentry/types';
  12. import Onboarding from 'sentry/views/onboarding/onboarding';
  13. describe('Onboarding', function () {
  14. afterEach(function () {
  15. MockApiClient.clearMockResponses();
  16. });
  17. it('renders the welcome page', function () {
  18. const routeParams = {
  19. step: 'welcome',
  20. };
  21. const {router, route, routerContext, organization} = initializeOrg({
  22. ...initializeOrg(),
  23. router: {
  24. params: routeParams,
  25. },
  26. });
  27. render(
  28. <OnboardingContextProvider>
  29. <Onboarding
  30. router={router}
  31. location={router.location}
  32. params={routeParams}
  33. routes={router.routes}
  34. routeParams={router.params}
  35. route={route}
  36. />
  37. </OnboardingContextProvider>,
  38. {
  39. context: routerContext,
  40. organization,
  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. render(
  57. <OnboardingContextProvider>
  58. <Onboarding
  59. router={router}
  60. location={router.location}
  61. params={routeParams}
  62. routes={router.routes}
  63. routeParams={router.params}
  64. route={route}
  65. />
  66. </OnboardingContextProvider>,
  67. {
  68. context: routerContext,
  69. organization,
  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. jest
  104. .spyOn(useRecentCreatedProjectHook, 'useRecentCreatedProject')
  105. .mockImplementation(() => {
  106. return {
  107. ...nextJsProject,
  108. firstError: false,
  109. firstTransaction: false,
  110. hasReplays: false,
  111. hasSessions: false,
  112. olderThanOneHour: false,
  113. firstIssue: undefined,
  114. };
  115. });
  116. render(
  117. <OnboardingContextProvider
  118. value={{
  119. selectedSDK: {
  120. key: nextJsProject.slug as PlatformKey,
  121. type: 'framework',
  122. language: 'javascript',
  123. category: 'browser',
  124. },
  125. projects: {
  126. [nextJsProject.id]: {
  127. slug: nextJsProject.slug,
  128. status: OnboardingProjectStatus.WAITING,
  129. firstIssueId: undefined,
  130. },
  131. },
  132. }}
  133. >
  134. <Onboarding
  135. router={router}
  136. location={router.location}
  137. params={routeParams}
  138. routes={router.routes}
  139. routeParams={router.params}
  140. route={route}
  141. />
  142. </OnboardingContextProvider>,
  143. {
  144. context: routerContext,
  145. organization,
  146. }
  147. );
  148. expect(await screen.findByText('Configure Next.js SDK')).toBeInTheDocument();
  149. });
  150. it('renders SDK data removal modal when going back', async function () {
  151. const reactProject: Project = TestStubs.Project({
  152. platform: 'javascript-react',
  153. id: '2',
  154. slug: 'javascript-react-slug',
  155. firstTransactionEvent: false,
  156. firstEvent: false,
  157. hasReplays: false,
  158. hasSessions: false,
  159. });
  160. const routeParams = {
  161. step: 'setup-docs',
  162. };
  163. const {router, route, routerContext, organization} = initializeOrg({
  164. ...initializeOrg(),
  165. organization: {
  166. ...initializeOrg().organization,
  167. features: ['onboarding-project-deletion-on-back-click'],
  168. },
  169. router: {
  170. params: routeParams,
  171. },
  172. });
  173. MockApiClient.addMockResponse({
  174. url: `/projects/${organization.slug}/${reactProject.slug}/docs/javascript-react-with-error-monitoring/`,
  175. body: null,
  176. });
  177. MockApiClient.addMockResponse({
  178. url: `/projects/org-slug/${reactProject.slug}/`,
  179. body: [reactProject],
  180. });
  181. MockApiClient.addMockResponse({
  182. url: `/projects/${organization.slug}/${reactProject.slug}/issues/`,
  183. body: [],
  184. });
  185. jest
  186. .spyOn(useRecentCreatedProjectHook, 'useRecentCreatedProject')
  187. .mockImplementation(() => {
  188. return {
  189. ...reactProject,
  190. firstError: false,
  191. firstTransaction: false,
  192. hasReplays: false,
  193. hasSessions: false,
  194. olderThanOneHour: false,
  195. firstIssue: undefined,
  196. };
  197. });
  198. render(
  199. <OnboardingContextProvider
  200. value={{
  201. selectedSDK: {
  202. key: reactProject.slug as PlatformKey,
  203. type: 'framework',
  204. language: 'javascript',
  205. category: 'browser',
  206. },
  207. projects: {
  208. [reactProject.id]: {
  209. slug: reactProject.slug,
  210. status: OnboardingProjectStatus.WAITING,
  211. firstIssueId: undefined,
  212. },
  213. },
  214. }}
  215. >
  216. <Onboarding
  217. router={router}
  218. location={router.location}
  219. params={routeParams}
  220. routes={router.routes}
  221. routeParams={router.params}
  222. route={route}
  223. />
  224. </OnboardingContextProvider>,
  225. {
  226. context: routerContext,
  227. organization,
  228. }
  229. );
  230. // Await for the docs to be loaded
  231. await screen.findByText('Configure React SDK');
  232. renderGlobalModal();
  233. // Click on back button
  234. await userEvent.click(screen.getByRole('button', {name: 'Back'}));
  235. // Await for the modal to be open
  236. expect(
  237. await screen.findByText(/Are you sure you want to head back?/)
  238. ).toBeInTheDocument();
  239. // Close modal
  240. await userEvent.click(screen.getByRole('button', {name: 'Cancel'}));
  241. });
  242. it('does not render SDK data removal modal when going back', async function () {
  243. const reactProject: Project = TestStubs.Project({
  244. platform: 'javascript-react',
  245. id: '2',
  246. slug: 'javascript-react-slug',
  247. });
  248. const routeParams = {
  249. step: 'setup-docs',
  250. };
  251. const {router, route, routerContext, organization} = initializeOrg({
  252. ...initializeOrg(),
  253. organization: {
  254. ...initializeOrg().organization,
  255. features: ['onboarding-project-deletion-on-back-click'],
  256. },
  257. router: {
  258. params: routeParams,
  259. },
  260. });
  261. MockApiClient.addMockResponse({
  262. url: `/projects/${organization.slug}/${reactProject.slug}/docs/javascript-react-with-error-monitoring/`,
  263. body: null,
  264. });
  265. MockApiClient.addMockResponse({
  266. url: `/projects/org-slug/${reactProject.slug}/`,
  267. body: [reactProject],
  268. });
  269. MockApiClient.addMockResponse({
  270. url: `/projects/${organization.slug}/${reactProject.slug}/issues/`,
  271. body: [],
  272. });
  273. jest
  274. .spyOn(useRecentCreatedProjectHook, 'useRecentCreatedProject')
  275. .mockImplementation(() => {
  276. return {
  277. ...reactProject,
  278. firstError: false,
  279. firstTransaction: false,
  280. hasReplays: false,
  281. hasSessions: true,
  282. olderThanOneHour: false,
  283. firstIssue: undefined,
  284. };
  285. });
  286. render(
  287. <OnboardingContextProvider
  288. value={{
  289. selectedSDK: {
  290. key: reactProject.slug as PlatformKey,
  291. type: 'framework',
  292. language: 'javascript',
  293. category: 'browser',
  294. },
  295. projects: {
  296. [reactProject.id]: {
  297. slug: reactProject.slug,
  298. status: OnboardingProjectStatus.WAITING,
  299. firstIssueId: undefined,
  300. },
  301. },
  302. }}
  303. >
  304. <Onboarding
  305. router={router}
  306. location={router.location}
  307. params={routeParams}
  308. routes={router.routes}
  309. routeParams={router.params}
  310. route={route}
  311. />
  312. </OnboardingContextProvider>,
  313. {
  314. context: routerContext,
  315. organization,
  316. }
  317. );
  318. // Await for the docs to be loaded
  319. await screen.findByText('Configure React SDK');
  320. renderGlobalModal();
  321. // Click on back button
  322. await userEvent.click(screen.getByRole('button', {name: 'Back'}));
  323. // Await for the modal to be open
  324. expect(
  325. screen.queryByText(/Are you sure you want to head back?/)
  326. ).not.toBeInTheDocument();
  327. });
  328. it('renders framework selection modal if vanilla js is selected', async function () {
  329. const routeParams = {
  330. step: 'select-platform',
  331. };
  332. const {router, route, routerContext, organization} = initializeOrg({
  333. ...initializeOrg(),
  334. organization: {
  335. ...initializeOrg().organization,
  336. features: ['onboarding-sdk-selection'],
  337. },
  338. router: {
  339. params: routeParams,
  340. },
  341. });
  342. render(
  343. <OnboardingContextProvider>
  344. <Onboarding
  345. router={router}
  346. location={router.location}
  347. params={routeParams}
  348. routes={router.routes}
  349. routeParams={router.params}
  350. route={route}
  351. />
  352. </OnboardingContextProvider>,
  353. {
  354. context: routerContext,
  355. organization,
  356. }
  357. );
  358. renderGlobalModal();
  359. // Select the JavaScript platform
  360. await userEvent.click(screen.getByTestId('platform-javascript'));
  361. // Click on 'configure SDK' button
  362. await userEvent.click(screen.getByRole('button', {name: 'Configure SDK'}));
  363. // Modal is open
  364. await screen.findByText('Do you use a framework?');
  365. // Close modal
  366. await userEvent.click(screen.getByRole('button', {name: 'Skip'}));
  367. });
  368. it('does not render framework selection modal if vanilla js is NOT selected', async function () {
  369. const routeParams = {
  370. step: 'select-platform',
  371. };
  372. const {router, route, routerContext, organization} = initializeOrg({
  373. ...initializeOrg(),
  374. organization: {
  375. ...initializeOrg().organization,
  376. features: ['onboarding-sdk-selection'],
  377. },
  378. router: {
  379. params: routeParams,
  380. },
  381. });
  382. render(
  383. <OnboardingContextProvider>
  384. <Onboarding
  385. router={router}
  386. location={router.location}
  387. params={routeParams}
  388. routes={router.routes}
  389. routeParams={router.params}
  390. route={route}
  391. />
  392. </OnboardingContextProvider>,
  393. {
  394. context: routerContext,
  395. organization,
  396. }
  397. );
  398. // Select the React platform
  399. await userEvent.click(screen.getByTestId('platform-javascript-react'));
  400. // Click on 'configure SDK' button
  401. await userEvent.click(screen.getByRole('button', {name: 'Configure SDK'}));
  402. // Modal shall not be open
  403. expect(screen.queryByText('Do you use a framework?')).not.toBeInTheDocument();
  404. });
  405. });