accountDetails.spec.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  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: TestStubs.UserDetails(params),
  11. });
  12. }
  13. describe('AccountDetails', function () {
  14. const {routerProps} = initializeOrg();
  15. beforeEach(function () {
  16. mockUserDetails();
  17. });
  18. it('renders', function () {
  19. render(<AccountDetails {...routerProps} />);
  20. expect(screen.getByRole('textbox', {name: 'Name'})).toBeEnabled();
  21. expect(screen.getByRole('checkbox', {name: 'Use a 24-hour clock'})).toBeEnabled();
  22. expect(screen.getByRole('radiogroup', {name: 'Avatar Type'})).toBeEnabled();
  23. });
  24. it('has username field if it is different than email', function () {
  25. mockUserDetails({username: 'different@example.com'});
  26. render(<AccountDetails {...routerProps} />);
  27. expect(screen.getByRole('textbox', {name: 'Username'})).toBeEnabled();
  28. });
  29. describe('Managed User', function () {
  30. it('does not have password fields', function () {
  31. mockUserDetails({isManaged: true});
  32. render(<AccountDetails {...routerProps} />);
  33. expect(screen.getByRole('textbox', {name: 'Name'})).toBeEnabled();
  34. expect(screen.queryByRole('textbox', {name: 'Password'})).not.toBeInTheDocument();
  35. });
  36. it('has disabled username field if it is different than email', function () {
  37. mockUserDetails({isManaged: true, username: 'different@example.com'});
  38. render(<AccountDetails {...routerProps} />);
  39. expect(screen.getByRole('textbox', {name: 'Username'})).toBeDisabled();
  40. });
  41. });
  42. describe('Default Issue Event', function () {
  43. const orgWithRecommendedEvent = TestStubs.Organization({
  44. features: [
  45. 'issue-details-most-helpful-event',
  46. 'issue-details-most-helpful-event-ui',
  47. ],
  48. });
  49. it('does not show the user setting without the feature enabled', function () {
  50. render(<AccountDetails {...routerProps} />);
  51. expect(screen.queryByText('Default Issue Event')).not.toBeInTheDocument();
  52. });
  53. it('shows the user setting with the feature enabled', function () {
  54. render(<AccountDetails {...routerProps} />, {
  55. organization: orgWithRecommendedEvent,
  56. });
  57. expect(screen.getByText('Default Issue Event')).toBeInTheDocument();
  58. });
  59. });
  60. });