integrationDetailedView.spec.tsx 9.9 KB

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