index.spec.tsx 1.9 KB

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