setupDocs.spec.tsx 14 KB

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