accountEmails.spec.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import React from 'react';
  2. import {mountWithTheme, shallow} from 'sentry-test/enzyme';
  3. import {Client} from 'app/api';
  4. import AccountEmails from 'app/views/settings/account/accountEmails';
  5. jest.mock('scroll-to-element', () => {});
  6. const ENDPOINT = '/users/me/emails/';
  7. describe('AccountEmails', function() {
  8. beforeEach(function() {
  9. Client.clearMockResponses();
  10. Client.addMockResponse({
  11. url: ENDPOINT,
  12. body: TestStubs.AccountEmails(),
  13. });
  14. });
  15. it('renders with emails', function() {
  16. const wrapper = shallow(<AccountEmails />, TestStubs.routerContext());
  17. expect(wrapper).toMatchSnapshot();
  18. });
  19. it('can remove an email', function() {
  20. const mock = Client.addMockResponse({
  21. url: ENDPOINT,
  22. method: 'DELETE',
  23. statusCode: 200,
  24. });
  25. const wrapper = mountWithTheme(<AccountEmails />, TestStubs.routerContext());
  26. expect(mock).not.toHaveBeenCalled();
  27. // The first Button should be delete button for first secondary email (NOT primary)
  28. wrapper
  29. .find('[data-test-id="remove"]')
  30. .at(1)
  31. .simulate('click');
  32. expect(mock).toHaveBeenCalledWith(
  33. ENDPOINT,
  34. expect.objectContaining({
  35. method: 'DELETE',
  36. data: {
  37. email: 'secondary1@example.com',
  38. },
  39. })
  40. );
  41. });
  42. it('can change a secondary email to primary an email', function() {
  43. const mock = Client.addMockResponse({
  44. url: ENDPOINT,
  45. method: 'PUT',
  46. statusCode: 200,
  47. });
  48. const wrapper = mountWithTheme(<AccountEmails />, TestStubs.routerContext());
  49. expect(mock).not.toHaveBeenCalled();
  50. // The first Button should be delete button for first secondary email (NOT primary)
  51. wrapper
  52. .find('Button[children="Set as primary"]')
  53. .first()
  54. .simulate('click');
  55. expect(mock).toHaveBeenCalledWith(
  56. ENDPOINT,
  57. expect.objectContaining({
  58. method: 'PUT',
  59. data: {
  60. email: 'secondary1@example.com',
  61. },
  62. })
  63. );
  64. });
  65. it('can resend verification email', function() {
  66. const mock = Client.addMockResponse({
  67. url: `${ENDPOINT}confirm/`,
  68. method: 'POST',
  69. statusCode: 200,
  70. });
  71. const wrapper = mountWithTheme(<AccountEmails />, TestStubs.routerContext());
  72. expect(mock).not.toHaveBeenCalled();
  73. wrapper.find('Button[children="Resend verification"]').simulate('click');
  74. expect(mock).toHaveBeenCalledWith(
  75. `${ENDPOINT}confirm/`,
  76. expect.objectContaining({
  77. method: 'POST',
  78. data: {
  79. email: 'secondary2@example.com',
  80. },
  81. })
  82. );
  83. });
  84. it('can add a secondary email', function() {
  85. const mock = Client.addMockResponse({
  86. url: ENDPOINT,
  87. method: 'POST',
  88. statusCode: 200,
  89. });
  90. const wrapper = mountWithTheme(<AccountEmails />, TestStubs.routerContext());
  91. expect(mock).not.toHaveBeenCalled();
  92. wrapper
  93. .find('input')
  94. .first()
  95. .simulate('change', {target: {value: 'test@example.com'}})
  96. .simulate('blur');
  97. expect(mock).toHaveBeenCalledWith(
  98. ENDPOINT,
  99. expect.objectContaining({
  100. method: 'POST',
  101. data: {
  102. email: 'test@example.com',
  103. },
  104. })
  105. );
  106. });
  107. });