platform.spec.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import {ProjectInstallPlatform} from 'sentry/views/projectInstall/platform';
  4. describe('ProjectInstallPlatform', function () {
  5. describe('render()', function () {
  6. const api = new MockApiClient();
  7. it('should redirect to if no matching platform', async function () {
  8. const {organization, router, project, routerContext} = initializeOrg({
  9. router: {
  10. location: {
  11. query: {},
  12. },
  13. params: {
  14. projectId: TestStubs.Project().slug,
  15. platform: 'other',
  16. },
  17. },
  18. });
  19. MockApiClient.addMockResponse({
  20. url: `/projects/org-slug/${project.slug}/docs/other/`,
  21. body: {},
  22. });
  23. MockApiClient.addMockResponse({
  24. method: 'GET',
  25. url: '/organizations/org-slug/projects/',
  26. body: [project],
  27. });
  28. render(
  29. <ProjectInstallPlatform
  30. api={api}
  31. organization={organization}
  32. routes={router.routes}
  33. router={router}
  34. location={router.location}
  35. params={router.params}
  36. />,
  37. {
  38. organization,
  39. context: routerContext,
  40. }
  41. );
  42. await waitFor(() => {
  43. expect(router.push).toHaveBeenCalledTimes(1);
  44. });
  45. });
  46. it('should render NotFound if no matching integration/platform', async function () {
  47. const {organization, router, project, routerContext} = initializeOrg({
  48. router: {
  49. location: {
  50. query: {},
  51. },
  52. params: {
  53. projectId: TestStubs.Project().slug,
  54. platform: 'lua',
  55. },
  56. },
  57. });
  58. MockApiClient.addMockResponse({
  59. url: '/projects/org-slug/project-slug/docs/lua/',
  60. statusCode: 404,
  61. });
  62. MockApiClient.addMockResponse({
  63. method: 'GET',
  64. url: '/organizations/org-slug/projects/',
  65. body: [project],
  66. });
  67. render(
  68. <ProjectInstallPlatform
  69. api={api}
  70. organization={organization}
  71. routes={router.routes}
  72. router={router}
  73. location={router.location}
  74. params={router.params}
  75. />,
  76. {
  77. organization,
  78. context: routerContext,
  79. }
  80. );
  81. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  82. });
  83. it('should render documentation', async function () {
  84. const {organization, router, project, routerContext} = initializeOrg({
  85. router: {
  86. location: {
  87. query: {},
  88. },
  89. params: {
  90. projectId: TestStubs.Project().slug,
  91. platform: 'node',
  92. },
  93. },
  94. });
  95. MockApiClient.addMockResponse({
  96. url: '/projects/org-slug/project-slug/docs/node/',
  97. body: {html: '<h1>Documentation here</h1>'},
  98. });
  99. MockApiClient.addMockResponse({
  100. method: 'GET',
  101. url: '/organizations/org-slug/projects/',
  102. body: [project],
  103. });
  104. render(
  105. <ProjectInstallPlatform
  106. api={api}
  107. organization={organization}
  108. routes={router.routes}
  109. router={router}
  110. location={router.location}
  111. params={router.params}
  112. />,
  113. {
  114. organization,
  115. context: routerContext,
  116. }
  117. );
  118. expect(await screen.findByText('Documentation here')).toBeInTheDocument();
  119. });
  120. });
  121. });