The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

177 lines
4.9 KiB

  1. import { pick } from 'lodash';
  2. import { emojiIndex } from 'emoji-mart';
  3. import { search } from '../emoji_mart_search_light';
  4. const trimEmojis = emoji => pick(emoji, ['id', 'unified', 'native', 'custom']);
  5. describe('emoji_index', () => {
  6. it('should give same result for emoji_index_light and emoji-mart', () => {
  7. const expected = [
  8. {
  9. id: 'pineapple',
  10. unified: '1f34d',
  11. native: '🍍',
  12. },
  13. ];
  14. expect(search('pineapple').map(trimEmojis)).toEqual(expected);
  15. expect(emojiIndex.search('pineapple').map(trimEmojis)).toEqual(expected);
  16. });
  17. it('orders search results correctly', () => {
  18. const expected = [
  19. {
  20. id: 'apple',
  21. unified: '1f34e',
  22. native: '🍎',
  23. },
  24. {
  25. id: 'pineapple',
  26. unified: '1f34d',
  27. native: '🍍',
  28. },
  29. {
  30. id: 'green_apple',
  31. unified: '1f34f',
  32. native: '🍏',
  33. },
  34. {
  35. id: 'iphone',
  36. unified: '1f4f1',
  37. native: '📱',
  38. },
  39. ];
  40. expect(search('apple').map(trimEmojis)).toEqual(expected);
  41. expect(emojiIndex.search('apple').map(trimEmojis)).toEqual(expected);
  42. });
  43. it('can include/exclude categories', () => {
  44. expect(search('flag', { include: ['people'] })).toEqual([]);
  45. expect(emojiIndex.search('flag', { include: ['people'] })).toEqual([]);
  46. });
  47. it('(different behavior from emoji-mart) do not erases custom emoji if not passed again', () => {
  48. const custom = [
  49. {
  50. id: 'mastodon',
  51. name: 'mastodon',
  52. short_names: ['mastodon'],
  53. text: '',
  54. emoticons: [],
  55. keywords: ['mastodon'],
  56. imageUrl: 'http://example.com',
  57. custom: true,
  58. },
  59. ];
  60. search('', { custom });
  61. emojiIndex.search('', { custom });
  62. const expected = [];
  63. const lightExpected = [
  64. {
  65. id: 'mastodon',
  66. custom: true,
  67. },
  68. ];
  69. expect(search('masto').map(trimEmojis)).toEqual(lightExpected);
  70. expect(emojiIndex.search('masto').map(trimEmojis)).toEqual(expected);
  71. });
  72. it('(different behavior from emoji-mart) erases custom emoji if another is passed', () => {
  73. const custom = [
  74. {
  75. id: 'mastodon',
  76. name: 'mastodon',
  77. short_names: ['mastodon'],
  78. text: '',
  79. emoticons: [],
  80. keywords: ['mastodon'],
  81. imageUrl: 'http://example.com',
  82. custom: true,
  83. },
  84. ];
  85. search('', { custom });
  86. emojiIndex.search('', { custom });
  87. const expected = [];
  88. expect(search('masto', { custom: [] }).map(trimEmojis)).toEqual(expected);
  89. expect(emojiIndex.search('masto').map(trimEmojis)).toEqual(expected);
  90. });
  91. it('handles custom emoji', () => {
  92. const custom = [
  93. {
  94. id: 'mastodon',
  95. name: 'mastodon',
  96. short_names: ['mastodon'],
  97. text: '',
  98. emoticons: [],
  99. keywords: ['mastodon'],
  100. imageUrl: 'http://example.com',
  101. custom: true,
  102. },
  103. ];
  104. search('', { custom });
  105. emojiIndex.search('', { custom });
  106. const expected = [
  107. {
  108. id: 'mastodon',
  109. custom: true,
  110. },
  111. ];
  112. expect(search('masto', { custom }).map(trimEmojis)).toEqual(expected);
  113. expect(emojiIndex.search('masto', { custom }).map(trimEmojis)).toEqual(expected);
  114. });
  115. it('should filter only emojis we care about, exclude pineapple', () => {
  116. const emojisToShowFilter = emoji => emoji.unified !== '1F34D';
  117. expect(search('apple', { emojisToShowFilter }).map((obj) => obj.id))
  118. .not.toContain('pineapple');
  119. expect(emojiIndex.search('apple', { emojisToShowFilter }).map((obj) => obj.id))
  120. .not.toContain('pineapple');
  121. });
  122. it('does an emoji whose unified name is irregular', () => {
  123. const expected = [
  124. {
  125. 'id': 'water_polo',
  126. 'unified': '1f93d',
  127. 'native': '🤽',
  128. },
  129. {
  130. 'id': 'man-playing-water-polo',
  131. 'unified': '1f93d-200d-2642-fe0f',
  132. 'native': '🤽‍♂️',
  133. },
  134. {
  135. 'id': 'woman-playing-water-polo',
  136. 'unified': '1f93d-200d-2640-fe0f',
  137. 'native': '🤽‍♀️',
  138. },
  139. ];
  140. expect(search('polo').map(trimEmojis)).toEqual(expected);
  141. expect(emojiIndex.search('polo').map(trimEmojis)).toEqual(expected);
  142. });
  143. it('can search for thinking_face', () => {
  144. const expected = [
  145. {
  146. id: 'thinking_face',
  147. unified: '1f914',
  148. native: '🤔',
  149. },
  150. ];
  151. expect(search('thinking_fac').map(trimEmojis)).toEqual(expected);
  152. expect(emojiIndex.search('thinking_fac').map(trimEmojis)).toEqual(expected);
  153. });
  154. it('can search for woman-facepalming', () => {
  155. const expected = [
  156. {
  157. id: 'woman-facepalming',
  158. unified: '1f926-200d-2640-fe0f',
  159. native: '🤦‍♀️',
  160. },
  161. ];
  162. expect(search('woman-facep').map(trimEmojis)).toEqual(expected);
  163. expect(emojiIndex.search('woman-facep').map(trimEmojis)).toEqual(expected);
  164. });
  165. });