formatters.spec.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {userDisplayName} from 'app/utils/formatters';
  2. describe('formatters', function() {
  3. describe('userDisplayName', function() {
  4. it('should only show email, if name and email are the same', function() {
  5. expect(
  6. userDisplayName({
  7. name: 'foo@bar.com',
  8. email: 'foo@bar.com',
  9. })
  10. ).toEqual('foo@bar.com');
  11. });
  12. it('should show name + email, if name and email differ', function() {
  13. expect(
  14. userDisplayName({
  15. name: 'user',
  16. email: 'foo@bar.com',
  17. })
  18. ).toEqual('user (foo@bar.com)');
  19. });
  20. it('should show unknown author with email, if email is only provided', function() {
  21. expect(
  22. userDisplayName({
  23. email: 'foo@bar.com',
  24. })
  25. ).toEqual('Unknown author (foo@bar.com)');
  26. });
  27. it('should show unknown author, if author or email is just whitespace', function() {
  28. expect(
  29. userDisplayName({
  30. // eslint-disable-next-line quotes
  31. name: `\t\n `,
  32. })
  33. ).toEqual('Unknown author');
  34. expect(
  35. userDisplayName({
  36. // eslint-disable-next-line quotes
  37. email: `\t\n `,
  38. })
  39. ).toEqual('Unknown author');
  40. });
  41. it('should show unknown author, if user object is either not an object or incomplete', function() {
  42. expect(userDisplayName()).toEqual('Unknown author');
  43. expect(userDisplayName({})).toEqual('Unknown author');
  44. });
  45. });
  46. });