accountDetails.spec.tsx 1.7 KB

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