platform.spec.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 {PlatformIntegration, PlatformKey, 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: (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 {organization, routerProps, project, router} = initializeOrg({
  51. router: {
  52. params: {
  53. projectId: ProjectFixture().slug,
  54. },
  55. },
  56. });
  57. mockProjectApiResponses([{...project, platform: 'lua'}]);
  58. render(
  59. <ProjectInstallPlatform
  60. {...routerProps}
  61. loading={false}
  62. platform={undefined}
  63. currentPlatformKey={'lua' as PlatformKey}
  64. project={project}
  65. />,
  66. {
  67. organization,
  68. router,
  69. }
  70. );
  71. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  72. });
  73. it('should display info for a non-supported platform', async function () {
  74. const {organization, routerProps, project} = initializeOrg({
  75. router: {
  76. params: {
  77. projectId: ProjectFixture().slug,
  78. },
  79. },
  80. });
  81. const platform: PlatformIntegration = {
  82. id: 'other',
  83. name: 'Other',
  84. link: 'https://docs.sentry.io/platforms/',
  85. type: 'language',
  86. language: 'other',
  87. };
  88. // this is needed because we don't handle a loading state in the UI
  89. ProjectsStore.loadInitialData([{...project, platform: platform.id}]);
  90. mockProjectApiResponses([{...project, platform: platform.id}]);
  91. render(
  92. <ProjectInstallPlatform
  93. {...routerProps}
  94. loading={false}
  95. platform={platform}
  96. project={project}
  97. currentPlatformKey={platform.id}
  98. />,
  99. {
  100. organization,
  101. }
  102. );
  103. expect(
  104. await screen.findByText(/We cannot provide instructions for 'Other' projects/)
  105. ).toBeInTheDocument();
  106. });
  107. it('should not render performance/session replay buttons for errors only self-hosted', async function () {
  108. const project = ProjectFixture({platform: 'javascript'});
  109. const {routerProps, router} = initializeOrg({
  110. router: {
  111. params: {
  112. projectId: project.slug,
  113. },
  114. },
  115. });
  116. ProjectsStore.loadInitialData([project]);
  117. mockProjectApiResponses([project]);
  118. ConfigStore.set('isSelfHostedErrorsOnly', true);
  119. const platform: PlatformIntegration = {
  120. id: 'javascript',
  121. name: 'Browser JavaScript',
  122. type: 'language',
  123. language: 'javascript',
  124. link: 'https://docs.sentry.io/platforms/javascript/',
  125. };
  126. render(
  127. <ProjectInstallPlatform
  128. {...routerProps}
  129. project={project}
  130. loading={false}
  131. platform={platform}
  132. currentPlatformKey={platform.id}
  133. />,
  134. {
  135. router,
  136. }
  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. });