apiTokens.spec.tsx 1.4 KB

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