platform.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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, routerProps, project, routerContext} = initializeOrg({
  47. router: {
  48. location: {
  49. query: {},
  50. },
  51. params: routeParams,
  52. },
  53. });
  54. mockProjectApiResponses([{...project, platform: 'lua'}]);
  55. render(<ProjectInstallPlatform {...routerProps} />, {
  56. organization,
  57. context: routerContext,
  58. });
  59. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  60. });
  61. it('should display info for a non-supported platform', async function () {
  62. const routeParams = {
  63. projectId: TestStubs.Project().slug,
  64. };
  65. const {organization, routerProps, project} = initializeOrg({
  66. router: {
  67. location: {
  68. query: {},
  69. },
  70. params: routeParams,
  71. },
  72. });
  73. // this is needed because we don't handle a loading state in the UI
  74. ProjectsStore.loadInitialData([{...project, platform: 'other'}]);
  75. mockProjectApiResponses([{...project, platform: 'other'}]);
  76. render(<ProjectInstallPlatform {...routerProps} />, {
  77. organization,
  78. });
  79. expect(
  80. await screen.findByText(/We cannot provide instructions for 'Other' projects/)
  81. ).toBeInTheDocument();
  82. });
  83. it('should render getting started docs for correct platform', async function () {
  84. const project = TestStubs.Project({platform: 'javascript'});
  85. const routeParams = {
  86. projectId: project.slug,
  87. platform: 'python',
  88. };
  89. const {routerProps, routerContext} = initializeOrg({
  90. router: {
  91. location: {
  92. query: {},
  93. },
  94. params: routeParams,
  95. },
  96. });
  97. ProjectsStore.loadInitialData([project]);
  98. mockProjectApiResponses([project]);
  99. render(<ProjectInstallPlatform {...routerProps} />, {
  100. context: routerContext,
  101. });
  102. expect(
  103. await screen.findByRole('heading', {
  104. name: 'Configure JavaScript SDK',
  105. })
  106. ).toBeInTheDocument();
  107. });
  108. });