letterAvatar.spec.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React from 'react';
  2. import {mount} from 'sentry-test/enzyme';
  3. import LetterAvatar from 'app/components/letterAvatar';
  4. describe('LetterAvatar', function() {
  5. const USER_1 = {
  6. identifier: 'janebloggs@example.com',
  7. displayName: 'Jane Bloggs',
  8. };
  9. const USER_2 = {
  10. identifier: 'johnsmith@example.com',
  11. displayName: 'johnsmith@example.com',
  12. };
  13. const USER_3 = {
  14. identifier: 'foo@example.com',
  15. displayName: 'foo@example.com',
  16. };
  17. const USER_4 = {
  18. identifier: '2',
  19. displayName: '',
  20. };
  21. const USER_5 = {
  22. identifier: '127.0.0.1',
  23. displayName: '',
  24. };
  25. const USER_6 = {
  26. identifier: 'janebloggs@example.com',
  27. displayName: 'Jane Bloggs ',
  28. };
  29. const USER_7 = {
  30. identifier: 'janebloggs@example.com',
  31. displayName: ' ',
  32. };
  33. const USER_8 = {
  34. identifier: 'janebloggs@example.com',
  35. displayName: '\u2603super \u2603duper',
  36. };
  37. const USER_9 = {
  38. identifier: 'janebloggs@example.com',
  39. displayName: 'jane austen bloggs',
  40. };
  41. describe('display name', function() {
  42. it('should get initials based on name', function() {
  43. const letterAvatar = mount(<LetterAvatar {...USER_1} />);
  44. expect(letterAvatar.text()).toEqual('JB');
  45. });
  46. it('should get initials based on email', function() {
  47. const letterAvatar = mount(<LetterAvatar {...USER_2} />);
  48. expect(letterAvatar.text()).toEqual('J');
  49. });
  50. it('should get initials based on username', function() {
  51. const letterAvatar = mount(<LetterAvatar {...USER_3} />);
  52. expect(letterAvatar.text()).toEqual('F');
  53. });
  54. it('should show question mark if user has no display name', function() {
  55. const letterAvatar = mount(<LetterAvatar {...USER_4} />);
  56. expect(letterAvatar.text()).toEqual('?');
  57. });
  58. it('should show question mark even if display name is a space', function() {
  59. const letterAvatar = mount(<LetterAvatar {...USER_7} />);
  60. expect(letterAvatar.text()).toEqual('?');
  61. });
  62. it('should get initials based on name even if there are trailing spaces', function() {
  63. const letterAvatar = mount(<LetterAvatar {...USER_6} />);
  64. expect(letterAvatar.text()).toEqual('JB');
  65. });
  66. it('should not slice multibyte characters in half', function() {
  67. const letterAvatar = mount(<LetterAvatar {...USER_8} />);
  68. expect(letterAvatar.text()).toEqual('\u2603\u2603');
  69. });
  70. it('should pick most last name', function() {
  71. const letterAvatar = mount(<LetterAvatar {...USER_9} />);
  72. expect(letterAvatar.text()).toEqual('JB');
  73. });
  74. });
  75. describe('color', function() {
  76. it('should return a color based on email', function() {
  77. const letterAvatar = mount(<LetterAvatar {...USER_1} />);
  78. expect(letterAvatar.find('rect').props().fill).toEqual('#4e3fb4');
  79. });
  80. it('should return a color based on username', function() {
  81. const letterAvatar = mount(<LetterAvatar {...USER_3} />);
  82. expect(letterAvatar.find('rect').props().fill).toEqual('#315cac');
  83. });
  84. it('should return a color based on id', function() {
  85. const letterAvatar = mount(<LetterAvatar {...USER_4} />);
  86. expect(letterAvatar.find('rect').props().fill).toEqual('#57be8c');
  87. });
  88. it('should return a color based on ip address', function() {
  89. const letterAvatar = mount(<LetterAvatar {...USER_5} />);
  90. expect(letterAvatar.find('rect').props().fill).toEqual('#ec5e44');
  91. });
  92. });
  93. });