integrationDetailedView.spec.jsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import IntegrationDetailedView from 'sentry/views/settings/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', 'org:write'],
  14. features: ['pr-comment-bot'],
  15. });
  16. beforeEach(() => {
  17. MockApiClient.clearMockResponses();
  18. mockResponse([
  19. [
  20. `/organizations/${org.slug}/config/integrations/?provider_key=bitbucket`,
  21. {
  22. providers: [
  23. {
  24. canAdd: true,
  25. canDisable: false,
  26. features: ['commits', 'issue-basic'],
  27. key: 'bitbucket',
  28. metadata: {
  29. aspects: {},
  30. author: 'The Sentry Team',
  31. description:
  32. 'Connect your Sentry organization to Bitbucket, enabling the following features:',
  33. features: [],
  34. issue_url:
  35. 'https://github.com/getsentry/sentry/issues/new?template=bug.yml&title=Bitbucket%20Integration:%20&labels=Component%3A%20Integrations',
  36. noun: 'Installation',
  37. source_url:
  38. 'https://github.com/getsentry/sentry/tree/master/src/sentry/integrations/bitbucket',
  39. },
  40. name: 'Bitbucket',
  41. setupDialog: {
  42. height: 600,
  43. url: '/organizations/sentry/integrations/bitbucket/setup/',
  44. width: 600,
  45. },
  46. slug: 'bitbucket',
  47. },
  48. ],
  49. },
  50. ],
  51. [
  52. `/organizations/${org.slug}/integrations/?provider_key=bitbucket&includeConfig=0`,
  53. [
  54. {
  55. accountType: null,
  56. configData: {},
  57. configOrganization: [],
  58. domainName: 'bitbucket.org/%7Bfb715533-bbd7-4666-aa57-01dc93dd9cc0%7D',
  59. 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',
  60. id: '4',
  61. name: '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}',
  62. provider: {
  63. aspects: {},
  64. canAdd: true,
  65. canDisable: false,
  66. features: ['commits', 'issue-basic'],
  67. key: 'bitbucket',
  68. name: 'Bitbucket',
  69. slug: 'bitbucket',
  70. },
  71. status: 'active',
  72. },
  73. ],
  74. ],
  75. ]);
  76. });
  77. it('shows integration name, status, and install button', function () {
  78. render(
  79. <IntegrationDetailedView
  80. params={{integrationSlug: 'bitbucket', orgId: org.slug}}
  81. location={{query: {}}}
  82. />
  83. );
  84. expect(screen.getByText('Bitbucket')).toBeInTheDocument();
  85. expect(screen.getByText('Installed')).toBeInTheDocument();
  86. expect(screen.getByRole('button', {name: 'Add integration'})).toBeEnabled();
  87. });
  88. it('view configurations', function () {
  89. render(
  90. <IntegrationDetailedView
  91. params={{integrationSlug: 'bitbucket', orgId: org.slug}}
  92. location={{query: {tab: 'configurations'}}}
  93. />
  94. );
  95. expect(screen.getByTestId('integration-name')).toHaveTextContent(
  96. '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}'
  97. );
  98. expect(screen.getByRole('button', {name: 'Configure'})).toBeEnabled();
  99. });
  100. it('disables configure for members without access', function () {
  101. render(
  102. <IntegrationDetailedView
  103. params={{integrationSlug: 'bitbucket', orgId: org.slug}}
  104. location={{query: {tab: 'configurations'}}}
  105. />,
  106. {organization: TestStubs.Organization({access: ['org:read']})}
  107. );
  108. expect(screen.getByRole('button', {name: 'Configure'})).toBeDisabled();
  109. });
  110. it('allows members to configure github/gitlab', function () {
  111. MockApiClient.addMockResponse({
  112. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  113. body: {
  114. providers: [TestStubs.GitHubIntegrationProvider()],
  115. },
  116. });
  117. MockApiClient.addMockResponse({
  118. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  119. body: [
  120. {
  121. accountType: null,
  122. configData: {},
  123. configOrganization: [],
  124. domainName: 'github.com/%7Bfb715533-bbd7-4666-aa57-01dc93dd9cc0%7D',
  125. 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',
  126. id: '4',
  127. name: '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}',
  128. provider: {
  129. aspects: {},
  130. canAdd: true,
  131. canDisable: false,
  132. features: ['commits', 'issue-basic'],
  133. key: 'github',
  134. name: 'GitHub',
  135. slug: 'github',
  136. },
  137. status: 'active',
  138. },
  139. ],
  140. });
  141. render(
  142. <IntegrationDetailedView
  143. params={{integrationSlug: 'github', orgId: org.slug}}
  144. location={{query: {tab: 'configurations'}}}
  145. />,
  146. {organization: TestStubs.Organization({access: ['org:read']})}
  147. );
  148. expect(screen.getByRole('button', {name: 'Configure'})).toBeEnabled();
  149. });
  150. it('shows features tab for github only', function () {
  151. MockApiClient.addMockResponse({
  152. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  153. body: {
  154. providers: [TestStubs.GitHubIntegrationProvider()],
  155. },
  156. });
  157. MockApiClient.addMockResponse({
  158. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  159. body: [
  160. {
  161. accountType: null,
  162. configData: {},
  163. configOrganization: [],
  164. domainName: 'github.com/%7Bfb715533-bbd7-4666-aa57-01dc93dd9cc0%7D',
  165. 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',
  166. id: '4',
  167. name: '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}',
  168. provider: {
  169. aspects: {},
  170. canAdd: true,
  171. canDisable: false,
  172. features: ['commits', 'issue-basic'],
  173. key: 'github',
  174. name: 'GitHub',
  175. slug: 'github',
  176. },
  177. status: 'active',
  178. },
  179. ],
  180. });
  181. render(
  182. <IntegrationDetailedView
  183. params={{integrationSlug: 'github'}}
  184. organization={org}
  185. location={{query: {}}}
  186. />
  187. );
  188. expect(screen.getByText('features')).toBeInTheDocument();
  189. });
  190. it('cannot enable PR bot without GitHub integration', async function () {
  191. MockApiClient.addMockResponse({
  192. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  193. body: {
  194. providers: [TestStubs.GitHubIntegrationProvider()],
  195. },
  196. });
  197. MockApiClient.addMockResponse({
  198. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  199. body: [],
  200. });
  201. render(
  202. <IntegrationDetailedView
  203. params={{integrationSlug: 'github'}}
  204. organization={org}
  205. location={{query: {}}}
  206. />
  207. );
  208. await userEvent.click(screen.getByText('features'));
  209. expect(
  210. screen.getByRole('checkbox', {name: /Enable Pull Request Bot/})
  211. ).toBeDisabled();
  212. });
  213. });