accountEmails.spec.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  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 wrapper = mountWithTheme(<AccountEmails />);
  16. expect(wrapper).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. const wrapper = mountWithTheme(<AccountEmails />);
  25. expect(mock).not.toHaveBeenCalled();
  26. // The first Button should be delete button for first secondary email (NOT primary)
  27. wrapper.find('[data-test-id="remove"]').at(1).simulate('click');
  28. expect(mock).toHaveBeenCalledWith(
  29. ENDPOINT,
  30. expect.objectContaining({
  31. method: 'DELETE',
  32. data: {
  33. email: 'secondary1@example.com',
  34. },
  35. })
  36. );
  37. });
  38. it('can change a secondary email to primary an email', function () {
  39. const mock = Client.addMockResponse({
  40. url: ENDPOINT,
  41. method: 'PUT',
  42. statusCode: 200,
  43. });
  44. const wrapper = mountWithTheme(<AccountEmails />);
  45. expect(mock).not.toHaveBeenCalled();
  46. // The first Button should be delete button for first secondary email (NOT primary)
  47. wrapper.find('Button[children="Set as primary"]').first().simulate('click');
  48. expect(mock).toHaveBeenCalledWith(
  49. ENDPOINT,
  50. expect.objectContaining({
  51. method: 'PUT',
  52. data: {
  53. email: 'secondary1@example.com',
  54. },
  55. })
  56. );
  57. });
  58. it('can resend verification email', function () {
  59. const mock = Client.addMockResponse({
  60. url: `${ENDPOINT}confirm/`,
  61. method: 'POST',
  62. statusCode: 200,
  63. });
  64. const wrapper = mountWithTheme(<AccountEmails />);
  65. expect(mock).not.toHaveBeenCalled();
  66. wrapper.find('Button[children="Resend verification"]').simulate('click');
  67. expect(mock).toHaveBeenCalledWith(
  68. `${ENDPOINT}confirm/`,
  69. expect.objectContaining({
  70. method: 'POST',
  71. data: {
  72. email: 'secondary2@example.com',
  73. },
  74. })
  75. );
  76. });
  77. it('can add a secondary email', function () {
  78. const mock = Client.addMockResponse({
  79. url: ENDPOINT,
  80. method: 'POST',
  81. statusCode: 200,
  82. });
  83. const wrapper = mountWithTheme(<AccountEmails />);
  84. expect(mock).not.toHaveBeenCalled();
  85. wrapper
  86. .find('input')
  87. .first()
  88. .simulate('change', {target: {value: 'test@example.com'}})
  89. .simulate('blur');
  90. expect(mock).toHaveBeenCalledWith(
  91. ENDPOINT,
  92. expect.objectContaining({
  93. method: 'POST',
  94. data: {
  95. email: 'test@example.com',
  96. },
  97. })
  98. );
  99. });
  100. });