platform.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import {Project as ProjectFixture} from 'sentry-fixture/project';
  2. import {ProjectKeys} from 'sentry-fixture/projectKeys';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen} from 'sentry-test/reactTestingLibrary';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import {Project} from 'sentry/types';
  7. import {ProjectInstallPlatform} from 'sentry/views/projectInstall/platform';
  8. type ProjectWithBadPlatform = Omit<Project, 'platform'> & {
  9. platform: string;
  10. };
  11. function mockProjectApiResponses(projects: Array<Project | ProjectWithBadPlatform>) {
  12. MockApiClient.addMockResponse({
  13. method: 'GET',
  14. url: '/organizations/org-slug/projects/',
  15. body: projects,
  16. });
  17. MockApiClient.addMockResponse({
  18. method: 'GET',
  19. url: '/projects/org-slug/project-slug/docs/other/',
  20. body: {},
  21. });
  22. MockApiClient.addMockResponse({
  23. method: 'GET',
  24. url: '/projects/org-slug/project-slug/rules/',
  25. body: [],
  26. });
  27. MockApiClient.addMockResponse({
  28. method: 'GET',
  29. url: '/projects/org-slug/project-slug/',
  30. body: projects,
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/projects/org-slug/project-slug/keys/',
  34. method: 'GET',
  35. body: [ProjectKeys()[0]],
  36. });
  37. MockApiClient.addMockResponse({
  38. url: `/projects/org-slug/project-slug/keys/${ProjectKeys()[0].public}/`,
  39. method: 'PUT',
  40. body: {},
  41. });
  42. }
  43. describe('ProjectInstallPlatform', function () {
  44. beforeEach(function () {
  45. MockApiClient.clearMockResponses();
  46. });
  47. it('should render NotFound if no matching integration/platform', async function () {
  48. const routeParams = {
  49. projectId: ProjectFixture().slug,
  50. };
  51. const {organization, routerProps, project, routerContext} = initializeOrg({
  52. router: {
  53. location: {
  54. query: {},
  55. },
  56. params: routeParams,
  57. },
  58. });
  59. mockProjectApiResponses([{...project, platform: 'lua'}]);
  60. render(<ProjectInstallPlatform {...routerProps} />, {
  61. organization,
  62. context: routerContext,
  63. });
  64. expect(await screen.findByText('Page Not Found')).toBeInTheDocument();
  65. });
  66. it('should display info for a non-supported platform', async function () {
  67. const routeParams = {
  68. projectId: ProjectFixture().slug,
  69. };
  70. const {organization, routerProps, project} = initializeOrg({
  71. router: {
  72. location: {
  73. query: {},
  74. },
  75. params: routeParams,
  76. },
  77. });
  78. // this is needed because we don't handle a loading state in the UI
  79. ProjectsStore.loadInitialData([{...project, platform: 'other'}]);
  80. mockProjectApiResponses([{...project, platform: 'other'}]);
  81. render(<ProjectInstallPlatform {...routerProps} />, {
  82. organization,
  83. });
  84. expect(
  85. await screen.findByText(/We cannot provide instructions for 'Other' projects/)
  86. ).toBeInTheDocument();
  87. });
  88. it('should render getting started docs for correct platform', async function () {
  89. const project = ProjectFixture({platform: 'javascript'});
  90. const routeParams = {
  91. projectId: project.slug,
  92. platform: 'python',
  93. };
  94. const {routerProps, routerContext} = initializeOrg({
  95. router: {
  96. location: {
  97. query: {},
  98. },
  99. params: routeParams,
  100. },
  101. });
  102. ProjectsStore.loadInitialData([project]);
  103. mockProjectApiResponses([project]);
  104. render(<ProjectInstallPlatform {...routerProps} />, {
  105. context: routerContext,
  106. });
  107. expect(
  108. await screen.findByRole('heading', {
  109. name: 'Configure Browser JavaScript SDK',
  110. })
  111. ).toBeInTheDocument();
  112. });
  113. });