apiTokens.spec.jsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import {shallow, mountWithTheme} from 'sentry-test/enzyme';
  3. import {Client} from 'app/api';
  4. import ApiTokens from 'app/views/settings/account/apiTokens';
  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. });
  14. const wrapper = shallow(<ApiTokens />, routerContext);
  15. // Should be loading
  16. expect(wrapper).toMatchSnapshot();
  17. });
  18. it('renders with result', function() {
  19. Client.addMockResponse({
  20. url: '/api-tokens/',
  21. body: [TestStubs.ApiToken()],
  22. });
  23. const wrapper = shallow(<ApiTokens />, routerContext);
  24. // Should be loading
  25. expect(wrapper).toMatchSnapshot();
  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. const wrapper = mountWithTheme(<ApiTokens />, routerContext);
  38. wrapper.find('.ref-delete-api-token').simulate('click');
  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. });