apiTokens.spec.tsx 1.4 KB

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