index.spec.jsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. } from 'sentry-test/reactTestingLibrary';
  7. import OrganizationApiKeys from 'sentry/views/settings/organizationApiKeys';
  8. const routes = [
  9. {path: '/'},
  10. {path: '/:orgId/'},
  11. {path: '/organizations/:orgId/'},
  12. {path: 'api-keys/', name: 'API Key'},
  13. ];
  14. describe('OrganizationApiKeys', function () {
  15. let getMock, deleteMock;
  16. beforeEach(function () {
  17. MockApiClient.clearMockResponses();
  18. getMock = MockApiClient.addMockResponse({
  19. url: '/organizations/org-slug/api-keys/',
  20. method: 'GET',
  21. body: [TestStubs.ApiKey()],
  22. });
  23. MockApiClient.addMockResponse({
  24. url: '/organizations/org-slug/api-keys/1/',
  25. method: 'GET',
  26. body: TestStubs.ApiKey(),
  27. });
  28. deleteMock = MockApiClient.addMockResponse({
  29. url: '/organizations/org-slug/api-keys/1/',
  30. method: 'DELETE',
  31. });
  32. });
  33. it('fetches api keys', function () {
  34. render(
  35. <OrganizationApiKeys
  36. location={TestStubs.location()}
  37. params={{orgId: 'org-slug'}}
  38. routes={routes}
  39. />
  40. );
  41. expect(screen.getByRole('textbox')).toBeInTheDocument();
  42. expect(getMock).toHaveBeenCalledTimes(1);
  43. });
  44. it('can delete a key', function () {
  45. render(
  46. <OrganizationApiKeys
  47. location={TestStubs.location()}
  48. params={{orgId: 'org-slug'}}
  49. routes={routes}
  50. />
  51. );
  52. expect(deleteMock).toHaveBeenCalledTimes(0);
  53. userEvent.click(screen.getByRole('link', {name: 'Remove API Key?'}));
  54. renderGlobalModal();
  55. userEvent.click(screen.getByTestId('confirm-button'));
  56. expect(deleteMock).toHaveBeenCalledTimes(1);
  57. expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
  58. });
  59. });