platform.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. describe('ProjectInstallPlatform', function () {
  6. it('should render NotFound if no matching integration/platform', async function () {
  7. const routeParams = {
  8. projectId: TestStubs.Project().slug,
  9. };
  10. const {organization, router, route, project, routerContext} = initializeOrg({
  11. router: {
  12. location: {
  13. query: {},
  14. },
  15. params: routeParams,
  16. },
  17. });
  18. MockApiClient.addMockResponse({
  19. method: 'GET',
  20. url: '/organizations/org-slug/projects/',
  21. body: [{...project, platform: 'lua'}],
  22. });
  23. MockApiClient.addMockResponse({
  24. method: 'GET',
  25. url: '/projects/org-slug/project-slug/rules/',
  26. body: [],
  27. });
  28. MockApiClient.addMockResponse({
  29. method: 'GET',
  30. url: '/projects/org-slug/project-slug/',
  31. body: [{...project, platform: 'lua'}],
  32. });
  33. render(
  34. <ProjectInstallPlatform
  35. router={router}
  36. route={route}
  37. location={router.location}
  38. routeParams={routeParams}
  39. routes={router.routes}
  40. params={routeParams}
  41. />,
  42. {
  43. organization,
  44. context: routerContext,
  45. }
  46. );
  47. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  48. });
  49. it('should redirect to neutral docs if no matching platform', async function () {
  50. const routeParams = {
  51. projectId: TestStubs.Project().slug,
  52. };
  53. const {organization, router, route, project, routerContext} = initializeOrg({
  54. router: {
  55. location: {
  56. query: {},
  57. },
  58. params: routeParams,
  59. },
  60. });
  61. // this is needed because we don't handle a loading state in the UI
  62. ProjectsStore.loadInitialData([{...project, platform: 'other'}]);
  63. MockApiClient.addMockResponse({
  64. method: 'GET',
  65. url: '/organizations/org-slug/projects/',
  66. body: [{...project, platform: 'other'}],
  67. });
  68. MockApiClient.addMockResponse({
  69. method: 'GET',
  70. url: '/projects/org-slug/project-slug/rules/',
  71. body: [],
  72. });
  73. MockApiClient.addMockResponse({
  74. method: 'GET',
  75. url: '/projects/org-slug/project-slug/',
  76. body: [{...project, platform: 'other'}],
  77. });
  78. render(
  79. <ProjectInstallPlatform
  80. router={router}
  81. route={route}
  82. location={router.location}
  83. routeParams={routeParams}
  84. routes={router.routes}
  85. params={routeParams}
  86. />,
  87. {
  88. organization,
  89. context: routerContext,
  90. }
  91. );
  92. await waitFor(() => {
  93. expect(router.push).toHaveBeenCalledTimes(1);
  94. });
  95. });
  96. });