accountDetail.spec.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(
  18. <AccountDetails location={{}} />,
  19. TestStubs.routerContext()
  20. );
  21. expect(wrapper.find('input[name="name"]')).toHaveLength(1);
  22. // Stacktrace order, language, timezone, theme
  23. expect(wrapper.find('SelectControl')).toHaveLength(4);
  24. expect(wrapper.find('BooleanField')).toHaveLength(1);
  25. expect(wrapper.find('RadioGroup')).toHaveLength(1);
  26. });
  27. it('has username field if it is different than email', function () {
  28. mockUserDetails({username: 'different@example.com'});
  29. const wrapper = mountWithTheme(
  30. <AccountDetails location={{}} />,
  31. TestStubs.routerContext()
  32. );
  33. expect(wrapper.find('input[name="username"]')).toHaveLength(1);
  34. expect(wrapper.find('input[name="username"]').prop('disabled')).toBe(false);
  35. });
  36. describe('Managed User', function () {
  37. it('does not have password fields', function () {
  38. mockUserDetails({isManaged: true});
  39. const wrapper = mountWithTheme(
  40. <AccountDetails location={{}} />,
  41. TestStubs.routerContext()
  42. );
  43. expect(wrapper.find('input[name="name"]')).toHaveLength(1);
  44. expect(wrapper.find('input[name="password"]')).toHaveLength(0);
  45. expect(wrapper.find('input[name="passwordVerify"]')).toHaveLength(0);
  46. });
  47. it('has disabled username field if it is different than email', function () {
  48. mockUserDetails({isManaged: true, username: 'different@example.com'});
  49. const wrapper = mountWithTheme(
  50. <AccountDetails location={{}} />,
  51. TestStubs.routerContext()
  52. );
  53. expect(wrapper.find('input[name="username"]')).toHaveLength(1);
  54. expect(wrapper.find('input[name="username"]').prop('disabled')).toBe(true);
  55. });
  56. });
  57. });