accountIdentities.spec.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {Client} from 'sentry/api';
  3. import GlobalModal from 'sentry/components/globalModal';
  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 {container} = render(<AccountIdentities />);
  17. expect(container).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 {container} = render(<AccountIdentities />);
  37. expect(container).toSnapshot();
  38. });
  39. it('disconnects identity', 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. render(<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. userEvent.click(screen.getByRole('button', {name: 'Disconnect'}));
  64. render(<GlobalModal />);
  65. userEvent.click(screen.getByTestId('confirm-button'));
  66. expect(mock).toHaveBeenCalledTimes(1);
  67. expect(mock).toHaveBeenCalledWith(
  68. `${ENDPOINT}social-identity/1/`,
  69. expect.objectContaining({
  70. method: 'DELETE',
  71. })
  72. );
  73. });
  74. });