userBadge.spec.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import UserBadge from 'sentry/components/idBadge/userBadge';
  3. describe('UserBadge', function () {
  4. const user = TestStubs.User();
  5. it('renders with no link when user is supplied', function () {
  6. const wrapper = mountWithTheme(<UserBadge user={user} />);
  7. expect(wrapper.find('StyledUserBadge')).toHaveLength(1);
  8. expect(wrapper.find('StyledName').prop('children')).toBe('Foo Bar');
  9. expect(wrapper.find('StyledEmail').prop('children')).toBe('foo@example.com');
  10. expect(wrapper.find('StyledName Link')).toHaveLength(0);
  11. });
  12. it('can display alternate display names/emails', function () {
  13. const wrapper = mountWithTheme(
  14. <UserBadge
  15. user={user}
  16. displayName="Other Display Name"
  17. displayEmail="Other Display Email"
  18. />
  19. );
  20. expect(wrapper.find('StyledName').prop('children')).toBe('Other Display Name');
  21. expect(wrapper.find('StyledEmail').prop('children')).toBe('Other Display Email');
  22. });
  23. it('can coalesce using username', function () {
  24. const username = TestStubs.User({
  25. name: null,
  26. email: null,
  27. username: 'the-batman',
  28. });
  29. const wrapper = mountWithTheme(<UserBadge user={username} />);
  30. expect(wrapper.find('StyledName').prop('children')).toBe(username.username);
  31. expect(wrapper.find('StyledEmail').prop('children')).toBe(null);
  32. });
  33. it('can coalesce using ipaddress', function () {
  34. const ipUser = TestStubs.User({
  35. name: null,
  36. email: null,
  37. username: null,
  38. ipAddress: '127.0.0.1',
  39. });
  40. const wrapper = mountWithTheme(<UserBadge user={ipUser} />);
  41. expect(wrapper.find('StyledName').prop('children')).toBe(ipUser.ipAddress);
  42. expect(wrapper.find('StyledEmail').prop('children')).toBe(null);
  43. });
  44. it('can coalesce using id', function () {
  45. const idUser = TestStubs.User({
  46. id: '99',
  47. name: null,
  48. email: null,
  49. username: null,
  50. ipAddress: null,
  51. });
  52. const wrapper = mountWithTheme(<UserBadge user={idUser} />);
  53. expect(wrapper.find('StyledName').prop('children')).toBe(idUser.id);
  54. expect(wrapper.find('StyledEmail').prop('children')).toBe(null);
  55. });
  56. it('can hide email address', function () {
  57. const wrapper = mountWithTheme(<UserBadge user={user} hideEmail />);
  58. expect(wrapper.find('StyledEmail')).toHaveLength(0);
  59. });
  60. });