platform.spec.tsx 3.4 KB

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