accountIdentities.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. waitFor,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import AccountIdentities from 'sentry/views/settings/account/accountIdentities';
  9. const ENDPOINT = '/users/me/user-identities/';
  10. describe('AccountIdentities', function () {
  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(<AccountIdentities />);
  21. });
  22. it('renders list', async function () {
  23. MockApiClient.addMockResponse({
  24. url: ENDPOINT,
  25. method: 'GET',
  26. body: [
  27. {
  28. category: 'social-identity',
  29. id: '1',
  30. provider: {
  31. key: 'github',
  32. name: 'GitHub',
  33. },
  34. status: 'can_disconnect',
  35. organization: null,
  36. },
  37. {
  38. category: 'org-identity',
  39. id: '2',
  40. provider: {
  41. key: 'google',
  42. name: 'Google',
  43. },
  44. status: 'needed_for_global_auth',
  45. organization: null,
  46. },
  47. ],
  48. });
  49. render(<AccountIdentities />);
  50. await waitFor(() =>
  51. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument()
  52. );
  53. expect(await screen.findByText('GitHub')).toBeInTheDocument();
  54. expect(await screen.findByText('Google')).toBeInTheDocument();
  55. });
  56. it('renders loading error', async function () {
  57. MockApiClient.addMockResponse({
  58. url: ENDPOINT,
  59. method: 'GET',
  60. statusCode: 400,
  61. body: {},
  62. });
  63. render(<AccountIdentities />);
  64. expect(
  65. await screen.findByText('There was an error loading data.')
  66. ).toBeInTheDocument();
  67. });
  68. it('disconnects identity', async function () {
  69. MockApiClient.addMockResponse({
  70. url: ENDPOINT,
  71. method: 'GET',
  72. body: [
  73. {
  74. category: 'social-identity',
  75. id: '1',
  76. provider: {
  77. key: 'github',
  78. name: 'GitHub',
  79. },
  80. status: 'can_disconnect',
  81. organization: null,
  82. },
  83. ],
  84. });
  85. render(<AccountIdentities />);
  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(await screen.findByRole('button', {name: 'Disconnect'}));
  93. renderGlobalModal();
  94. await userEvent.click(screen.getByTestId('confirm-button'));
  95. expect(
  96. await screen.findByText(
  97. 'There are no organization identities associated with your Sentry account'
  98. )
  99. ).toBeInTheDocument();
  100. expect(mock).toHaveBeenCalledTimes(1);
  101. expect(mock).toHaveBeenCalledWith(
  102. `${ENDPOINT}social-identity/1/`,
  103. expect.objectContaining({
  104. method: 'DELETE',
  105. })
  106. );
  107. });
  108. });