platform.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import {ProjectInstallPlatform} from 'sentry/views/projectInstall/platform';
  5. function mockProjectApiResponses(projects) {
  6. MockApiClient.addMockResponse({
  7. method: 'GET',
  8. url: '/organizations/org-slug/projects/',
  9. body: projects,
  10. });
  11. MockApiClient.addMockResponse({
  12. method: 'GET',
  13. url: '/projects/org-slug/project-slug/rules/',
  14. body: [],
  15. });
  16. MockApiClient.addMockResponse({
  17. method: 'GET',
  18. url: '/projects/org-slug/project-slug/',
  19. body: projects,
  20. });
  21. MockApiClient.addMockResponse({
  22. url: '/projects/org-slug/project-slug/keys/',
  23. method: 'GET',
  24. body: [TestStubs.ProjectKeys()[0]],
  25. });
  26. MockApiClient.addMockResponse({
  27. url: `/projects/org-slug/project-slug/keys/${TestStubs.ProjectKeys()[0].public}/`,
  28. method: 'PUT',
  29. body: {},
  30. });
  31. }
  32. describe('ProjectInstallPlatform', function () {
  33. beforeEach(function () {
  34. MockApiClient.clearMockResponses();
  35. });
  36. it('should render NotFound if no matching integration/platform', async function () {
  37. const routeParams = {
  38. projectId: TestStubs.Project().slug,
  39. };
  40. const {organization, router, route, project, routerContext} = initializeOrg({
  41. router: {
  42. location: {
  43. query: {},
  44. },
  45. params: routeParams,
  46. },
  47. });
  48. mockProjectApiResponses([{...project, platform: 'lua'}]);
  49. render(
  50. <ProjectInstallPlatform
  51. router={router}
  52. route={route}
  53. location={router.location}
  54. routeParams={routeParams}
  55. routes={router.routes}
  56. params={routeParams}
  57. />,
  58. {
  59. organization,
  60. context: routerContext,
  61. }
  62. );
  63. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  64. });
  65. it('should redirect to neutral docs if no matching platform', async function () {
  66. const routeParams = {
  67. projectId: TestStubs.Project().slug,
  68. };
  69. const {organization, router, route, project, routerContext} = initializeOrg({
  70. router: {
  71. location: {
  72. query: {},
  73. },
  74. params: routeParams,
  75. },
  76. });
  77. // this is needed because we don't handle a loading state in the UI
  78. ProjectsStore.loadInitialData([{...project, platform: 'other'}]);
  79. mockProjectApiResponses([{...project, platform: 'other'}]);
  80. render(
  81. <ProjectInstallPlatform
  82. router={router}
  83. route={route}
  84. location={router.location}
  85. routeParams={routeParams}
  86. routes={router.routes}
  87. params={routeParams}
  88. />,
  89. {
  90. organization,
  91. context: routerContext,
  92. }
  93. );
  94. await waitFor(() => {
  95. expect(router.push).toHaveBeenCalledTimes(1);
  96. });
  97. });
  98. it('should render getting started docs for correct platform', async function () {
  99. const project = TestStubs.Project({platform: 'javascript'});
  100. const routeParams = {
  101. projectId: project.slug,
  102. platform: 'python',
  103. };
  104. const {router, route, routerContext} = initializeOrg({
  105. router: {
  106. location: {
  107. query: {},
  108. },
  109. params: routeParams,
  110. },
  111. });
  112. ProjectsStore.loadInitialData([project]);
  113. mockProjectApiResponses([project]);
  114. render(
  115. <ProjectInstallPlatform
  116. router={router}
  117. route={route}
  118. location={router.location}
  119. routeParams={routeParams}
  120. routes={router.routes}
  121. params={routeParams}
  122. />,
  123. {
  124. context: routerContext,
  125. }
  126. );
  127. expect(
  128. await screen.findByRole('heading', {
  129. name: 'Configure JavaScript SDK',
  130. })
  131. ).toBeInTheDocument();
  132. });
  133. });