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.

99 lines
3.1 KiB

  1. import { expect } from 'chai';
  2. import { search } from '../../../app/javascript/mastodon/features/emoji/emoji_mart_search_light';
  3. import { emojiIndex } from 'emoji-mart';
  4. import { pick } from 'lodash';
  5. const trimEmojis = emoji => pick(emoji, ['id', 'unified', 'native', 'custom']);
  6. // hack to fix https://github.com/chaijs/type-detect/issues/98
  7. // see: https://github.com/chaijs/type-detect/issues/98#issuecomment-325010785
  8. import jsdom from 'jsdom';
  9. global.window = new jsdom.JSDOM().window;
  10. global.document = window.document;
  11. global.HTMLElement = window.HTMLElement;
  12. describe('emoji_index', () => {
  13. it('should give same result for emoji_index_light and emoji-mart', () => {
  14. let expected = [{
  15. id: 'pineapple',
  16. unified: '1f34d',
  17. native: '🍍',
  18. }];
  19. expect(search('pineapple').map(trimEmojis)).to.deep.equal(expected);
  20. expect(emojiIndex.search('pineapple').map(trimEmojis)).to.deep.equal(expected);
  21. });
  22. it('orders search results correctly', () => {
  23. let expected = [{
  24. id: 'apple',
  25. unified: '1f34e',
  26. native: '🍎',
  27. }, {
  28. id: 'pineapple',
  29. unified: '1f34d',
  30. native: '🍍',
  31. }, {
  32. id: 'green_apple',
  33. unified: '1f34f',
  34. native: '🍏',
  35. }, {
  36. id: 'iphone',
  37. unified: '1f4f1',
  38. native: '📱',
  39. }];
  40. expect(search('apple').map(trimEmojis)).to.deep.equal(expected);
  41. expect(emojiIndex.search('apple').map(trimEmojis)).to.deep.equal(expected);
  42. });
  43. it('handles custom emoji', () => {
  44. let custom = [{
  45. id: 'mastodon',
  46. name: 'mastodon',
  47. short_names: ['mastodon'],
  48. text: '',
  49. emoticons: [],
  50. keywords: ['mastodon'],
  51. imageUrl: 'http://example.com',
  52. custom: true,
  53. }];
  54. search('', { custom });
  55. emojiIndex.search('', { custom });
  56. let expected = [ { id: 'mastodon', custom: true } ];
  57. expect(search('masto').map(trimEmojis)).to.deep.equal(expected);
  58. expect(emojiIndex.search('masto').map(trimEmojis)).to.deep.equal(expected);
  59. });
  60. it('should filter only emojis we care about, exclude pineapple', () => {
  61. let emojisToShowFilter = (unified) => unified !== '1F34D';
  62. expect(search('apple', { emojisToShowFilter }).map((obj) => obj.id))
  63. .not.to.contain('pineapple');
  64. expect(emojiIndex.search('apple', { emojisToShowFilter }).map((obj) => obj.id))
  65. .not.to.contain('pineapple');
  66. });
  67. it('can include/exclude categories', () => {
  68. expect(search('flag', { include: ['people'] }))
  69. .to.deep.equal([]);
  70. expect(emojiIndex.search('flag', { include: ['people'] }))
  71. .to.deep.equal([]);
  72. });
  73. it('does an emoji whose unified name is irregular', () => {
  74. let expected = [{
  75. 'id': 'water_polo',
  76. 'unified': '1f93d',
  77. 'native': '🤽',
  78. }, {
  79. 'id': 'man-playing-water-polo',
  80. 'unified': '1f93d-200d-2642-fe0f',
  81. 'native': '🤽‍♂️',
  82. }, {
  83. 'id': 'woman-playing-water-polo',
  84. 'unified': '1f93d-200d-2640-fe0f',
  85. 'native': '🤽‍♀️',
  86. }];
  87. expect(search('polo').map(trimEmojis)).to.deep.equal(expected);
  88. expect(emojiIndex.search('polo').map(trimEmojis)).to.deep.equal(expected);
  89. });
  90. });