accountIdentities.spec.jsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React from 'react';
  2. import {shallow, mountWithTheme} from 'sentry-test/enzyme';
  3. import {Client} from 'app/api';
  4. import AccountIdentities from 'app/views/settings/account/accountIdentities';
  5. const ENDPOINT = '/users/me/social-identities/';
  6. describe('AccountIdentities', function() {
  7. beforeEach(function() {
  8. Client.clearMockResponses();
  9. });
  10. it('renders empty', function() {
  11. Client.addMockResponse({
  12. url: ENDPOINT,
  13. method: 'GET',
  14. body: [],
  15. });
  16. const wrapper = shallow(<AccountIdentities />, TestStubs.routerContext());
  17. expect(wrapper).toMatchSnapshot();
  18. });
  19. it('renders list', function() {
  20. Client.addMockResponse({
  21. url: ENDPOINT,
  22. method: 'GET',
  23. body: [
  24. {
  25. id: '1',
  26. provider: 'github',
  27. providerLabel: 'GitHub',
  28. },
  29. ],
  30. });
  31. const wrapper = shallow(<AccountIdentities />, TestStubs.routerContext());
  32. expect(wrapper).toMatchSnapshot();
  33. });
  34. it('disconnects identity', function() {
  35. Client.addMockResponse({
  36. url: ENDPOINT,
  37. method: 'GET',
  38. body: [
  39. {
  40. id: '1',
  41. provider: 'github',
  42. providerLabel: 'GitHub',
  43. },
  44. ],
  45. });
  46. const wrapper = mountWithTheme(<AccountIdentities />, TestStubs.routerContext());
  47. const disconnectRequest = {
  48. url: `${ENDPOINT}1/`,
  49. method: 'DELETE',
  50. };
  51. const mock = Client.addMockResponse(disconnectRequest);
  52. expect(mock).not.toHaveBeenCalled();
  53. wrapper
  54. .find('Button')
  55. .first()
  56. .simulate('click');
  57. expect(mock).toHaveBeenCalledTimes(1);
  58. expect(mock).toHaveBeenCalledWith(
  59. `${ENDPOINT}1/`,
  60. expect.objectContaining({
  61. method: 'DELETE',
  62. })
  63. );
  64. });
  65. });