setupDocs.spec.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. import {ProjectKeys} from 'sentry-fixture/projectKeys';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  4. import {OnboardingContextProvider} from 'sentry/components/onboarding/onboardingContext';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import ProjectsStore from 'sentry/stores/projectsStore';
  7. import {Organization, Project} from 'sentry/types';
  8. import SetupDocs from 'sentry/views/onboarding/setupDocs';
  9. const PROJECT_KEY = ProjectKeys()[0];
  10. function renderMockRequests({
  11. project,
  12. orgSlug,
  13. }: {
  14. orgSlug: Organization['slug'];
  15. project: Project;
  16. }) {
  17. MockApiClient.addMockResponse({
  18. url: `/projects/${orgSlug}/${project.slug}/`,
  19. body: project,
  20. });
  21. MockApiClient.addMockResponse({
  22. url: `/projects/${orgSlug}/${project.slug}/keys/`,
  23. body: [PROJECT_KEY],
  24. });
  25. MockApiClient.addMockResponse({
  26. url: `/projects/${orgSlug}/${project.slug}/issues/`,
  27. body: [],
  28. });
  29. MockApiClient.addMockResponse({
  30. url: `/organizations/${orgSlug}/sdks/`,
  31. body: {
  32. 'sentry.java.android.gradle-plugin': {
  33. canonical: 'maven:io.sentry:sentry',
  34. main_docs_url: 'https://docs.sentry.io/platforms/java',
  35. name: 'io.sentry:sentry',
  36. package_url: 'https://search.maven.org/artifact/io.sentry/sentry',
  37. repo_url: 'https://github.com/getsentry/sentry-java',
  38. version: '3.12.0',
  39. },
  40. },
  41. });
  42. if (project.slug !== 'javascript-react') {
  43. MockApiClient.addMockResponse({
  44. url: `/projects/${orgSlug}/${project.slug}/docs/${project.platform}/`,
  45. body: {html: ''},
  46. });
  47. }
  48. }
  49. describe('Onboarding Setup Docs', function () {
  50. it('does not render Product Selection', async function () {
  51. const {router, route, routerContext, organization, project} = initializeOrg({
  52. projects: [
  53. {
  54. ...initializeOrg().project,
  55. slug: 'python',
  56. platform: 'python',
  57. },
  58. ],
  59. });
  60. ProjectsStore.init();
  61. ProjectsStore.loadInitialData([project]);
  62. renderMockRequests({project, orgSlug: organization.slug});
  63. render(
  64. <OnboardingContextProvider>
  65. <SetupDocs
  66. active
  67. onComplete={() => {}}
  68. stepIndex={2}
  69. router={router}
  70. route={route}
  71. location={router.location}
  72. genSkipOnboardingLink={() => ''}
  73. orgId={organization.slug}
  74. search=""
  75. recentCreatedProject={project}
  76. />
  77. </OnboardingContextProvider>,
  78. {
  79. context: routerContext,
  80. organization,
  81. }
  82. );
  83. expect(
  84. await screen.findByRole('heading', {name: 'Configure Python SDK'})
  85. ).toBeInTheDocument();
  86. expect(
  87. screen.queryByTestId(
  88. `product-${ProductSolution.ERROR_MONITORING}-${ProductSolution.PERFORMANCE_MONITORING}-${ProductSolution.SESSION_REPLAY}`
  89. )
  90. ).not.toBeInTheDocument();
  91. });
  92. it('renders SDK version from the sentry release registry', async function () {
  93. const {router, route, routerContext, organization, project} = initializeOrg({
  94. projects: [
  95. {
  96. ...initializeOrg().project,
  97. slug: 'java',
  98. platform: 'java',
  99. },
  100. ],
  101. });
  102. ProjectsStore.init();
  103. ProjectsStore.loadInitialData([project]);
  104. renderMockRequests({project, orgSlug: organization.slug});
  105. render(
  106. <OnboardingContextProvider>
  107. <SetupDocs
  108. active
  109. onComplete={() => {}}
  110. stepIndex={2}
  111. router={router}
  112. route={route}
  113. location={router.location}
  114. genSkipOnboardingLink={() => ''}
  115. orgId={organization.slug}
  116. search=""
  117. recentCreatedProject={project}
  118. />
  119. </OnboardingContextProvider>,
  120. {
  121. context: routerContext,
  122. organization,
  123. }
  124. );
  125. expect(
  126. await screen.findByText(/id "io.sentry.jvm.gradle" version "3.12.0"/)
  127. ).toBeInTheDocument();
  128. });
  129. describe('renders Product Selection', function () {
  130. it('all products checked', async function () {
  131. const {router, route, routerContext, organization, project} = initializeOrg({
  132. router: {
  133. location: {
  134. query: {
  135. product: [
  136. ProductSolution.PERFORMANCE_MONITORING,
  137. ProductSolution.SESSION_REPLAY,
  138. ],
  139. },
  140. },
  141. },
  142. projects: [
  143. {
  144. ...initializeOrg().project,
  145. slug: 'javascript-react',
  146. platform: 'javascript-react',
  147. },
  148. ],
  149. });
  150. ProjectsStore.init();
  151. ProjectsStore.loadInitialData([project]);
  152. renderMockRequests({
  153. project,
  154. orgSlug: organization.slug,
  155. });
  156. render(
  157. <OnboardingContextProvider>
  158. <SetupDocs
  159. active
  160. onComplete={() => {}}
  161. stepIndex={2}
  162. router={router}
  163. route={route}
  164. location={router.location}
  165. genSkipOnboardingLink={() => ''}
  166. orgId={organization.slug}
  167. search=""
  168. recentCreatedProject={project}
  169. />
  170. </OnboardingContextProvider>,
  171. {
  172. context: routerContext,
  173. organization,
  174. }
  175. );
  176. expect(
  177. await screen.findByRole('heading', {name: 'Configure React SDK'})
  178. ).toBeInTheDocument();
  179. expect(await screen.findByText('// Performance Monitoring')).toBeInTheDocument();
  180. expect(screen.getByText('// Session Replay')).toBeInTheDocument();
  181. });
  182. it('only performance checked', async function () {
  183. const {router, route, routerContext, organization, project} = initializeOrg({
  184. router: {
  185. location: {
  186. query: {product: [ProductSolution.PERFORMANCE_MONITORING]},
  187. },
  188. },
  189. projects: [
  190. {
  191. ...initializeOrg().project,
  192. slug: 'javascript-react',
  193. platform: 'javascript-react',
  194. },
  195. ],
  196. });
  197. ProjectsStore.init();
  198. ProjectsStore.loadInitialData([project]);
  199. renderMockRequests({
  200. project,
  201. orgSlug: organization.slug,
  202. });
  203. render(
  204. <OnboardingContextProvider>
  205. <SetupDocs
  206. active
  207. onComplete={() => {}}
  208. stepIndex={2}
  209. router={router}
  210. route={route}
  211. location={router.location}
  212. genSkipOnboardingLink={() => ''}
  213. orgId={organization.slug}
  214. search=""
  215. recentCreatedProject={project}
  216. />
  217. </OnboardingContextProvider>,
  218. {
  219. context: routerContext,
  220. organization,
  221. }
  222. );
  223. expect(await screen.findByText('// Performance Monitoring')).toBeInTheDocument();
  224. expect(screen.queryByText('// Session Replay')).not.toBeInTheDocument();
  225. });
  226. it('only session replay checked', async function () {
  227. const {router, route, routerContext, organization, project} = initializeOrg({
  228. router: {
  229. location: {
  230. query: {product: [ProductSolution.SESSION_REPLAY]},
  231. },
  232. },
  233. projects: [
  234. {
  235. ...initializeOrg().project,
  236. slug: 'javascript-react',
  237. platform: 'javascript-react',
  238. },
  239. ],
  240. });
  241. ProjectsStore.init();
  242. ProjectsStore.loadInitialData([project]);
  243. renderMockRequests({
  244. project,
  245. orgSlug: organization.slug,
  246. });
  247. render(
  248. <OnboardingContextProvider>
  249. <SetupDocs
  250. active
  251. onComplete={() => {}}
  252. stepIndex={2}
  253. router={router}
  254. route={route}
  255. location={router.location}
  256. genSkipOnboardingLink={() => ''}
  257. orgId={organization.slug}
  258. search=""
  259. recentCreatedProject={project}
  260. />
  261. </OnboardingContextProvider>,
  262. {
  263. context: routerContext,
  264. organization,
  265. }
  266. );
  267. expect(await screen.findByText('// Session Replay')).toBeInTheDocument();
  268. expect(screen.queryByText('// Performance Monitoring')).not.toBeInTheDocument();
  269. });
  270. it('only error monitoring checked', async function () {
  271. const {router, route, routerContext, organization, project} = initializeOrg({
  272. router: {
  273. location: {
  274. query: {product: []},
  275. },
  276. },
  277. projects: [
  278. {
  279. ...initializeOrg().project,
  280. slug: 'javascript-react',
  281. platform: 'javascript-react',
  282. },
  283. ],
  284. });
  285. ProjectsStore.init();
  286. ProjectsStore.loadInitialData([project]);
  287. renderMockRequests({
  288. project,
  289. orgSlug: organization.slug,
  290. });
  291. render(
  292. <OnboardingContextProvider>
  293. <SetupDocs
  294. active
  295. onComplete={() => {}}
  296. stepIndex={2}
  297. router={router}
  298. route={route}
  299. location={router.location}
  300. genSkipOnboardingLink={() => ''}
  301. orgId={organization.slug}
  302. search=""
  303. recentCreatedProject={project}
  304. />
  305. </OnboardingContextProvider>,
  306. {
  307. context: routerContext,
  308. organization,
  309. }
  310. );
  311. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  312. expect(screen.queryByText('// Session Replay')).not.toBeInTheDocument();
  313. expect(screen.queryByText('// Performance Monitoring')).not.toBeInTheDocument();
  314. });
  315. });
  316. describe('JS Loader Script', function () {
  317. it('renders Loader Script setup', async function () {
  318. const {router, route, routerContext, organization, project} = initializeOrg({
  319. router: {
  320. location: {
  321. query: {
  322. product: [
  323. ProductSolution.PERFORMANCE_MONITORING,
  324. ProductSolution.SESSION_REPLAY,
  325. ],
  326. },
  327. },
  328. },
  329. projects: [
  330. {
  331. ...initializeOrg().project,
  332. slug: 'javascript',
  333. platform: 'javascript',
  334. },
  335. ],
  336. });
  337. const updateLoaderMock = MockApiClient.addMockResponse({
  338. url: `/projects/${organization.slug}/${project.slug}/keys/${PROJECT_KEY.id}/`,
  339. method: 'PUT',
  340. body: PROJECT_KEY,
  341. });
  342. ProjectsStore.init();
  343. ProjectsStore.loadInitialData([project]);
  344. renderMockRequests({
  345. project,
  346. orgSlug: organization.slug,
  347. });
  348. const {rerender} = render(
  349. <OnboardingContextProvider>
  350. <SetupDocs
  351. active
  352. onComplete={() => {}}
  353. stepIndex={2}
  354. router={router}
  355. route={route}
  356. location={router.location}
  357. genSkipOnboardingLink={() => ''}
  358. orgId={organization.slug}
  359. search=""
  360. recentCreatedProject={project}
  361. />
  362. </OnboardingContextProvider>,
  363. {
  364. context: routerContext,
  365. organization,
  366. }
  367. );
  368. expect(
  369. await screen.findByRole('heading', {name: 'Configure Browser JavaScript SDK'})
  370. ).toBeInTheDocument();
  371. expect(updateLoaderMock).toHaveBeenCalledTimes(1);
  372. expect(updateLoaderMock).toHaveBeenCalledWith(
  373. expect.any(String), // The URL
  374. {
  375. data: {
  376. dynamicSdkLoaderOptions: {
  377. hasDebug: false,
  378. hasPerformance: true,
  379. hasReplay: true,
  380. },
  381. },
  382. error: expect.any(Function),
  383. method: 'PUT',
  384. success: expect.any(Function),
  385. }
  386. );
  387. // update query in URL
  388. router.location.query = {
  389. product: [ProductSolution.SESSION_REPLAY],
  390. };
  391. rerender(
  392. <OnboardingContextProvider>
  393. <SetupDocs
  394. active
  395. onComplete={() => {}}
  396. stepIndex={2}
  397. router={router}
  398. route={route}
  399. location={router.location}
  400. genSkipOnboardingLink={() => ''}
  401. orgId={organization.slug}
  402. search=""
  403. recentCreatedProject={project}
  404. />
  405. </OnboardingContextProvider>
  406. );
  407. expect(updateLoaderMock).toHaveBeenCalledTimes(2);
  408. expect(updateLoaderMock).toHaveBeenLastCalledWith(
  409. expect.any(String), // The URL
  410. {
  411. data: {
  412. dynamicSdkLoaderOptions: {
  413. hasDebug: false,
  414. hasPerformance: false,
  415. hasReplay: true,
  416. },
  417. },
  418. error: expect.any(Function),
  419. method: 'PUT',
  420. success: expect.any(Function),
  421. }
  422. );
  423. });
  424. });
  425. describe('special platforms', () => {
  426. it('renders platform other', async function () {
  427. const {router, route, routerContext, organization, project} = initializeOrg({
  428. projects: [
  429. {
  430. ...initializeOrg().project,
  431. slug: 'other',
  432. platform: 'other',
  433. },
  434. ],
  435. });
  436. ProjectsStore.init();
  437. ProjectsStore.loadInitialData([project]);
  438. renderMockRequests({project, orgSlug: organization.slug});
  439. render(
  440. <OnboardingContextProvider>
  441. <SetupDocs
  442. active
  443. onComplete={() => {}}
  444. stepIndex={2}
  445. router={router}
  446. route={route}
  447. location={router.location}
  448. genSkipOnboardingLink={() => ''}
  449. orgId={organization.slug}
  450. search=""
  451. recentCreatedProject={project}
  452. />
  453. </OnboardingContextProvider>,
  454. {
  455. context: routerContext,
  456. organization,
  457. }
  458. );
  459. expect(
  460. await screen.findByRole('heading', {name: 'Configure Other SDK'})
  461. ).toBeInTheDocument();
  462. });
  463. });
  464. });