userBadge.spec.tsx 1.9 KB

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