pleroma/app/soapbox/features/emoji/__tests__/emoji-index.test.ts

140 lines
3.2 KiB
TypeScript
Raw Normal View History

2022-07-09 06:59:26 -07:00
import { List, Map } from 'immutable';
import pick from 'lodash/pick';
2022-07-09 06:59:26 -07:00
import search, { addCustomToPool } from '../search';
2020-03-27 13:59:38 -07:00
2022-07-06 10:31:11 -07:00
const trimEmojis = (emoji: any) => pick(emoji, ['id', 'unified', 'native', 'custom']);
2020-03-27 13:59:38 -07:00
describe('emoji_index', () => {
it('should give same result for emoji_index_light and emoji-mart', () => {
const expected = [
{
id: 'pineapple',
unified: '1f34d',
native: '🍍',
},
];
expect(search('pineapple').map(trimEmojis)).toEqual(expected);
});
it('orders search results correctly', () => {
const expected = [
{
id: 'pineapple',
unified: '1f34d',
native: '🍍',
},
2022-07-07 17:52:29 -07:00
{
id: 'apple',
unified: '1f34e',
native: '🍎',
},
2020-03-27 13:59:38 -07:00
{
id: 'green_apple',
unified: '1f34f',
native: '🍏',
},
];
expect(search('apple').map(trimEmojis)).toEqual(expected);
});
2022-07-09 06:59:26 -07:00
it('handles custom emojis', () => {
2020-03-27 13:59:38 -07:00
const custom = [
{
id: 'mastodon',
name: 'mastodon',
keywords: ['mastodon'],
2022-07-09 06:59:26 -07:00
skins: { src: 'http://example.com' },
2020-03-27 13:59:38 -07:00
},
];
2022-07-09 06:59:26 -07:00
const custom_emojis = List([
Map({ static_url: 'http://example.com', shortcode: 'mastodon' }),
]);
2020-03-27 13:59:38 -07:00
const lightExpected = [
{
id: 'mastodon',
2020-03-27 13:59:38 -07:00
custom: true,
},
];
2022-07-09 06:59:26 -07:00
addCustomToPool(custom);
expect(search('masto', {}, custom_emojis).map(trimEmojis)).toEqual(lightExpected);
2020-03-27 13:59:38 -07:00
});
2022-07-09 06:59:26 -07:00
it('updates custom emoji if another is passed', () => {
2020-03-27 13:59:38 -07:00
const custom = [
{
id: 'mastodon',
name: 'mastodon',
keywords: ['mastodon'],
2022-07-09 06:59:26 -07:00
skins: { src: 'http://example.com' },
2020-03-27 13:59:38 -07:00
},
];
2022-07-09 06:59:26 -07:00
addCustomToPool(custom);
const custom2 = [
2020-03-27 13:59:38 -07:00
{
2022-07-09 06:59:26 -07:00
id: 'pleroma',
name: 'pleroma',
keywords: ['pleroma'],
skins: { src: 'http://example.com' },
2020-03-27 13:59:38 -07:00
},
];
2022-07-09 06:59:26 -07:00
addCustomToPool(custom2);
const custom_emojis = List([
Map({ static_url: 'http://example.com', shortcode: 'pleroma' }),
]);
2022-07-09 09:03:22 -07:00
const expected: any = [];
2022-07-09 06:59:26 -07:00
expect(search('masto', {}, custom_emojis).map(trimEmojis)).toEqual(expected);
2020-03-27 13:59:38 -07:00
});
it('does an emoji whose unified name is irregular', () => {
const expected = [
{
'id': 'water_polo',
'unified': '1f93d',
'native': '🤽',
},
{
'id': 'man-playing-water-polo',
'unified': '1f93d-200d-2642-fe0f',
'native': '🤽‍♂️',
},
{
'id': 'woman-playing-water-polo',
'unified': '1f93d-200d-2640-fe0f',
'native': '🤽‍♀️',
},
];
expect(search('polo').map(trimEmojis)).toEqual(expected);
});
it('can search for thinking_face', () => {
const expected = [
{
id: 'thinking_face',
unified: '1f914',
native: '🤔',
},
];
expect(search('thinking_fac').map(trimEmojis)).toEqual(expected);
});
it('can search for woman-facepalming', () => {
const expected = [
{
id: 'woman-facepalming',
unified: '1f926-200d-2640-fe0f',
native: '🤦‍♀️',
},
];
expect(search('woman-facep').map(trimEmojis)).toEqual(expected);
});
});