platform.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} 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 display info for a non-supported platform', async function () {
  72. const routeParams = {
  73. projectId: TestStubs.Project().slug,
  74. };
  75. const {organization, router, route, project} = 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. }
  98. );
  99. expect(
  100. await screen.findByText(/We cannot provide instructions for 'other' projects/)
  101. ).toBeInTheDocument();
  102. });
  103. it('should render getting started docs for correct platform', async function () {
  104. const project = TestStubs.Project({platform: 'javascript'});
  105. const routeParams = {
  106. projectId: project.slug,
  107. platform: 'python',
  108. };
  109. const {router, route, routerContext} = initializeOrg({
  110. router: {
  111. location: {
  112. query: {},
  113. },
  114. params: routeParams,
  115. },
  116. });
  117. ProjectsStore.loadInitialData([project]);
  118. mockProjectApiResponses([project]);
  119. render(
  120. <ProjectInstallPlatform
  121. router={router}
  122. route={route}
  123. location={router.location}
  124. routeParams={routeParams}
  125. routes={router.routes}
  126. params={routeParams}
  127. />,
  128. {
  129. context: routerContext,
  130. }
  131. );
  132. expect(
  133. await screen.findByRole('heading', {
  134. name: 'Configure JavaScript SDK',
  135. })
  136. ).toBeInTheDocument();
  137. });
  138. });