accountDetails.spec.jsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  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. render(<AccountDetails location={{}} />);
  18. expect(screen.getByRole('textbox', {name: 'Name'})).toBeEnabled();
  19. expect(screen.getByRole('checkbox', {name: 'Use a 24-hour clock'})).toBeEnabled();
  20. expect(screen.getByRole('radiogroup', {name: 'Avatar Type'})).toBeEnabled();
  21. });
  22. it('has username field if it is different than email', function () {
  23. mockUserDetails({username: 'different@example.com'});
  24. render(<AccountDetails location={{}} />);
  25. expect(screen.getByRole('textbox', {name: 'Username'})).toBeEnabled();
  26. });
  27. describe('Managed User', function () {
  28. it('does not have password fields', function () {
  29. mockUserDetails({isManaged: true});
  30. render(<AccountDetails location={{}} />);
  31. expect(screen.getByRole('textbox', {name: 'Name'})).toBeEnabled();
  32. expect(screen.queryByRole('textbox', {name: 'Password'})).not.toBeInTheDocument();
  33. });
  34. it('has disabled username field if it is different than email', function () {
  35. mockUserDetails({isManaged: true, username: 'different@example.com'});
  36. render(<AccountDetails location={{}} />);
  37. expect(screen.getByRole('textbox', {name: 'Username'})).toBeDisabled();
  38. });
  39. });
  40. });