accountEmails.spec.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import AccountEmails from 'sentry/views/settings/account/accountEmails';
  3. jest.mock('scroll-to-element', () => {});
  4. const ENDPOINT = '/users/me/emails/';
  5. describe('AccountEmails', function () {
  6. beforeEach(function () {
  7. MockApiClient.clearMockResponses();
  8. MockApiClient.addMockResponse({
  9. url: ENDPOINT,
  10. body: TestStubs.AccountEmails(),
  11. });
  12. });
  13. it('renders with emails', function () {
  14. render(<AccountEmails />);
  15. });
  16. it('can remove an email', async function () {
  17. const mock = MockApiClient.addMockResponse({
  18. url: ENDPOINT,
  19. method: 'DELETE',
  20. statusCode: 200,
  21. });
  22. render(<AccountEmails />);
  23. expect(mock).not.toHaveBeenCalled();
  24. await userEvent.click(screen.getAllByRole('button', {name: 'Remove email'})[0]);
  25. expect(mock).toHaveBeenCalledWith(
  26. ENDPOINT,
  27. expect.objectContaining({
  28. method: 'DELETE',
  29. data: {
  30. email: 'secondary1@example.com',
  31. },
  32. })
  33. );
  34. });
  35. it('can change a secondary email to primary an email', async function () {
  36. const mock = MockApiClient.addMockResponse({
  37. url: ENDPOINT,
  38. method: 'PUT',
  39. statusCode: 200,
  40. });
  41. render(<AccountEmails />);
  42. expect(mock).not.toHaveBeenCalled();
  43. await userEvent.click(screen.getAllByRole('button', {name: 'Set as primary'})[0]);
  44. expect(mock).toHaveBeenCalledWith(
  45. ENDPOINT,
  46. expect.objectContaining({
  47. method: 'PUT',
  48. data: {
  49. email: 'secondary1@example.com',
  50. },
  51. })
  52. );
  53. });
  54. it('can resend verification email', async function () {
  55. const mock = MockApiClient.addMockResponse({
  56. url: `${ENDPOINT}confirm/`,
  57. method: 'POST',
  58. statusCode: 200,
  59. });
  60. render(<AccountEmails />);
  61. expect(mock).not.toHaveBeenCalled();
  62. await userEvent.click(
  63. screen.getAllByRole('button', {name: 'Resend verification'})[0]
  64. );
  65. expect(mock).toHaveBeenCalledWith(
  66. `${ENDPOINT}confirm/`,
  67. expect.objectContaining({
  68. method: 'POST',
  69. data: {
  70. email: 'secondary2@example.com',
  71. },
  72. })
  73. );
  74. });
  75. it('can add a secondary email', async function () {
  76. const mock = MockApiClient.addMockResponse({
  77. url: ENDPOINT,
  78. method: 'POST',
  79. statusCode: 200,
  80. });
  81. render(<AccountEmails />);
  82. expect(mock).not.toHaveBeenCalled();
  83. await userEvent.type(screen.getByRole('textbox'), 'test@example.com{enter}');
  84. expect(mock).toHaveBeenCalledWith(
  85. ENDPOINT,
  86. expect.objectContaining({
  87. method: 'POST',
  88. data: {
  89. email: 'test@example.com',
  90. },
  91. })
  92. );
  93. });
  94. });