index.spec.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. waitFor,
  8. within,
  9. } from 'sentry-test/reactTestingLibrary';
  10. import OrganizationDeveloperSettings from 'sentry/views/settings/organizationDeveloperSettings/index';
  11. describe('Organization Developer Settings', function () {
  12. const {organization: org, routerProps, router} = initializeOrg();
  13. const sentryApp = TestStubs.SentryApp({
  14. scopes: [
  15. 'team:read',
  16. 'project:releases',
  17. 'event:read',
  18. 'event:write',
  19. 'org:read',
  20. 'org:write',
  21. ],
  22. });
  23. beforeEach(() => {
  24. MockApiClient.clearMockResponses();
  25. });
  26. describe('when no Apps exist', () => {
  27. it('displays empty state', async () => {
  28. MockApiClient.addMockResponse({
  29. url: `/organizations/${org.slug}/sentry-apps/`,
  30. body: [],
  31. });
  32. render(<OrganizationDeveloperSettings {...routerProps} organization={org} />);
  33. await waitFor(() => {
  34. expect(
  35. screen.getByText('No internal integrations have been created yet.')
  36. ).toBeInTheDocument();
  37. });
  38. });
  39. });
  40. describe('with unpublished apps', () => {
  41. beforeEach(() => {
  42. MockApiClient.addMockResponse({
  43. url: `/organizations/${org.slug}/sentry-apps/`,
  44. body: [sentryApp],
  45. });
  46. });
  47. it('internal integrations list is empty', () => {
  48. render(<OrganizationDeveloperSettings {...routerProps} organization={org} />, {
  49. organization: org,
  50. });
  51. expect(
  52. screen.getByText('No internal integrations have been created yet.')
  53. ).toBeInTheDocument();
  54. });
  55. it('public integrations list contains 1 item', () => {
  56. render(
  57. <OrganizationDeveloperSettings
  58. {...routerProps}
  59. organization={org}
  60. location={{...router.location, query: {type: 'public'}}}
  61. />,
  62. {organization: org}
  63. );
  64. expect(screen.getByText('Sample App')).toBeInTheDocument();
  65. expect(screen.getByText('unpublished')).toBeInTheDocument();
  66. });
  67. it('allows for deletion', async () => {
  68. MockApiClient.addMockResponse({
  69. url: `/sentry-apps/${sentryApp.slug}/`,
  70. method: 'DELETE',
  71. body: [],
  72. });
  73. render(
  74. <OrganizationDeveloperSettings
  75. {...routerProps}
  76. organization={org}
  77. location={{...router.location, query: {type: 'public'}}}
  78. />
  79. );
  80. const deleteButton = await screen.findByRole('button', {name: 'Delete'});
  81. expect(deleteButton).toHaveAttribute('aria-disabled', 'false');
  82. await userEvent.click(deleteButton);
  83. renderGlobalModal();
  84. const dialog = await screen.findByRole('dialog');
  85. expect(dialog).toBeInTheDocument();
  86. const input = await within(dialog).findByPlaceholderText('sample-app');
  87. await userEvent.type(input, 'sample-app');
  88. const confirmDeleteButton = await screen.findByRole('button', {name: 'Confirm'});
  89. await userEvent.click(confirmDeleteButton);
  90. await screen.findByText('No public integrations have been created yet.');
  91. });
  92. it('can make a request to publish an integration', async () => {
  93. const mock = MockApiClient.addMockResponse({
  94. url: `/sentry-apps/${sentryApp.slug}/publish-request/`,
  95. method: 'POST',
  96. });
  97. render(
  98. <OrganizationDeveloperSettings
  99. {...routerProps}
  100. organization={org}
  101. location={{...router.location, query: {type: 'public'}}}
  102. />
  103. );
  104. const publishButton = await screen.findByRole('button', {name: 'Publish'});
  105. expect(publishButton).toHaveAttribute('aria-disabled', 'false');
  106. await userEvent.click(publishButton);
  107. renderGlobalModal();
  108. const dialog = await screen.findByRole('dialog');
  109. expect(dialog).toBeInTheDocument();
  110. const questionnaire = [
  111. {
  112. answer: 'Answer 0',
  113. question: 'What does your integration do? Please be as detailed as possible.',
  114. },
  115. {answer: 'Answer 1', question: 'What value does it offer customers?'},
  116. {
  117. answer: 'Answer 2',
  118. question: 'Do you operate the web service your integration communicates with?',
  119. },
  120. {
  121. answer: 'Answer 3',
  122. question:
  123. 'Please justify why you are requesting each of the following permissions: Team Read, Release Admin, Event Write, Organization Write.',
  124. },
  125. ];
  126. for (const {question, answer} of questionnaire) {
  127. const element = within(dialog).getByRole('textbox', {name: question});
  128. await userEvent.type(element, answer);
  129. }
  130. const requestPublishButton = await within(dialog).findByLabelText(
  131. 'Request Publication'
  132. );
  133. expect(requestPublishButton).toHaveAttribute('aria-disabled', 'false');
  134. await userEvent.click(requestPublishButton);
  135. expect(mock).toHaveBeenCalledWith(
  136. `/sentry-apps/${sentryApp.slug}/publish-request/`,
  137. expect.objectContaining({
  138. data: {questionnaire},
  139. })
  140. );
  141. });
  142. });
  143. describe('with published apps', () => {
  144. beforeEach(() => {
  145. const publishedSentryApp = TestStubs.SentryApp({status: 'published'});
  146. MockApiClient.addMockResponse({
  147. url: `/organizations/${org.slug}/sentry-apps/`,
  148. body: [publishedSentryApp],
  149. });
  150. });
  151. it('shows the published status', () => {
  152. render(
  153. <OrganizationDeveloperSettings
  154. {...routerProps}
  155. organization={org}
  156. location={{...router.location, query: {type: 'public'}}}
  157. />
  158. );
  159. expect(screen.getByText('published')).toBeInTheDocument();
  160. });
  161. it('trash button is disabled', async () => {
  162. render(
  163. <OrganizationDeveloperSettings
  164. {...routerProps}
  165. organization={org}
  166. location={{...router.location, query: {type: 'public'}}}
  167. />
  168. );
  169. const deleteButton = await screen.findByRole('button', {name: 'Delete'});
  170. expect(deleteButton).toHaveAttribute('aria-disabled', 'true');
  171. });
  172. it('publish button is disabled', async () => {
  173. render(
  174. <OrganizationDeveloperSettings
  175. {...routerProps}
  176. organization={org}
  177. location={{...router.location, query: {type: 'public'}}}
  178. />
  179. );
  180. const publishButton = await screen.findByRole('button', {name: 'Publish'});
  181. expect(publishButton).toHaveAttribute('aria-disabled', 'true');
  182. });
  183. });
  184. describe('with Internal Integrations', () => {
  185. beforeEach(() => {
  186. const internalIntegration = TestStubs.SentryApp({status: 'internal'});
  187. MockApiClient.addMockResponse({
  188. url: `/organizations/${org.slug}/sentry-apps/`,
  189. body: [internalIntegration],
  190. });
  191. });
  192. it('allows deleting', async () => {
  193. render(<OrganizationDeveloperSettings {...routerProps} organization={org} />);
  194. const deleteButton = await screen.findByRole('button', {name: 'Delete'});
  195. expect(deleteButton).toHaveAttribute('aria-disabled', 'false');
  196. });
  197. it('publish button does not exist', () => {
  198. render(<OrganizationDeveloperSettings {...routerProps} organization={org} />);
  199. expect(screen.queryByText('Publish')).not.toBeInTheDocument();
  200. });
  201. });
  202. describe('without Owner permissions', () => {
  203. const newOrg = TestStubs.Organization({access: ['org:read']});
  204. beforeEach(() => {
  205. MockApiClient.addMockResponse({
  206. url: `/organizations/${newOrg.slug}/sentry-apps/`,
  207. body: [sentryApp],
  208. });
  209. });
  210. it('trash button is disabled', async () => {
  211. render(
  212. <OrganizationDeveloperSettings
  213. {...routerProps}
  214. organization={newOrg}
  215. location={{...router.location, query: {type: 'public'}}}
  216. />,
  217. {organization: newOrg}
  218. );
  219. const deleteButton = await screen.findByRole('button', {name: 'Delete'});
  220. expect(deleteButton).toHaveAttribute('aria-disabled', 'true');
  221. });
  222. it('publish button is disabled', async () => {
  223. render(
  224. <OrganizationDeveloperSettings
  225. {...routerProps}
  226. organization={newOrg}
  227. location={{...router.location, query: {type: 'public'}}}
  228. />,
  229. {organization: newOrg}
  230. );
  231. const publishButton = await screen.findByRole('button', {name: 'Publish'});
  232. expect(publishButton).toHaveAttribute('aria-disabled', 'true');
  233. });
  234. });
  235. });