accountIdentities.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. 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. });
  31. it('renders list', function () {
  32. MockApiClient.addMockResponse({
  33. url: ENDPOINT,
  34. method: 'GET',
  35. body: [
  36. {
  37. category: 'social-identity',
  38. id: '1',
  39. provider: {
  40. key: 'github',
  41. name: 'GitHub',
  42. },
  43. status: 'can_disconnect',
  44. organization: null,
  45. },
  46. ],
  47. });
  48. render(
  49. <AccountIdentities
  50. route={router.routes[0]}
  51. routeParams={router.params}
  52. location={router.location}
  53. params={router.params}
  54. router={router}
  55. routes={router.routes}
  56. />
  57. );
  58. });
  59. it('disconnects identity', async function () {
  60. MockApiClient.addMockResponse({
  61. url: ENDPOINT,
  62. method: 'GET',
  63. body: [
  64. {
  65. category: 'social-identity',
  66. id: '1',
  67. provider: {
  68. key: 'github',
  69. name: 'GitHub',
  70. },
  71. status: 'can_disconnect',
  72. organization: null,
  73. },
  74. ],
  75. });
  76. render(
  77. <AccountIdentities
  78. route={router.routes[0]}
  79. routeParams={router.params}
  80. location={router.location}
  81. params={router.params}
  82. router={router}
  83. routes={router.routes}
  84. />
  85. );
  86. const disconnectRequest = {
  87. url: `${ENDPOINT}social-identity/1/`,
  88. method: 'DELETE',
  89. };
  90. const mock = MockApiClient.addMockResponse(disconnectRequest);
  91. expect(mock).not.toHaveBeenCalled();
  92. await userEvent.click(screen.getByRole('button', {name: 'Disconnect'}));
  93. renderGlobalModal();
  94. await userEvent.click(screen.getByTestId('confirm-button'));
  95. expect(mock).toHaveBeenCalledTimes(1);
  96. expect(mock).toHaveBeenCalledWith(
  97. `${ENDPOINT}social-identity/1/`,
  98. expect.objectContaining({
  99. method: 'DELETE',
  100. })
  101. );
  102. });
  103. });