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