apiTokens.spec.jsx 1.5 KB

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