integrationDetailedView.spec.jsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import IntegrationDetailedView from 'sentry/views/organizationIntegrations/integrationDetailedView';
  3. const mockResponse = mocks => {
  4. mocks.forEach(([url, body]) =>
  5. MockApiClient.addMockResponse({
  6. url,
  7. body,
  8. })
  9. );
  10. };
  11. describe('IntegrationDetailedView', function () {
  12. const org = TestStubs.Organization({
  13. access: ['org:integrations'],
  14. });
  15. beforeEach(() => {
  16. MockApiClient.clearMockResponses();
  17. mockResponse([
  18. [
  19. `/organizations/${org.slug}/config/integrations/?provider_key=bitbucket`,
  20. {
  21. providers: [
  22. {
  23. canAdd: true,
  24. canDisable: false,
  25. features: ['commits', 'issue-basic'],
  26. key: 'bitbucket',
  27. metadata: {
  28. aspects: {},
  29. author: 'The Sentry Team',
  30. description:
  31. 'Connect your Sentry organization to Bitbucket, enabling the following features:',
  32. features: [],
  33. issue_url:
  34. 'https://github.com/getsentry/sentry/issues/new?template=bug.yml&title=Bitbucket%20Integration:%20&labels=Component%3A%20Integrations',
  35. noun: 'Installation',
  36. source_url:
  37. 'https://github.com/getsentry/sentry/tree/master/src/sentry/integrations/bitbucket',
  38. },
  39. name: 'Bitbucket',
  40. setupDialog: {
  41. height: 600,
  42. url: '/organizations/sentry/integrations/bitbucket/setup/',
  43. width: 600,
  44. },
  45. slug: 'bitbucket',
  46. },
  47. ],
  48. },
  49. ],
  50. [
  51. `/organizations/${org.slug}/integrations/?provider_key=bitbucket&includeConfig=0`,
  52. [
  53. {
  54. accountType: null,
  55. configData: {},
  56. configOrganization: [],
  57. domainName: 'bitbucket.org/%7Bfb715533-bbd7-4666-aa57-01dc93dd9cc0%7D',
  58. icon: 'https://secure.gravatar.com/avatar/8b4cb68e40b74c90427d8262256bd1c8?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FNN-0.png',
  59. id: '4',
  60. name: '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}',
  61. provider: {
  62. aspects: {},
  63. canAdd: true,
  64. canDisable: false,
  65. features: ['commits', 'issue-basic'],
  66. key: 'bitbucket',
  67. name: 'Bitbucket',
  68. slug: 'bitbucket',
  69. },
  70. status: 'active',
  71. },
  72. ],
  73. ],
  74. ]);
  75. });
  76. it('shows integration name, status, and install button', function () {
  77. render(
  78. <IntegrationDetailedView
  79. params={{integrationSlug: 'bitbucket', orgId: org.slug}}
  80. location={{query: {}}}
  81. />
  82. );
  83. expect(screen.getByText('Bitbucket')).toBeInTheDocument();
  84. expect(screen.getByText('Installed')).toBeInTheDocument();
  85. expect(screen.getByRole('button', {name: 'Add integration'})).toBeEnabled();
  86. });
  87. it('view configurations', function () {
  88. render(
  89. <IntegrationDetailedView
  90. params={{integrationSlug: 'bitbucket', orgId: org.slug}}
  91. location={{query: {tab: 'configurations'}}}
  92. />
  93. );
  94. expect(screen.getByTestId('integration-name')).toHaveTextContent(
  95. '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}'
  96. );
  97. expect(screen.getByRole('button', {name: 'Configure'})).toBeEnabled();
  98. });
  99. it('disables configure for members without access', function () {
  100. render(
  101. <IntegrationDetailedView
  102. params={{integrationSlug: 'bitbucket', orgId: org.slug}}
  103. location={{query: {tab: 'configurations'}}}
  104. organization={TestStubs.Organization({access: ['org:read']})}
  105. />
  106. );
  107. expect(screen.getByRole('button', {name: 'Configure'})).toBeDisabled();
  108. });
  109. it('allows members to configure github/gitlab', function () {
  110. MockApiClient.addMockResponse({
  111. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  112. body: {
  113. providers: [TestStubs.GitHubIntegrationProvider()],
  114. },
  115. });
  116. MockApiClient.addMockResponse({
  117. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  118. body: [
  119. {
  120. accountType: null,
  121. configData: {},
  122. configOrganization: [],
  123. domainName: 'github.com/%7Bfb715533-bbd7-4666-aa57-01dc93dd9cc0%7D',
  124. icon: 'https://secure.gravatar.com/avatar/8b4cb68e40b74c90427d8262256bd1c8?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FNN-0.png',
  125. id: '4',
  126. name: '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}',
  127. provider: {
  128. aspects: {},
  129. canAdd: true,
  130. canDisable: false,
  131. features: ['commits', 'issue-basic'],
  132. key: 'github',
  133. name: 'GitHub',
  134. slug: 'github',
  135. },
  136. status: 'active',
  137. },
  138. ],
  139. });
  140. render(
  141. <IntegrationDetailedView
  142. params={{integrationSlug: 'github', orgId: org.slug}}
  143. location={{query: {tab: 'configurations'}}}
  144. organization={TestStubs.Organization({access: ['org:read']})}
  145. />
  146. );
  147. expect(screen.getByRole('button', {name: 'Configure'})).toBeEnabled();
  148. });
  149. });