accountDetail.spec.jsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import AccountDetails from 'app/views/settings/account/accountDetails';
  4. jest.mock('jquery');
  5. jest.mock('scroll-to-element', () => 'scroll-to-element');
  6. const mockUserDetails = params => {
  7. MockApiClient.clearMockResponses();
  8. MockApiClient.addMockResponse({
  9. url: '/users/me/',
  10. method: 'GET',
  11. body: TestStubs.UserDetails(params),
  12. });
  13. };
  14. describe('AccountDetails', function() {
  15. beforeEach(function() {
  16. mockUserDetails();
  17. });
  18. it('renders', function() {
  19. const wrapper = mountWithTheme(
  20. <AccountDetails location={{}} />,
  21. TestStubs.routerContext()
  22. );
  23. expect(wrapper.find('input[name="name"]')).toHaveLength(1);
  24. // Stacktrace order, language, timezone
  25. expect(wrapper.find('SelectControl')).toHaveLength(3);
  26. expect(wrapper.find('BooleanField')).toHaveLength(1);
  27. expect(wrapper.find('RadioGroup')).toHaveLength(1);
  28. });
  29. it('has username field if it is different than email', function() {
  30. mockUserDetails({username: 'different@example.com'});
  31. const wrapper = mountWithTheme(
  32. <AccountDetails location={{}} />,
  33. TestStubs.routerContext()
  34. );
  35. expect(wrapper.find('input[name="username"]')).toHaveLength(1);
  36. expect(wrapper.find('input[name="username"]').prop('disabled')).toBe(false);
  37. });
  38. describe('Managed User', function() {
  39. it('does not have password fields', function() {
  40. mockUserDetails({isManaged: true});
  41. const wrapper = mountWithTheme(
  42. <AccountDetails location={{}} />,
  43. TestStubs.routerContext()
  44. );
  45. expect(wrapper.find('input[name="name"]')).toHaveLength(1);
  46. expect(wrapper.find('input[name="password"]')).toHaveLength(0);
  47. expect(wrapper.find('input[name="passwordVerify"]')).toHaveLength(0);
  48. });
  49. it('has disabled username field if it is different than email', function() {
  50. mockUserDetails({isManaged: true, username: 'different@example.com'});
  51. const wrapper = mountWithTheme(
  52. <AccountDetails location={{}} />,
  53. TestStubs.routerContext()
  54. );
  55. expect(wrapper.find('input[name="username"]')).toHaveLength(1);
  56. expect(wrapper.find('input[name="username"]').prop('disabled')).toBe(true);
  57. });
  58. });
  59. });