apiTokens.spec.tsx 1.3 KB

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