accountDetail.spec.jsx 2.0 KB

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