apiTokens.spec.jsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  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. const routerContext = TestStubs.routerContext();
  7. beforeEach(function () {
  8. Client.clearMockResponses();
  9. });
  10. it('renders empty result', function () {
  11. Client.addMockResponse({
  12. url: '/api-tokens/',
  13. body: null,
  14. });
  15. const wrapper = mountWithTheme(
  16. <ApiTokens organization={organization} />,
  17. routerContext
  18. );
  19. // Should be loading
  20. expect(wrapper).toSnapshot();
  21. });
  22. it('renders with result', function () {
  23. Client.addMockResponse({
  24. url: '/api-tokens/',
  25. body: [TestStubs.ApiToken()],
  26. });
  27. const wrapper = mountWithTheme(
  28. <ApiTokens organization={organization} />,
  29. routerContext
  30. );
  31. // Should be loading
  32. expect(wrapper).toSnapshot();
  33. });
  34. it('can delete token', function () {
  35. Client.addMockResponse({
  36. url: '/api-tokens/',
  37. body: [TestStubs.ApiToken()],
  38. });
  39. const mock = Client.addMockResponse({
  40. url: '/api-tokens/',
  41. method: 'DELETE',
  42. });
  43. expect(mock).not.toHaveBeenCalled();
  44. const wrapper = mountWithTheme(
  45. <ApiTokens organization={organization} />,
  46. routerContext
  47. );
  48. wrapper.find('button[aria-label="Remove"]').simulate('click');
  49. // Should be loading
  50. expect(mock).toHaveBeenCalledTimes(1);
  51. expect(mock).toHaveBeenCalledWith(
  52. '/api-tokens/',
  53. expect.objectContaining({
  54. method: 'DELETE',
  55. })
  56. );
  57. });
  58. });