integrationDetailedView.spec.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. import {GitHubIntegrationProvider} from 'sentry-fixture/githubIntegrationProvider';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import IntegrationDetailedView from 'sentry/views/settings/organizationIntegrations/integrationDetailedView';
  5. describe('IntegrationDetailedView', function () {
  6. const ENDPOINT = '/organizations/org-slug/';
  7. const org = Organization({
  8. access: ['org:integrations', 'org:write'],
  9. });
  10. beforeEach(() => {
  11. MockApiClient.clearMockResponses();
  12. MockApiClient.addMockResponse({
  13. url: `/organizations/${org.slug}/config/integrations/?provider_key=bitbucket`,
  14. body: {
  15. providers: [
  16. {
  17. canAdd: true,
  18. canDisable: false,
  19. features: ['commits', 'issue-basic'],
  20. key: 'bitbucket',
  21. metadata: {
  22. aspects: {},
  23. author: 'The Sentry Team',
  24. description:
  25. 'Connect your Sentry organization to Bitbucket, enabling the following features:',
  26. features: [],
  27. issue_url:
  28. 'https://github.com/getsentry/sentry/issues/new?template=bug.yml&title=Bitbucket%20Integration:%20&labels=Component%3A%20Integrations',
  29. noun: 'Installation',
  30. source_url:
  31. 'https://github.com/getsentry/sentry/tree/master/src/sentry/integrations/bitbucket',
  32. },
  33. name: 'Bitbucket',
  34. setupDialog: {
  35. height: 600,
  36. url: '/organizations/sentry/integrations/bitbucket/setup/',
  37. width: 600,
  38. },
  39. slug: 'bitbucket',
  40. },
  41. ],
  42. },
  43. });
  44. MockApiClient.addMockResponse({
  45. url: `/organizations/${org.slug}/integrations/?provider_key=bitbucket&includeConfig=0`,
  46. body: [
  47. {
  48. accountType: null,
  49. configData: {},
  50. configOrganization: [],
  51. domainName: 'bitbucket.org/%7Bfb715533-bbd7-4666-aa57-01dc93dd9cc0%7D',
  52. 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',
  53. id: '4',
  54. name: '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}',
  55. provider: {
  56. aspects: {},
  57. canAdd: true,
  58. canDisable: false,
  59. features: ['commits', 'issue-basic'],
  60. key: 'bitbucket',
  61. name: 'Bitbucket',
  62. slug: 'bitbucket',
  63. },
  64. status: 'active',
  65. },
  66. ],
  67. });
  68. });
  69. it('shows integration name, status, and install button', function () {
  70. render(
  71. <IntegrationDetailedView
  72. {...TestStubs.routeComponentProps()}
  73. params={{integrationSlug: 'bitbucket'}}
  74. location={TestStubs.location({query: {}})}
  75. />
  76. );
  77. expect(screen.getByText('Bitbucket')).toBeInTheDocument();
  78. expect(screen.getByText('Installed')).toBeInTheDocument();
  79. expect(screen.getByRole('button', {name: 'Add integration'})).toBeEnabled();
  80. });
  81. it('view configurations', function () {
  82. render(
  83. <IntegrationDetailedView
  84. {...TestStubs.routeComponentProps()}
  85. params={{integrationSlug: 'bitbucket'}}
  86. location={TestStubs.location({query: {tab: 'configurations'}})}
  87. />
  88. );
  89. expect(screen.getByTestId('integration-name')).toHaveTextContent(
  90. '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}'
  91. );
  92. expect(screen.getByRole('button', {name: 'Configure'})).toBeEnabled();
  93. });
  94. it('disables configure for members without access', function () {
  95. render(
  96. <IntegrationDetailedView
  97. {...TestStubs.routeComponentProps()}
  98. params={{integrationSlug: 'bitbucket'}}
  99. location={TestStubs.location({query: {tab: 'configurations'}})}
  100. />,
  101. {organization: Organization({access: ['org:read']})}
  102. );
  103. expect(screen.getByRole('button', {name: 'Configure'})).toBeDisabled();
  104. });
  105. it('allows members to configure github/gitlab', function () {
  106. MockApiClient.addMockResponse({
  107. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  108. body: {
  109. providers: [GitHubIntegrationProvider()],
  110. },
  111. });
  112. MockApiClient.addMockResponse({
  113. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  114. body: [
  115. {
  116. accountType: null,
  117. configData: {},
  118. configOrganization: [],
  119. domainName: 'github.com/%7Bfb715533-bbd7-4666-aa57-01dc93dd9cc0%7D',
  120. 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',
  121. id: '4',
  122. name: '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}',
  123. provider: {
  124. aspects: {},
  125. canAdd: true,
  126. canDisable: false,
  127. features: ['commits', 'issue-basic'],
  128. key: 'github',
  129. name: 'GitHub',
  130. slug: 'github',
  131. },
  132. status: 'active',
  133. },
  134. ],
  135. });
  136. render(
  137. <IntegrationDetailedView
  138. {...TestStubs.routeComponentProps()}
  139. params={{integrationSlug: 'github'}}
  140. location={TestStubs.location({query: {tab: 'configurations'}})}
  141. />,
  142. {organization: Organization({access: ['org:read']})}
  143. );
  144. expect(screen.getByRole('button', {name: 'Configure'})).toBeEnabled();
  145. });
  146. it('shows features tab for github only', function () {
  147. MockApiClient.addMockResponse({
  148. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  149. body: {
  150. providers: [GitHubIntegrationProvider()],
  151. },
  152. });
  153. MockApiClient.addMockResponse({
  154. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  155. body: [
  156. {
  157. accountType: null,
  158. configData: {},
  159. configOrganization: [],
  160. domainName: 'github.com/%7Bfb715533-bbd7-4666-aa57-01dc93dd9cc0%7D',
  161. 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',
  162. id: '4',
  163. name: '{fb715533-bbd7-4666-aa57-01dc93dd9cc0}',
  164. provider: {
  165. aspects: {},
  166. canAdd: true,
  167. canDisable: false,
  168. features: ['commits', 'issue-basic'],
  169. key: 'github',
  170. name: 'GitHub',
  171. slug: 'github',
  172. },
  173. status: 'active',
  174. },
  175. ],
  176. });
  177. render(
  178. <IntegrationDetailedView
  179. {...TestStubs.routeComponentProps()}
  180. params={{integrationSlug: 'github'}}
  181. organization={org}
  182. location={TestStubs.location({query: {}})}
  183. />
  184. );
  185. expect(screen.getByText('features')).toBeInTheDocument();
  186. });
  187. it('cannot enable PR bot without GitHub integration', async function () {
  188. org.features.push('integrations-open-pr-comment');
  189. MockApiClient.addMockResponse({
  190. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  191. body: {
  192. providers: [GitHubIntegrationProvider()],
  193. },
  194. });
  195. MockApiClient.addMockResponse({
  196. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  197. body: [],
  198. });
  199. render(
  200. <IntegrationDetailedView
  201. {...TestStubs.routeComponentProps()}
  202. params={{integrationSlug: 'github'}}
  203. organization={org}
  204. location={TestStubs.location({query: {}})}
  205. />
  206. );
  207. await userEvent.click(screen.getByText('features'));
  208. expect(
  209. screen.getByRole('checkbox', {name: /Enable Comments on Suspect Pull Requests/})
  210. ).toBeDisabled();
  211. expect(
  212. screen.getByRole('checkbox', {name: /Enable Comments on Open Pull Requests/})
  213. ).toBeDisabled();
  214. });
  215. it('can enable github features', async function () {
  216. org.features.push('integrations-open-pr-comment');
  217. org.features.push('integrations-gh-invite');
  218. MockApiClient.addMockResponse({
  219. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  220. body: {
  221. providers: [GitHubIntegrationProvider()],
  222. },
  223. });
  224. MockApiClient.addMockResponse({
  225. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  226. body: [TestStubs.GitHubIntegration()],
  227. });
  228. render(
  229. <IntegrationDetailedView
  230. {...TestStubs.routeComponentProps()}
  231. params={{integrationSlug: 'github'}}
  232. organization={org}
  233. location={TestStubs.location({query: {}})}
  234. />
  235. );
  236. await userEvent.click(screen.getByText('features'));
  237. const mock = MockApiClient.addMockResponse({
  238. url: ENDPOINT,
  239. method: 'PUT',
  240. });
  241. await userEvent.click(
  242. screen.getByRole('checkbox', {name: /Enable Comments on Suspect Pull Requests/})
  243. );
  244. await waitFor(() => {
  245. expect(mock).toHaveBeenCalledWith(
  246. ENDPOINT,
  247. expect.objectContaining({
  248. data: {githubPRBot: true},
  249. })
  250. );
  251. });
  252. await userEvent.click(
  253. screen.getByRole('checkbox', {name: /Enable Comments on Open Pull Requests/})
  254. );
  255. await waitFor(() => {
  256. expect(mock).toHaveBeenCalledWith(
  257. ENDPOINT,
  258. expect.objectContaining({
  259. data: {githubOpenPRBot: true},
  260. })
  261. );
  262. });
  263. await userEvent.click(
  264. screen.getByRole('checkbox', {name: /Enable Missing Member Detection/})
  265. );
  266. await waitFor(() => {
  267. expect(mock).toHaveBeenCalledWith(
  268. ENDPOINT,
  269. expect.objectContaining({
  270. data: {githubNudgeInvite: true},
  271. })
  272. );
  273. });
  274. });
  275. });