accountIdentities.spec.jsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. } from 'sentry-test/reactTestingLibrary';
  7. import {Client} from 'sentry/api';
  8. import AccountIdentities from 'sentry/views/settings/account/accountIdentities';
  9. const ENDPOINT = '/users/me/user-identities/';
  10. describe('AccountIdentities', function () {
  11. beforeEach(function () {
  12. Client.clearMockResponses();
  13. });
  14. it('renders empty', function () {
  15. Client.addMockResponse({
  16. url: ENDPOINT,
  17. method: 'GET',
  18. body: [],
  19. });
  20. const {container} = render(<AccountIdentities />);
  21. expect(container).toSnapshot();
  22. });
  23. it('renders list', function () {
  24. Client.addMockResponse({
  25. url: ENDPOINT,
  26. method: 'GET',
  27. body: [
  28. {
  29. category: 'social-identity',
  30. id: '1',
  31. provider: {
  32. key: 'github',
  33. name: 'GitHub',
  34. },
  35. status: 'can_disconnect',
  36. organization: null,
  37. },
  38. ],
  39. });
  40. const {container} = render(<AccountIdentities />);
  41. expect(container).toSnapshot();
  42. });
  43. it('disconnects identity', async function () {
  44. Client.addMockResponse({
  45. url: ENDPOINT,
  46. method: 'GET',
  47. body: [
  48. {
  49. category: 'social-identity',
  50. id: '1',
  51. provider: {
  52. key: 'github',
  53. name: 'GitHub',
  54. },
  55. status: 'can_disconnect',
  56. organization: null,
  57. },
  58. ],
  59. });
  60. render(<AccountIdentities />);
  61. const disconnectRequest = {
  62. url: `${ENDPOINT}social-identity/1/`,
  63. method: 'DELETE',
  64. };
  65. const mock = Client.addMockResponse(disconnectRequest);
  66. expect(mock).not.toHaveBeenCalled();
  67. await userEvent.click(screen.getByRole('button', {name: 'Disconnect'}));
  68. renderGlobalModal();
  69. await userEvent.click(screen.getByTestId('confirm-button'));
  70. expect(mock).toHaveBeenCalledTimes(1);
  71. expect(mock).toHaveBeenCalledWith(
  72. `${ENDPOINT}social-identity/1/`,
  73. expect.objectContaining({
  74. method: 'DELETE',
  75. })
  76. );
  77. });
  78. });