apiTokens.spec.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. const {container} = render(<ApiTokens organization={organization} />);
  14. // Should be loading
  15. expect(container).toSnapshot();
  16. });
  17. it('renders with result', function () {
  18. MockApiClient.addMockResponse({
  19. url: '/api-tokens/',
  20. body: [TestStubs.ApiToken()],
  21. });
  22. const {container} = render(<ApiTokens organization={organization} />);
  23. // Should be loading
  24. expect(container).toSnapshot();
  25. });
  26. it('can delete token', function () {
  27. MockApiClient.addMockResponse({
  28. url: '/api-tokens/',
  29. body: [TestStubs.ApiToken()],
  30. });
  31. const mock = MockApiClient.addMockResponse({
  32. url: '/api-tokens/',
  33. method: 'DELETE',
  34. });
  35. expect(mock).not.toHaveBeenCalled();
  36. render(<ApiTokens organization={organization} />);
  37. fireEvent.click(screen.getByLabelText('Remove'));
  38. // Should be loading
  39. expect(mock).toHaveBeenCalledTimes(1);
  40. expect(mock).toHaveBeenCalledWith(
  41. '/api-tokens/',
  42. expect.objectContaining({
  43. method: 'DELETE',
  44. })
  45. );
  46. });
  47. });