index.spec.tsx 1.8 KB

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