2021-02-06 09:09:11 +00:00
|
|
|
|
import { emojiFixtureMap, mockEmojiData, initEmojiMock } from 'helpers/emoji';
|
2021-02-14 18:09:20 +00:00
|
|
|
|
import { trimText } from 'helpers/text_helper';
|
2021-02-06 09:09:11 +00:00
|
|
|
|
import { glEmojiTag, searchEmoji, getEmojiInfo, sortEmoji } from '~/emoji';
|
2017-06-23 20:25:21 +00:00
|
|
|
|
import isEmojiUnicodeSupported, {
|
2017-03-07 21:25:27 +00:00
|
|
|
|
isFlagEmoji,
|
2017-11-14 21:59:23 +00:00
|
|
|
|
isRainbowFlagEmoji,
|
2017-03-07 21:25:27 +00:00
|
|
|
|
isKeycapEmoji,
|
|
|
|
|
isSkinToneComboEmoji,
|
|
|
|
|
isHorceRacingSkinToneComboEmoji,
|
|
|
|
|
isPersonZwjEmoji,
|
2017-06-27 05:10:17 +00:00
|
|
|
|
} from '~/emoji/support/is_emoji_unicode_supported';
|
2017-02-28 04:44:34 +00:00
|
|
|
|
|
|
|
|
|
const emptySupportMap = {
|
|
|
|
|
personZwj: false,
|
|
|
|
|
horseRacing: false,
|
|
|
|
|
flag: false,
|
|
|
|
|
skinToneModifier: false,
|
|
|
|
|
'9.0': false,
|
|
|
|
|
'8.0': false,
|
|
|
|
|
'7.0': false,
|
|
|
|
|
6.1: false,
|
|
|
|
|
'6.0': false,
|
|
|
|
|
5.2: false,
|
|
|
|
|
5.1: false,
|
|
|
|
|
4.1: false,
|
|
|
|
|
'4.0': false,
|
|
|
|
|
3.2: false,
|
|
|
|
|
'3.0': false,
|
|
|
|
|
1.1: false,
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
describe('emoji', () => {
|
2020-07-08 06:09:13 +00:00
|
|
|
|
let mock;
|
2017-02-28 04:44:34 +00:00
|
|
|
|
|
2020-10-13 09:08:27 +00:00
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
mock = await initEmojiMock();
|
2020-07-08 06:09:13 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
mock.restore();
|
|
|
|
|
});
|
2017-02-28 04:44:34 +00:00
|
|
|
|
|
|
|
|
|
describe('glEmojiTag', () => {
|
2019-03-14 09:18:18 +00:00
|
|
|
|
it('bomb emoji', () => {
|
2017-02-28 04:44:34 +00:00
|
|
|
|
const emojiKey = 'bomb';
|
2021-02-06 09:09:11 +00:00
|
|
|
|
const markup = glEmojiTag(emojiKey);
|
2017-02-28 04:44:34 +00:00
|
|
|
|
|
2020-07-08 06:09:13 +00:00
|
|
|
|
expect(trimText(markup)).toMatchInlineSnapshot(
|
|
|
|
|
`"<gl-emoji data-name=\\"bomb\\"></gl-emoji>"`,
|
2019-03-14 09:18:18 +00:00
|
|
|
|
);
|
2017-02-28 04:44:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
2019-03-14 09:18:18 +00:00
|
|
|
|
it('bomb emoji with sprite fallback readiness', () => {
|
2017-02-28 04:44:34 +00:00
|
|
|
|
const emojiKey = 'bomb';
|
2021-02-06 09:09:11 +00:00
|
|
|
|
const markup = glEmojiTag(emojiKey, {
|
2017-02-28 04:44:34 +00:00
|
|
|
|
sprite: true,
|
|
|
|
|
});
|
2020-07-08 06:09:13 +00:00
|
|
|
|
expect(trimText(markup)).toMatchInlineSnapshot(
|
|
|
|
|
`"<gl-emoji data-fallback-sprite-class=\\"emoji-bomb\\" data-name=\\"bomb\\"></gl-emoji>"`,
|
2019-03-14 09:18:18 +00:00
|
|
|
|
);
|
2017-03-16 19:37:25 +00:00
|
|
|
|
});
|
2017-02-28 04:44:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isFlagEmoji', () => {
|
2017-06-02 08:52:27 +00:00
|
|
|
|
it('should gracefully handle empty string', () => {
|
|
|
|
|
expect(isFlagEmoji('')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect flag_ac', () => {
|
|
|
|
|
expect(isFlagEmoji('🇦🇨')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect flag_us', () => {
|
|
|
|
|
expect(isFlagEmoji('🇺🇸')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect flag_zw', () => {
|
|
|
|
|
expect(isFlagEmoji('🇿🇼')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect flags', () => {
|
|
|
|
|
expect(isFlagEmoji('🎏')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect triangular_flag_on_post', () => {
|
|
|
|
|
expect(isFlagEmoji('🚩')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect single letter', () => {
|
|
|
|
|
expect(isFlagEmoji('🇦')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect >2 letters', () => {
|
|
|
|
|
expect(isFlagEmoji('🇦🇧🇨')).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-14 21:59:23 +00:00
|
|
|
|
describe('isRainbowFlagEmoji', () => {
|
|
|
|
|
it('should gracefully handle empty string', () => {
|
|
|
|
|
expect(isRainbowFlagEmoji('')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-11-14 21:59:23 +00:00
|
|
|
|
it('should detect rainbow_flag', () => {
|
|
|
|
|
expect(isRainbowFlagEmoji('🏳🌈')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
|
it("should not detect flag_white on its' own", () => {
|
2017-11-14 21:59:23 +00:00
|
|
|
|
expect(isRainbowFlagEmoji('🏳')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
|
it("should not detect rainbow on its' own", () => {
|
2017-11-14 21:59:23 +00:00
|
|
|
|
expect(isRainbowFlagEmoji('🌈')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-11-14 21:59:23 +00:00
|
|
|
|
it('should not detect flag_white with something else', () => {
|
|
|
|
|
expect(isRainbowFlagEmoji('🏳🔵')).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
describe('isKeycapEmoji', () => {
|
2017-06-02 08:52:27 +00:00
|
|
|
|
it('should gracefully handle empty string', () => {
|
|
|
|
|
expect(isKeycapEmoji('')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect one(keycap)', () => {
|
|
|
|
|
expect(isKeycapEmoji('1️⃣')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect nine(keycap)', () => {
|
|
|
|
|
expect(isKeycapEmoji('9️⃣')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect ten(keycap)', () => {
|
|
|
|
|
expect(isKeycapEmoji('🔟')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect hash(keycap)', () => {
|
|
|
|
|
expect(isKeycapEmoji('#⃣')).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isSkinToneComboEmoji', () => {
|
2017-06-02 08:52:27 +00:00
|
|
|
|
it('should gracefully handle empty string', () => {
|
|
|
|
|
expect(isSkinToneComboEmoji('')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect hand_splayed_tone5', () => {
|
|
|
|
|
expect(isSkinToneComboEmoji('🖐🏿')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect hand_splayed', () => {
|
|
|
|
|
expect(isSkinToneComboEmoji('🖐')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect lifter_tone1', () => {
|
|
|
|
|
expect(isSkinToneComboEmoji('🏋🏻')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect lifter', () => {
|
|
|
|
|
expect(isSkinToneComboEmoji('🏋')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect rowboat_tone4', () => {
|
|
|
|
|
expect(isSkinToneComboEmoji('🚣🏾')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect rowboat', () => {
|
|
|
|
|
expect(isSkinToneComboEmoji('🚣')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect individual tone emoji', () => {
|
|
|
|
|
expect(isSkinToneComboEmoji('🏻')).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isHorceRacingSkinToneComboEmoji', () => {
|
2017-06-02 08:52:27 +00:00
|
|
|
|
it('should gracefully handle empty string', () => {
|
|
|
|
|
expect(isHorceRacingSkinToneComboEmoji('')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect horse_racing_tone2', () => {
|
|
|
|
|
expect(isHorceRacingSkinToneComboEmoji('🏇🏼')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect horse_racing', () => {
|
|
|
|
|
expect(isHorceRacingSkinToneComboEmoji('🏇')).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isPersonZwjEmoji', () => {
|
2017-06-02 08:52:27 +00:00
|
|
|
|
it('should gracefully handle empty string', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect couple_mm', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('👨❤️👨')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect couple_with_heart', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('💑')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect couplekiss', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('💏')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect family_mmb', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('👨👨👦')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect family_mwgb', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('👨👩👧👦')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect family', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('👪')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should detect kiss_ww', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('👩❤️💋👩')).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect girl', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('👧')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect girl_tone5', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('👧🏿')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect man', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('👨')).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('should not detect woman', () => {
|
|
|
|
|
expect(isPersonZwjEmoji('👩')).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isEmojiUnicodeSupported', () => {
|
2017-06-02 08:52:27 +00:00
|
|
|
|
it('should gracefully handle empty string with unicode support', () => {
|
2018-10-17 07:13:26 +00:00
|
|
|
|
const isSupported = isEmojiUnicodeSupported({ '1.0': true }, '', '1.0');
|
2018-10-09 18:03:09 +00:00
|
|
|
|
|
2017-06-02 08:52:27 +00:00
|
|
|
|
expect(isSupported).toBeTruthy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-06-02 08:52:27 +00:00
|
|
|
|
it('should gracefully handle empty string without unicode support', () => {
|
2018-10-17 07:13:26 +00:00
|
|
|
|
const isSupported = isEmojiUnicodeSupported({}, '', '1.0');
|
2018-10-09 18:03:09 +00:00
|
|
|
|
|
2017-06-02 08:52:27 +00:00
|
|
|
|
expect(isSupported).toBeFalsy();
|
|
|
|
|
});
|
2018-10-09 17:01:49 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
it('bomb(6.0) with 6.0 support', () => {
|
|
|
|
|
const emojiKey = 'bomb';
|
2020-05-07 21:09:26 +00:00
|
|
|
|
const unicodeSupportMap = { ...emptySupportMap, '6.0': true };
|
2017-02-28 04:44:34 +00:00
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
2019-03-14 09:18:18 +00:00
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
2017-02-28 04:44:34 +00:00
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
expect(isSupported).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('bomb(6.0) without 6.0 support', () => {
|
|
|
|
|
const emojiKey = 'bomb';
|
|
|
|
|
const unicodeSupportMap = emptySupportMap;
|
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
2019-03-14 09:18:18 +00:00
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
2017-02-28 04:44:34 +00:00
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
expect(isSupported).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('bomb(6.0) without 6.0 but with 9.0 support', () => {
|
|
|
|
|
const emojiKey = 'bomb';
|
2020-05-07 21:09:26 +00:00
|
|
|
|
const unicodeSupportMap = { ...emptySupportMap, '9.0': true };
|
2017-02-28 04:44:34 +00:00
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
2019-03-14 09:18:18 +00:00
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
2017-02-28 04:44:34 +00:00
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
expect(isSupported).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('construction_worker_tone5(8.0) without skin tone modifier support', () => {
|
|
|
|
|
const emojiKey = 'construction_worker_tone5';
|
2020-05-07 21:09:26 +00:00
|
|
|
|
const unicodeSupportMap = {
|
|
|
|
|
...emptySupportMap,
|
2017-02-28 04:44:34 +00:00
|
|
|
|
skinToneModifier: false,
|
|
|
|
|
'9.0': true,
|
|
|
|
|
'8.0': true,
|
|
|
|
|
'7.0': true,
|
|
|
|
|
6.1: true,
|
|
|
|
|
'6.0': true,
|
|
|
|
|
5.2: true,
|
|
|
|
|
5.1: true,
|
|
|
|
|
4.1: true,
|
|
|
|
|
'4.0': true,
|
|
|
|
|
3.2: true,
|
|
|
|
|
'3.0': true,
|
|
|
|
|
1.1: true,
|
2020-05-07 21:09:26 +00:00
|
|
|
|
};
|
2017-02-28 04:44:34 +00:00
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
2019-03-14 09:18:18 +00:00
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
2017-02-28 04:44:34 +00:00
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
expect(isSupported).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('use native keycap on >=57 chrome', () => {
|
|
|
|
|
const emojiKey = 'five';
|
2020-05-07 21:09:26 +00:00
|
|
|
|
const unicodeSupportMap = {
|
|
|
|
|
...emptySupportMap,
|
2017-02-28 04:44:34 +00:00
|
|
|
|
'3.0': true,
|
|
|
|
|
meta: {
|
|
|
|
|
isChrome: true,
|
|
|
|
|
chromeVersion: 57,
|
|
|
|
|
},
|
2020-05-07 21:09:26 +00:00
|
|
|
|
};
|
2017-02-28 04:44:34 +00:00
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
2019-03-14 09:18:18 +00:00
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
2017-02-28 04:44:34 +00:00
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
expect(isSupported).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fallback keycap on <57 chrome', () => {
|
|
|
|
|
const emojiKey = 'five';
|
2020-05-07 21:09:26 +00:00
|
|
|
|
const unicodeSupportMap = {
|
|
|
|
|
...emptySupportMap,
|
2017-02-28 04:44:34 +00:00
|
|
|
|
'3.0': true,
|
|
|
|
|
meta: {
|
|
|
|
|
isChrome: true,
|
|
|
|
|
chromeVersion: 50,
|
|
|
|
|
},
|
2020-05-07 21:09:26 +00:00
|
|
|
|
};
|
2017-02-28 04:44:34 +00:00
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
2019-03-14 09:18:18 +00:00
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
2017-02-28 04:44:34 +00:00
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
|
2017-02-28 04:44:34 +00:00
|
|
|
|
expect(isSupported).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-09-23 06:09:45 +00:00
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
describe('getEmojiInfo', () => {
|
|
|
|
|
it.each(['atom', 'five', 'black_heart'])("should return a correct emoji for '%s'", (name) => {
|
|
|
|
|
expect(getEmojiInfo(name)).toEqual(mockEmojiData[name]);
|
2020-10-16 12:09:33 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
it('should return fallback emoji by default', () => {
|
|
|
|
|
expect(getEmojiInfo('atjs')).toEqual(mockEmojiData.grey_question);
|
2020-10-13 09:08:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
it('should return null when fallback is false', () => {
|
|
|
|
|
expect(getEmojiInfo('atjs', false)).toBe(null);
|
2020-10-13 09:08:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
describe('when query is undefined', () => {
|
|
|
|
|
it('should return fallback emoji by default', () => {
|
|
|
|
|
expect(getEmojiInfo()).toEqual(mockEmojiData.grey_question);
|
2020-10-13 09:08:27 +00:00
|
|
|
|
});
|
2020-09-28 18:09:40 +00:00
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
it('should return null when fallback is false', () => {
|
|
|
|
|
expect(getEmojiInfo(undefined, false)).toBe(null);
|
2020-10-16 12:09:33 +00:00
|
|
|
|
});
|
2020-10-13 09:08:27 +00:00
|
|
|
|
});
|
2021-02-06 09:09:11 +00:00
|
|
|
|
});
|
2020-10-13 09:08:27 +00:00
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
describe('searchEmoji', () => {
|
|
|
|
|
const emojiFixture = Object.keys(mockEmojiData).reduce((acc, k) => {
|
|
|
|
|
const { name, e, u, d } = mockEmojiData[k];
|
|
|
|
|
acc[k] = { name, e, u, d };
|
|
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
it.each([undefined, null, ''])("should return all emoji when the input is '%s'", (input) => {
|
|
|
|
|
const search = searchEmoji(input);
|
|
|
|
|
|
|
|
|
|
const expected = [
|
|
|
|
|
'atom',
|
|
|
|
|
'bomb',
|
|
|
|
|
'construction_worker_tone5',
|
|
|
|
|
'five',
|
|
|
|
|
'grey_question',
|
|
|
|
|
'black_heart',
|
|
|
|
|
'heart',
|
|
|
|
|
'custard',
|
|
|
|
|
'star',
|
|
|
|
|
].map((name) => {
|
|
|
|
|
return {
|
|
|
|
|
emoji: emojiFixture[name],
|
|
|
|
|
field: 'd',
|
|
|
|
|
fieldValue: emojiFixture[name].d,
|
|
|
|
|
score: 0,
|
|
|
|
|
};
|
2020-10-13 09:08:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
expect(search).toEqual(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
|
[
|
|
|
|
|
'searching by unicode value',
|
|
|
|
|
'⚛',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'e',
|
|
|
|
|
fieldValue: 'atom',
|
|
|
|
|
score: 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching by partial alias',
|
|
|
|
|
'_symbol',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'alias',
|
|
|
|
|
fieldValue: 'atom_symbol',
|
|
|
|
|
score: 4,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching by full alias',
|
|
|
|
|
'atom_symbol',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'alias',
|
|
|
|
|
fieldValue: 'atom_symbol',
|
|
|
|
|
score: 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
])('should return a correct result when %s', (_, query, searchResult) => {
|
|
|
|
|
const expected = searchResult.map((item) => {
|
|
|
|
|
const { field, score, fieldValue, name } = item;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
emoji: emojiFixture[name],
|
|
|
|
|
field,
|
|
|
|
|
fieldValue,
|
|
|
|
|
score,
|
|
|
|
|
};
|
2020-10-13 09:08:27 +00:00
|
|
|
|
});
|
2020-09-23 06:09:45 +00:00
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
expect(searchEmoji(query)).toEqual(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
|
['searching with a non-existing emoji name', 'asdf', []],
|
|
|
|
|
[
|
|
|
|
|
'searching by full name',
|
|
|
|
|
'atom',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
'searching by full description',
|
|
|
|
|
'atom symbol',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
'searching by partial name',
|
|
|
|
|
'question',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'grey_question',
|
|
|
|
|
field: 'name',
|
|
|
|
|
score: 5,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching by partial description',
|
|
|
|
|
'ment',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'grey_question',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 24,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching with query "heart"',
|
|
|
|
|
'heart',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'black_heart',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 6,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'heart',
|
|
|
|
|
field: 'name',
|
|
|
|
|
score: 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching with query "HEART"',
|
|
|
|
|
'HEART',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'black_heart',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 6,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'heart',
|
|
|
|
|
field: 'name',
|
|
|
|
|
score: 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching with query "star"',
|
|
|
|
|
'star',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'custard',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 2,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'star',
|
|
|
|
|
field: 'name',
|
|
|
|
|
score: 0,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
])('should return a correct result when %s', (_, query, searchResult) => {
|
|
|
|
|
const expected = searchResult.map((item) => {
|
|
|
|
|
const { field, score, name } = item;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
emoji: emojiFixture[name],
|
|
|
|
|
field,
|
|
|
|
|
fieldValue: emojiFixture[name][field],
|
|
|
|
|
score,
|
|
|
|
|
};
|
2020-10-13 09:08:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-02-06 09:09:11 +00:00
|
|
|
|
expect(searchEmoji(query)).toEqual(expected);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('sortEmoji', () => {
|
|
|
|
|
const testCases = [
|
|
|
|
|
[
|
|
|
|
|
'should correctly sort by score',
|
|
|
|
|
[
|
|
|
|
|
{ score: 10, fieldValue: '', emoji: { name: 'a' } },
|
|
|
|
|
{ score: 5, fieldValue: '', emoji: { name: 'b' } },
|
|
|
|
|
{ score: 0, fieldValue: '', emoji: { name: 'c' } },
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
{ score: 0, fieldValue: '', emoji: { name: 'c' } },
|
|
|
|
|
{ score: 5, fieldValue: '', emoji: { name: 'b' } },
|
|
|
|
|
{ score: 10, fieldValue: '', emoji: { name: 'a' } },
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'should correctly sort by fieldValue',
|
|
|
|
|
[
|
|
|
|
|
{ score: 0, fieldValue: 'y', emoji: { name: 'b' } },
|
|
|
|
|
{ score: 0, fieldValue: 'x', emoji: { name: 'a' } },
|
|
|
|
|
{ score: 0, fieldValue: 'z', emoji: { name: 'c' } },
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
{ score: 0, fieldValue: 'x', emoji: { name: 'a' } },
|
|
|
|
|
{ score: 0, fieldValue: 'y', emoji: { name: 'b' } },
|
|
|
|
|
{ score: 0, fieldValue: 'z', emoji: { name: 'c' } },
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'should correctly sort by score and then by fieldValue (in order)',
|
|
|
|
|
[
|
|
|
|
|
{ score: 5, fieldValue: 'y', emoji: { name: 'c' } },
|
|
|
|
|
{ score: 0, fieldValue: 'z', emoji: { name: 'a' } },
|
|
|
|
|
{ score: 5, fieldValue: 'x', emoji: { name: 'b' } },
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
{ score: 0, fieldValue: 'z', emoji: { name: 'a' } },
|
|
|
|
|
{ score: 5, fieldValue: 'x', emoji: { name: 'b' } },
|
|
|
|
|
{ score: 5, fieldValue: 'y', emoji: { name: 'c' } },
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
it.each(testCases)('%s', (_, scoredItems, expected) => {
|
|
|
|
|
expect(sortEmoji(scoredItems)).toEqual(expected);
|
2020-10-13 09:08:27 +00:00
|
|
|
|
});
|
2020-09-23 06:09:45 +00:00
|
|
|
|
});
|
2017-02-28 04:44:34 +00:00
|
|
|
|
});
|