accountIdentities.spec.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {mountGlobalModal} from 'sentry-test/modal';
  3. import {Client} from 'sentry/api';
  4. import AccountIdentities from 'sentry/views/settings/account/accountIdentities';
  5. const ENDPOINT = '/users/me/user-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 = mountWithTheme(<AccountIdentities />);
  17. expect(wrapper).toSnapshot();
  18. });
  19. it('renders list', function () {
  20. Client.addMockResponse({
  21. url: ENDPOINT,
  22. method: 'GET',
  23. body: [
  24. {
  25. category: 'social-identity',
  26. id: '1',
  27. provider: {
  28. key: 'github',
  29. name: 'GitHub',
  30. },
  31. status: 'can_disconnect',
  32. organization: null,
  33. },
  34. ],
  35. });
  36. const wrapper = mountWithTheme(<AccountIdentities />);
  37. expect(wrapper).toSnapshot();
  38. });
  39. it('disconnects identity', async function () {
  40. Client.addMockResponse({
  41. url: ENDPOINT,
  42. method: 'GET',
  43. body: [
  44. {
  45. category: 'social-identity',
  46. id: '1',
  47. provider: {
  48. key: 'github',
  49. name: 'GitHub',
  50. },
  51. status: 'can_disconnect',
  52. organization: null,
  53. },
  54. ],
  55. });
  56. const wrapper = mountWithTheme(<AccountIdentities />);
  57. const disconnectRequest = {
  58. url: `${ENDPOINT}social-identity/1/`,
  59. method: 'DELETE',
  60. };
  61. const mock = Client.addMockResponse(disconnectRequest);
  62. expect(mock).not.toHaveBeenCalled();
  63. wrapper.find('Button').first().simulate('click');
  64. const modal = await mountGlobalModal();
  65. modal.find('Button[priority="danger"]').simulate('click');
  66. expect(mock).toHaveBeenCalledTimes(1);
  67. expect(mock).toHaveBeenCalledWith(
  68. `${ENDPOINT}social-identity/1/`,
  69. expect.objectContaining({
  70. method: 'DELETE',
  71. })
  72. );
  73. });
  74. });