platform.spec.tsx 3.4 KB

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