memberBadge.spec.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {mountWithTheme, shallow} from 'sentry-test/enzyme';
  2. import MemberBadge from 'sentry/components/idBadge/memberBadge';
  3. describe('MemberBadge', function () {
  4. let member;
  5. beforeEach(() => {
  6. member = TestStubs.Member();
  7. });
  8. it('renders with link when member and orgId are supplied', function () {
  9. const wrapper = mountWithTheme(<MemberBadge member={member} orgId="orgId" />);
  10. expect(wrapper.find('StyledName').prop('children')).toBe('Foo Bar');
  11. expect(wrapper.find('StyledEmail').prop('children')).toBe('foo@example.com');
  12. expect(wrapper.find('StyledName Link')).toHaveLength(1);
  13. expect(wrapper.find('StyledAvatar')).toHaveLength(1);
  14. });
  15. it('does not use a link when useLink = false', function () {
  16. const wrapper = mountWithTheme(
  17. <MemberBadge member={member} useLink={false} orgId="orgId" />
  18. );
  19. expect(wrapper.find('StyledName Link')).toHaveLength(0);
  20. });
  21. it('does not use a link when orgId = null', function () {
  22. const wrapper = mountWithTheme(<MemberBadge member={member} useLink />);
  23. expect(wrapper.find('StyledName Link')).toHaveLength(0);
  24. });
  25. it('can display alternate display names/emails', function () {
  26. const wrapper = shallow(
  27. <MemberBadge
  28. member={member}
  29. displayName="Other Display Name"
  30. displayEmail="Other Display Email"
  31. />
  32. );
  33. expect(wrapper.find('StyledName').prop('children')).toBe('Other Display Name');
  34. expect(wrapper.find('StyledEmail').prop('children')).toBe('Other Display Email');
  35. expect(wrapper.find('StyledAvatar')).toHaveLength(1);
  36. });
  37. it('can coalesce using username', function () {
  38. member.user = TestStubs.User({
  39. name: null,
  40. email: null,
  41. username: 'the-batman',
  42. });
  43. const wrapper = shallow(<MemberBadge member={member} />);
  44. expect(wrapper.find('StyledName').prop('children')).toBe(member.user.username);
  45. expect(wrapper.find('StyledEmail').prop('children')).toBe(null);
  46. expect(wrapper.find('StyledAvatar')).toHaveLength(1);
  47. });
  48. it('can coalesce using ipaddress', function () {
  49. member.user = TestStubs.User({
  50. name: null,
  51. email: null,
  52. username: null,
  53. ipAddress: '127.0.0.1',
  54. });
  55. const wrapper = shallow(<MemberBadge member={member} />);
  56. expect(wrapper.find('StyledName').prop('children')).toBe(member.user.ipAddress);
  57. expect(wrapper.find('StyledEmail').prop('children')).toBe(null);
  58. });
  59. it('can hide email address', function () {
  60. const wrapper = mountWithTheme(<MemberBadge member={member} hideEmail />);
  61. expect(wrapper.find('StyledEmail')).toHaveLength(0);
  62. });
  63. it('renders when a member without a user to passed to member', function () {
  64. const wrapper = mountWithTheme(<MemberBadge member={{...member, user: null}} />);
  65. expect(wrapper.find('StyledName').prop('children')).toBe('Sentry 1 Name');
  66. expect(wrapper.find('StyledAvatar')).toHaveLength(1);
  67. expect(wrapper.find('StyledAvatar').prop('user').email).toBe(member.email);
  68. });
  69. });