apiTokens.spec.tsx 1.3 KB

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