platform.spec.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import {ProjectFixture} from 'sentry-fixture/project';
  2. import {ProjectKeysFixture} from 'sentry-fixture/projectKeys';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen} from 'sentry-test/reactTestingLibrary';
  5. import ConfigStore from 'sentry/stores/configStore';
  6. import ProjectsStore from 'sentry/stores/projectsStore';
  7. import type {Project} from 'sentry/types/project';
  8. import {ProjectInstallPlatform} from 'sentry/views/projectInstall/platform';
  9. type ProjectWithBadPlatform = Omit<Project, 'platform'> & {
  10. platform: string;
  11. };
  12. function mockProjectApiResponses(projects: Array<Project | ProjectWithBadPlatform>) {
  13. MockApiClient.addMockResponse({
  14. method: 'GET',
  15. url: '/organizations/org-slug/projects/',
  16. body: projects,
  17. });
  18. MockApiClient.addMockResponse({
  19. method: 'GET',
  20. url: '/projects/org-slug/project-slug/docs/other/',
  21. body: {},
  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: projects,
  32. });
  33. MockApiClient.addMockResponse({
  34. url: '/projects/org-slug/project-slug/keys/',
  35. method: 'GET',
  36. body: [ProjectKeysFixture()[0]],
  37. });
  38. MockApiClient.addMockResponse({
  39. url: `/projects/org-slug/project-slug/keys/${ProjectKeysFixture()[0].public}/`,
  40. method: 'PUT',
  41. body: {},
  42. });
  43. }
  44. describe('ProjectInstallPlatform', function () {
  45. beforeEach(function () {
  46. MockApiClient.clearMockResponses();
  47. ConfigStore.init();
  48. });
  49. it('should render NotFound if no matching integration/platform', async function () {
  50. const routeParams = {
  51. projectId: ProjectFixture().slug,
  52. };
  53. const {organization, routerProps, project, router} = initializeOrg({
  54. router: {
  55. location: {
  56. query: {},
  57. },
  58. params: routeParams,
  59. },
  60. });
  61. mockProjectApiResponses([{...project, platform: 'lua'}]);
  62. render(<ProjectInstallPlatform {...routerProps} />, {
  63. organization,
  64. router,
  65. });
  66. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  67. });
  68. it('should display info for a non-supported platform', async function () {
  69. const routeParams = {
  70. projectId: ProjectFixture().slug,
  71. };
  72. const {organization, routerProps, project} = initializeOrg({
  73. router: {
  74. location: {
  75. query: {},
  76. },
  77. params: routeParams,
  78. },
  79. });
  80. // this is needed because we don't handle a loading state in the UI
  81. ProjectsStore.loadInitialData([{...project, platform: 'other'}]);
  82. mockProjectApiResponses([{...project, platform: 'other'}]);
  83. render(<ProjectInstallPlatform {...routerProps} />, {
  84. organization,
  85. });
  86. expect(
  87. await screen.findByText(/We cannot provide instructions for 'Other' projects/)
  88. ).toBeInTheDocument();
  89. });
  90. it('should render getting started docs for correct platform', async function () {
  91. const project = ProjectFixture({platform: 'javascript'});
  92. const routeParams = {
  93. projectId: project.slug,
  94. platform: 'python',
  95. };
  96. const {routerProps, router} = initializeOrg({
  97. router: {
  98. location: {
  99. query: {},
  100. },
  101. params: routeParams,
  102. },
  103. });
  104. ProjectsStore.loadInitialData([project]);
  105. mockProjectApiResponses([project]);
  106. render(<ProjectInstallPlatform {...routerProps} />, {
  107. router,
  108. });
  109. expect(
  110. await screen.findByRole('heading', {
  111. name: 'Configure Browser JavaScript SDK',
  112. })
  113. ).toBeInTheDocument();
  114. expect(await screen.getByText('Take me to Issues')).toBeInTheDocument();
  115. expect(await screen.getByText('Take me to Performance')).toBeInTheDocument();
  116. expect(await screen.getByText('Take me to Session Replay')).toBeInTheDocument();
  117. });
  118. it('should not render performance/session replay buttons for errors only self-hosted', async function () {
  119. const project = ProjectFixture({platform: 'javascript'});
  120. const routeParams = {
  121. projectId: project.slug,
  122. platform: 'python',
  123. };
  124. const {routerProps, router} = initializeOrg({
  125. router: {
  126. location: {
  127. query: {},
  128. },
  129. params: routeParams,
  130. },
  131. });
  132. ProjectsStore.loadInitialData([project]);
  133. mockProjectApiResponses([project]);
  134. ConfigStore.set('isSelfHostedErrorsOnly', true);
  135. render(<ProjectInstallPlatform {...routerProps} />, {
  136. router,
  137. });
  138. expect(
  139. await screen.findByRole('heading', {
  140. name: 'Configure Browser JavaScript SDK',
  141. })
  142. ).toBeInTheDocument();
  143. expect(screen.getByText('Take me to Issues')).toBeInTheDocument();
  144. expect(() => screen.getByText('Take me to Performance')).toThrow();
  145. expect(() => screen.getByText('Take me to Session Replay')).toThrow();
  146. });
  147. });