accountIdentities.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. beforeEach(function () {
  11. MockApiClient.clearMockResponses();
  12. });
  13. it('renders empty', function () {
  14. MockApiClient.addMockResponse({
  15. url: ENDPOINT,
  16. method: 'GET',
  17. body: [],
  18. });
  19. render(<AccountIdentities />);
  20. });
  21. it('renders list', async function () {
  22. MockApiClient.addMockResponse({
  23. url: ENDPOINT,
  24. method: 'GET',
  25. body: [
  26. {
  27. category: 'social-identity',
  28. id: '1',
  29. provider: {
  30. key: 'github',
  31. name: 'GitHub',
  32. },
  33. status: 'can_disconnect',
  34. organization: null,
  35. },
  36. {
  37. category: 'org-identity',
  38. id: '2',
  39. provider: {
  40. key: 'google',
  41. name: 'Google',
  42. },
  43. status: 'needed_for_global_auth',
  44. organization: null,
  45. },
  46. ],
  47. });
  48. render(<AccountIdentities />);
  49. expect(await screen.findByTestId('loading-indicator')).toBeInTheDocument();
  50. expect(await screen.findByText('GitHub')).toBeInTheDocument();
  51. expect(await screen.findByText('Google')).toBeInTheDocument();
  52. });
  53. it('renders loading error', async function () {
  54. MockApiClient.addMockResponse({
  55. url: ENDPOINT,
  56. method: 'GET',
  57. statusCode: 400,
  58. body: {},
  59. });
  60. render(<AccountIdentities />);
  61. expect(
  62. await screen.findByText('There was an error loading data.')
  63. ).toBeInTheDocument();
  64. });
  65. it('disconnects identity', async function () {
  66. MockApiClient.addMockResponse({
  67. url: ENDPOINT,
  68. method: 'GET',
  69. body: [
  70. {
  71. category: 'social-identity',
  72. id: '1',
  73. provider: {
  74. key: 'github',
  75. name: 'GitHub',
  76. },
  77. status: 'can_disconnect',
  78. organization: null,
  79. },
  80. ],
  81. });
  82. render(<AccountIdentities />);
  83. const disconnectRequest = {
  84. url: `${ENDPOINT}social-identity/1/`,
  85. method: 'DELETE',
  86. };
  87. const mock = MockApiClient.addMockResponse(disconnectRequest);
  88. expect(mock).not.toHaveBeenCalled();
  89. await userEvent.click(await screen.findByRole('button', {name: 'Disconnect'}));
  90. renderGlobalModal();
  91. await userEvent.click(screen.getByTestId('confirm-button'));
  92. expect(
  93. await screen.findByText(
  94. 'There are no organization identities associated with your Sentry account'
  95. )
  96. ).toBeInTheDocument();
  97. expect(mock).toHaveBeenCalledTimes(1);
  98. expect(mock).toHaveBeenCalledWith(
  99. `${ENDPOINT}social-identity/1/`,
  100. expect.objectContaining({
  101. method: 'DELETE',
  102. })
  103. );
  104. });
  105. });