integrationDetailedView.spec.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. MockApiClient.addMockResponse({
  192. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  193. body: {
  194. providers: [GitHubIntegrationProviderFixture()],
  195. },
  196. });
  197. MockApiClient.addMockResponse({
  198. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  199. body: [],
  200. });
  201. render(
  202. <IntegrationDetailedView
  203. {...RouteComponentPropsFixture()}
  204. params={{integrationSlug: 'github'}}
  205. organization={org}
  206. location={LocationFixture({query: {}})}
  207. />
  208. );
  209. await userEvent.click(screen.getByText('features'));
  210. expect(
  211. screen.getByRole('checkbox', {name: /Enable Comments on Suspect Pull Requests/})
  212. ).toBeDisabled();
  213. expect(
  214. screen.getByRole('checkbox', {name: /Enable Comments on Open Pull Requests/})
  215. ).toBeDisabled();
  216. });
  217. it('can enable github features', async function () {
  218. MockApiClient.addMockResponse({
  219. url: `/organizations/${org.slug}/config/integrations/?provider_key=github`,
  220. body: {
  221. providers: [GitHubIntegrationProviderFixture()],
  222. },
  223. });
  224. MockApiClient.addMockResponse({
  225. url: `/organizations/${org.slug}/integrations/?provider_key=github&includeConfig=0`,
  226. body: [GitHubIntegrationFixture()],
  227. });
  228. render(
  229. <IntegrationDetailedView
  230. {...RouteComponentPropsFixture()}
  231. params={{integrationSlug: 'github'}}
  232. organization={org}
  233. location={LocationFixture({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. });