memberBadge.spec.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  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. render(<MemberBadge member={member} orgId="orgId" />);
  10. expect(screen.getByTestId('letter_avatar-avatar')).toBeInTheDocument();
  11. expect(screen.getByRole('link', {name: 'Foo Bar'})).toBeInTheDocument();
  12. expect(screen.getByText('foo@example.com')).toBeInTheDocument();
  13. });
  14. it('does not use a link when useLink = false', function () {
  15. render(<MemberBadge member={member} useLink={false} orgId="orgId" />);
  16. expect(screen.queryByRole('link', {name: 'Foo Bar'})).not.toBeInTheDocument();
  17. expect(screen.getByText('Foo Bar')).toBeInTheDocument();
  18. });
  19. it('does not use a link when orgId = null', function () {
  20. render(<MemberBadge member={member} useLink />);
  21. expect(screen.queryByRole('link', {name: 'Foo Bar'})).not.toBeInTheDocument();
  22. expect(screen.getByText('Foo Bar')).toBeInTheDocument();
  23. });
  24. it('can display alternate display names/emails', function () {
  25. render(
  26. <MemberBadge
  27. member={member}
  28. displayName="Other Display Name"
  29. displayEmail="Other Display Email"
  30. />
  31. );
  32. expect(screen.getByTestId('letter_avatar-avatar')).toBeInTheDocument();
  33. expect(screen.getByText('Other Display Name')).toBeInTheDocument();
  34. expect(screen.getByText('Other Display Email')).toBeInTheDocument();
  35. });
  36. it('can coalesce using username', function () {
  37. member.user = TestStubs.User({
  38. name: null,
  39. email: null,
  40. username: 'the-batman',
  41. });
  42. render(<MemberBadge member={member} />);
  43. expect(screen.getByText('the-batman')).toBeInTheDocument();
  44. });
  45. it('can coalesce using ipaddress', function () {
  46. member.user = TestStubs.User({
  47. name: null,
  48. email: null,
  49. username: null,
  50. ipAddress: '127.0.0.1',
  51. });
  52. render(<MemberBadge member={member} />);
  53. expect(screen.getByText('127.0.0.1')).toBeInTheDocument();
  54. });
  55. it('can hide email address', function () {
  56. render(<MemberBadge member={member} hideEmail />);
  57. expect(screen.queryByText('foo@example.com')).not.toBeInTheDocument();
  58. });
  59. it('renders when a member without a user to passed to member', function () {
  60. render(<MemberBadge member={{...member, user: null}} />);
  61. expect(screen.getByTestId('letter_avatar-avatar')).toBeInTheDocument();
  62. expect(screen.getByText('Sentry 1 Name')).toBeInTheDocument();
  63. });
  64. });