accountIdentities.spec.tsx 2.7 KB

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