organizationApiKeysView.spec.jsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {mountGlobalModal} from 'sentry-test/modal';
  3. import OrganizationApiKeys from 'sentry/views/settings/organizationApiKeys';
  4. const routes = [
  5. {path: '/'},
  6. {path: '/:orgId/'},
  7. {path: '/organizations/:orgId/'},
  8. {path: 'api-keys/', name: 'API Key'},
  9. ];
  10. describe('OrganizationApiKeys', function () {
  11. let getMock, deleteMock;
  12. beforeEach(function () {
  13. MockApiClient.clearMockResponses();
  14. getMock = MockApiClient.addMockResponse({
  15. url: '/organizations/org-slug/api-keys/',
  16. method: 'GET',
  17. body: [TestStubs.ApiKey()],
  18. });
  19. MockApiClient.addMockResponse({
  20. url: '/organizations/org-slug/api-keys/1/',
  21. method: 'GET',
  22. body: TestStubs.ApiKey(),
  23. });
  24. deleteMock = MockApiClient.addMockResponse({
  25. url: '/organizations/org-slug/api-keys/1/',
  26. method: 'DELETE',
  27. });
  28. });
  29. it('fetches api keys', function () {
  30. const wrapper = mountWithTheme(
  31. <OrganizationApiKeys
  32. location={TestStubs.location()}
  33. params={{orgId: 'org-slug'}}
  34. routes={routes}
  35. />
  36. );
  37. expect(wrapper.find('AutoSelectTextInput')).toHaveLength(1);
  38. expect(getMock).toHaveBeenCalledTimes(1);
  39. });
  40. it('can delete a key', async function () {
  41. const wrapper = mountWithTheme(
  42. <OrganizationApiKeys
  43. location={TestStubs.location()}
  44. params={{orgId: 'org-slug'}}
  45. routes={routes}
  46. />
  47. );
  48. expect(deleteMock).toHaveBeenCalledTimes(0);
  49. wrapper.find('Confirm[aria-label="Remove API Key"]').simulate('click');
  50. const modal = await mountGlobalModal();
  51. modal.find('button[aria-label="Confirm"]').simulate('click');
  52. wrapper.update();
  53. expect(deleteMock).toHaveBeenCalledTimes(1);
  54. expect(wrapper.find('AutoSelectTextInput')).toHaveLength(0);
  55. });
  56. });