logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

emoji_index-test.js (3644B)


  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('handles custom emoji', () => {
  44. const custom = [
  45. {
  46. id: 'mastodon',
  47. name: 'mastodon',
  48. short_names: ['mastodon'],
  49. text: '',
  50. emoticons: [],
  51. keywords: ['mastodon'],
  52. imageUrl: 'http://example.com',
  53. custom: true,
  54. },
  55. ];
  56. search('', { custom });
  57. emojiIndex.search('', { custom });
  58. const expected = [
  59. {
  60. id: 'mastodon',
  61. custom: true,
  62. },
  63. ];
  64. expect(search('masto').map(trimEmojis)).toEqual(expected);
  65. expect(emojiIndex.search('masto').map(trimEmojis)).toEqual(expected);
  66. });
  67. it('should filter only emojis we care about, exclude pineapple', () => {
  68. const emojisToShowFilter = unified => unified !== '1F34D';
  69. expect(search('apple', { emojisToShowFilter }).map((obj) => obj.id))
  70. .not.toContain('pineapple');
  71. expect(emojiIndex.search('apple', { emojisToShowFilter }).map((obj) => obj.id))
  72. .not.toContain('pineapple');
  73. });
  74. it('can include/exclude categories', () => {
  75. expect(search('flag', { include: ['people'] })).toEqual([]);
  76. expect(emojiIndex.search('flag', { include: ['people'] })).toEqual([]);
  77. });
  78. it('does an emoji whose unified name is irregular', () => {
  79. const expected = [
  80. {
  81. 'id': 'water_polo',
  82. 'unified': '1f93d',
  83. 'native': '🤽',
  84. },
  85. {
  86. 'id': 'man-playing-water-polo',
  87. 'unified': '1f93d-200d-2642-fe0f',
  88. 'native': '🤽‍♂️',
  89. },
  90. {
  91. 'id': 'woman-playing-water-polo',
  92. 'unified': '1f93d-200d-2640-fe0f',
  93. 'native': '🤽‍♀️',
  94. },
  95. ];
  96. expect(search('polo').map(trimEmojis)).toEqual(expected);
  97. expect(emojiIndex.search('polo').map(trimEmojis)).toEqual(expected);
  98. });
  99. it('can search for thinking_face', () => {
  100. const expected = [
  101. {
  102. id: 'thinking_face',
  103. unified: '1f914',
  104. native: '🤔',
  105. },
  106. ];
  107. expect(search('thinking_fac').map(trimEmojis)).toEqual(expected);
  108. expect(emojiIndex.search('thinking_fac').map(trimEmojis)).toEqual(expected);
  109. });
  110. it('can search for woman-facepalming', () => {
  111. const expected = [
  112. {
  113. id: 'woman-facepalming',
  114. unified: '1f926-200d-2640-fe0f',
  115. native: '🤦‍♀️',
  116. },
  117. ];
  118. expect(search('woman-facep').map(trimEmojis)).toEqual(expected);
  119. expect(emojiIndex.search('woman-facep').map(trimEmojis)).toEqual(expected);
  120. });
  121. });