platform.spec.tsx 3.9 KB

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