accountDetails.spec.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {UserDetails} from 'sentry-fixture/userDetails';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import AccountDetails from 'sentry/views/settings/account/accountDetails';
  5. jest.mock('scroll-to-element', () => 'scroll-to-element');
  6. function mockUserDetails(params?: any) {
  7. MockApiClient.clearMockResponses();
  8. MockApiClient.addMockResponse({
  9. url: '/users/me/',
  10. method: 'GET',
  11. body: UserDetails(params),
  12. });
  13. }
  14. describe('AccountDetails', function () {
  15. const {routerProps} = initializeOrg();
  16. beforeEach(function () {
  17. mockUserDetails();
  18. });
  19. it('renders', function () {
  20. render(<AccountDetails {...routerProps} />);
  21. expect(screen.getByRole('textbox', {name: 'Name'})).toBeEnabled();
  22. expect(screen.getByRole('checkbox', {name: 'Use a 24-hour clock'})).toBeEnabled();
  23. expect(screen.getByRole('radiogroup', {name: 'Avatar Type'})).toBeEnabled();
  24. });
  25. it('has username field if it is different than email', function () {
  26. mockUserDetails({username: 'different@example.com'});
  27. render(<AccountDetails {...routerProps} />);
  28. expect(screen.getByRole('textbox', {name: 'Username'})).toBeEnabled();
  29. });
  30. describe('Managed User', function () {
  31. it('does not have password fields', function () {
  32. mockUserDetails({isManaged: true});
  33. render(<AccountDetails {...routerProps} />);
  34. expect(screen.getByRole('textbox', {name: 'Name'})).toBeEnabled();
  35. expect(screen.queryByRole('textbox', {name: 'Password'})).not.toBeInTheDocument();
  36. });
  37. it('has disabled username field if it is different than email', function () {
  38. mockUserDetails({isManaged: true, username: 'different@example.com'});
  39. render(<AccountDetails {...routerProps} />);
  40. expect(screen.getByRole('textbox', {name: 'Username'})).toBeDisabled();
  41. });
  42. });
  43. });