accountEmails.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {Client} from 'sentry/api';
  3. import AccountEmails from 'sentry/views/settings/account/accountEmails';
  4. jest.mock('scroll-to-element', () => {});
  5. const ENDPOINT = '/users/me/emails/';
  6. describe('AccountEmails', function () {
  7. beforeEach(function () {
  8. Client.clearMockResponses();
  9. Client.addMockResponse({
  10. url: ENDPOINT,
  11. body: TestStubs.AccountEmails(),
  12. });
  13. });
  14. it('renders with emails', function () {
  15. const {container} = render(<AccountEmails />);
  16. expect(container).toSnapshot();
  17. });
  18. it('can remove an email', function () {
  19. const mock = Client.addMockResponse({
  20. url: ENDPOINT,
  21. method: 'DELETE',
  22. statusCode: 200,
  23. });
  24. render(<AccountEmails />);
  25. expect(mock).not.toHaveBeenCalled();
  26. userEvent.click(screen.getAllByRole('button', {name: 'Remove email'})[0]);
  27. expect(mock).toHaveBeenCalledWith(
  28. ENDPOINT,
  29. expect.objectContaining({
  30. method: 'DELETE',
  31. data: {
  32. email: 'secondary1@example.com',
  33. },
  34. })
  35. );
  36. });
  37. it('can change a secondary email to primary an email', function () {
  38. const mock = Client.addMockResponse({
  39. url: ENDPOINT,
  40. method: 'PUT',
  41. statusCode: 200,
  42. });
  43. render(<AccountEmails />);
  44. expect(mock).not.toHaveBeenCalled();
  45. userEvent.click(screen.getAllByRole('button', {name: 'Set as primary'})[0]);
  46. expect(mock).toHaveBeenCalledWith(
  47. ENDPOINT,
  48. expect.objectContaining({
  49. method: 'PUT',
  50. data: {
  51. email: 'secondary1@example.com',
  52. },
  53. })
  54. );
  55. });
  56. it('can resend verification email', function () {
  57. const mock = Client.addMockResponse({
  58. url: `${ENDPOINT}confirm/`,
  59. method: 'POST',
  60. statusCode: 200,
  61. });
  62. render(<AccountEmails />);
  63. expect(mock).not.toHaveBeenCalled();
  64. userEvent.click(screen.getAllByRole('button', {name: 'Resend verification'})[0]);
  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', function () {
  76. const mock = Client.addMockResponse({
  77. url: ENDPOINT,
  78. method: 'POST',
  79. statusCode: 200,
  80. });
  81. render(<AccountEmails />);
  82. expect(mock).not.toHaveBeenCalled();
  83. 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. });