platform.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. }
  22. describe('ProjectInstallPlatform', function () {
  23. beforeEach(function () {
  24. MockApiClient.clearMockResponses();
  25. });
  26. it('should render NotFound if no matching integration/platform', async function () {
  27. const routeParams = {
  28. projectId: TestStubs.Project().slug,
  29. };
  30. const {organization, router, route, project, routerContext} = initializeOrg({
  31. router: {
  32. location: {
  33. query: {},
  34. },
  35. params: routeParams,
  36. },
  37. });
  38. mockProjectApiResponses([{...project, platform: 'lua'}]);
  39. render(
  40. <ProjectInstallPlatform
  41. router={router}
  42. route={route}
  43. location={router.location}
  44. routeParams={routeParams}
  45. routes={router.routes}
  46. params={routeParams}
  47. />,
  48. {
  49. organization,
  50. context: routerContext,
  51. }
  52. );
  53. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  54. });
  55. it('should redirect to neutral docs if no matching platform', async function () {
  56. const routeParams = {
  57. projectId: TestStubs.Project().slug,
  58. };
  59. const {organization, router, route, project, routerContext} = initializeOrg({
  60. router: {
  61. location: {
  62. query: {},
  63. },
  64. params: routeParams,
  65. },
  66. });
  67. // this is needed because we don't handle a loading state in the UI
  68. ProjectsStore.loadInitialData([{...project, platform: 'other'}]);
  69. mockProjectApiResponses([{...project, platform: 'other'}]);
  70. render(
  71. <ProjectInstallPlatform
  72. router={router}
  73. route={route}
  74. location={router.location}
  75. routeParams={routeParams}
  76. routes={router.routes}
  77. params={routeParams}
  78. />,
  79. {
  80. organization,
  81. context: routerContext,
  82. }
  83. );
  84. await waitFor(() => {
  85. expect(router.push).toHaveBeenCalledTimes(1);
  86. });
  87. });
  88. it('should render getting started docs for correct platform', async function () {
  89. const project = TestStubs.Project({platform: 'javascript'});
  90. const routeParams = {
  91. projectId: project.slug,
  92. platform: 'python',
  93. };
  94. const {router, route, routerContext} = initializeOrg({
  95. router: {
  96. location: {
  97. query: {},
  98. },
  99. params: routeParams,
  100. },
  101. });
  102. ProjectsStore.loadInitialData([project]);
  103. mockProjectApiResponses([project]);
  104. render(
  105. <ProjectInstallPlatform
  106. router={router}
  107. route={route}
  108. location={router.location}
  109. routeParams={routeParams}
  110. routes={router.routes}
  111. params={routeParams}
  112. />,
  113. {
  114. context: routerContext,
  115. }
  116. );
  117. expect(
  118. await screen.findByRole('heading', {
  119. name: 'Configure JavaScript SDK',
  120. })
  121. ).toBeInTheDocument();
  122. });
  123. });