index.spec.jsx 7.8 KB

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