apiTokens.spec.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {ApiTokenFixture} from 'sentry-fixture/apiToken';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {
  4. render,
  5. renderGlobalModal,
  6. screen,
  7. userEvent,
  8. } from 'sentry-test/reactTestingLibrary';
  9. import {ApiTokens} from 'sentry/views/settings/account/apiTokens';
  10. const organization = OrganizationFixture();
  11. describe('ApiTokens', function () {
  12. beforeEach(function () {
  13. MockApiClient.clearMockResponses();
  14. });
  15. it('renders empty result', function () {
  16. MockApiClient.addMockResponse({
  17. url: '/api-tokens/',
  18. body: null,
  19. });
  20. render(<ApiTokens organization={organization} />);
  21. });
  22. it('renders with result', function () {
  23. MockApiClient.addMockResponse({
  24. url: '/api-tokens/',
  25. body: [ApiTokenFixture()],
  26. });
  27. render(<ApiTokens organization={organization} />);
  28. });
  29. it('can delete token', async function () {
  30. MockApiClient.addMockResponse({
  31. url: '/api-tokens/',
  32. body: [ApiTokenFixture()],
  33. });
  34. const mock = MockApiClient.addMockResponse({
  35. url: '/api-tokens/',
  36. method: 'DELETE',
  37. });
  38. expect(mock).not.toHaveBeenCalled();
  39. render(<ApiTokens organization={organization} />);
  40. renderGlobalModal();
  41. await userEvent.click(screen.getByRole('button', {name: 'Remove'}));
  42. // Confirm modal
  43. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  44. // Should be loading
  45. expect(mock).toHaveBeenCalledTimes(1);
  46. expect(mock).toHaveBeenCalledWith(
  47. '/api-tokens/',
  48. expect.objectContaining({
  49. method: 'DELETE',
  50. })
  51. );
  52. });
  53. });