2022-01-26 12:08:38 +05:30
|
|
|
|
import {
|
|
|
|
|
emojiFixtureMap,
|
|
|
|
|
mockEmojiData,
|
|
|
|
|
initEmojiMock,
|
|
|
|
|
validEmoji,
|
|
|
|
|
invalidEmoji,
|
|
|
|
|
clearEmojiMock,
|
|
|
|
|
} from 'helpers/emoji';
|
2020-10-24 23:57:45 +05:30
|
|
|
|
import { trimText } from 'helpers/text_helper';
|
2022-01-26 12:08:38 +05:30
|
|
|
|
import {
|
|
|
|
|
glEmojiTag,
|
|
|
|
|
searchEmoji,
|
|
|
|
|
getEmojiInfo,
|
|
|
|
|
sortEmoji,
|
|
|
|
|
initEmojiMap,
|
|
|
|
|
getAllEmoji,
|
|
|
|
|
} from '~/emoji';
|
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
|
import isEmojiUnicodeSupported, {
|
2017-08-17 22:00:37 +05:30
|
|
|
|
isFlagEmoji,
|
2018-03-17 18:26:18 +05:30
|
|
|
|
isRainbowFlagEmoji,
|
2017-08-17 22:00:37 +05:30
|
|
|
|
isKeycapEmoji,
|
|
|
|
|
isSkinToneComboEmoji,
|
|
|
|
|
isHorceRacingSkinToneComboEmoji,
|
|
|
|
|
isPersonZwjEmoji,
|
2017-09-10 17:25:29 +05:30
|
|
|
|
} from '~/emoji/support/is_emoji_unicode_supported';
|
2022-07-23 23:45:48 +05:30
|
|
|
|
import { NEUTRAL_INTENT_MULTIPLIER } from '~/emoji/constants';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
|
|
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-03-11 19:13:27 +05:30
|
|
|
|
describe('emoji', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
|
beforeEach(async () => {
|
2022-01-26 12:08:38 +05:30
|
|
|
|
await initEmojiMock();
|
2020-07-28 23:09:34 +05:30
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
2022-01-26 12:08:38 +05:30
|
|
|
|
clearEmojiMock();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('initEmojiMap', () => {
|
|
|
|
|
it('should contain valid emoji', async () => {
|
|
|
|
|
await initEmojiMap();
|
|
|
|
|
|
|
|
|
|
const allEmoji = Object.keys(getAllEmoji());
|
|
|
|
|
Object.keys(validEmoji).forEach((key) => {
|
|
|
|
|
expect(allEmoji.includes(key)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not contain invalid emoji', async () => {
|
|
|
|
|
await initEmojiMap();
|
|
|
|
|
|
|
|
|
|
const allEmoji = Object.keys(getAllEmoji());
|
|
|
|
|
Object.keys(invalidEmoji).forEach((key) => {
|
|
|
|
|
expect(allEmoji.includes(key)).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fixes broken pride emoji', async () => {
|
|
|
|
|
clearEmojiMock();
|
|
|
|
|
await initEmojiMock({
|
|
|
|
|
gay_pride_flag: {
|
|
|
|
|
c: 'flags',
|
|
|
|
|
// Without a zero-width joiner
|
|
|
|
|
e: '🏳🌈',
|
|
|
|
|
name: 'gay_pride_flag',
|
|
|
|
|
u: '6.0',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(getAllEmoji()).toEqual({
|
|
|
|
|
gay_pride_flag: {
|
|
|
|
|
c: 'flags',
|
|
|
|
|
// With a zero-width joiner
|
|
|
|
|
e: '🏳️🌈',
|
|
|
|
|
name: 'gay_pride_flag',
|
|
|
|
|
u: '6.0',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
|
|
describe('glEmojiTag', () => {
|
|
|
|
|
it('bomb emoji', () => {
|
|
|
|
|
const emojiKey = 'bomb';
|
2021-03-11 19:13:27 +05:30
|
|
|
|
const markup = glEmojiTag(emojiKey);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
|
expect(trimText(markup)).toMatchInlineSnapshot(
|
|
|
|
|
`"<gl-emoji data-name=\\"bomb\\"></gl-emoji>"`,
|
2017-08-17 22:00:37 +05:30
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('bomb emoji with sprite fallback readiness', () => {
|
|
|
|
|
const emojiKey = 'bomb';
|
2021-03-11 19:13:27 +05:30
|
|
|
|
const markup = glEmojiTag(emojiKey, {
|
2017-08-17 22:00:37 +05:30
|
|
|
|
sprite: true,
|
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
expect(trimText(markup)).toMatchInlineSnapshot(
|
|
|
|
|
`"<gl-emoji data-fallback-sprite-class=\\"emoji-bomb\\" data-name=\\"bomb\\"></gl-emoji>"`,
|
2017-08-17 22:00:37 +05:30
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isFlagEmoji', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
|
it('should gracefully handle empty string', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isFlagEmoji('')).toBe(false);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect flag_ac', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isFlagEmoji('🇦🇨')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect flag_us', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isFlagEmoji('🇺🇸')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect flag_zw', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isFlagEmoji('🇿🇼')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect flags', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isFlagEmoji('🎏')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect triangular_flag_on_post', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isFlagEmoji('🚩')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect single letter', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isFlagEmoji('🇦')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect >2 letters', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isFlagEmoji('🇦🇧🇨')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
|
describe('isRainbowFlagEmoji', () => {
|
|
|
|
|
it('should gracefully handle empty string', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isRainbowFlagEmoji('')).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
|
it('should detect rainbow_flag', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isRainbowFlagEmoji('🏳🌈')).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
|
|
it("should not detect flag_white on its' own", () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isRainbowFlagEmoji('🏳')).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
|
|
it("should not detect rainbow on its' own", () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isRainbowFlagEmoji('🌈')).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
|
it('should not detect flag_white with something else', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isRainbowFlagEmoji('🏳🔵')).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
describe('isKeycapEmoji', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
|
it('should gracefully handle empty string', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isKeycapEmoji('')).toBe(false);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect one(keycap)', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isKeycapEmoji('1️⃣')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect nine(keycap)', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isKeycapEmoji('9️⃣')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect ten(keycap)', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isKeycapEmoji('🔟')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect hash(keycap)', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isKeycapEmoji('#⃣')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isSkinToneComboEmoji', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
|
it('should gracefully handle empty string', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSkinToneComboEmoji('')).toBe(false);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect hand_splayed_tone5', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSkinToneComboEmoji('🖐🏿')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect hand_splayed', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSkinToneComboEmoji('🖐')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect lifter_tone1', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSkinToneComboEmoji('🏋🏻')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect lifter', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSkinToneComboEmoji('🏋')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect rowboat_tone4', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSkinToneComboEmoji('🚣🏾')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect rowboat', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSkinToneComboEmoji('🚣')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect individual tone emoji', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSkinToneComboEmoji('🏻')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isHorceRacingSkinToneComboEmoji', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
|
it('should gracefully handle empty string', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isHorceRacingSkinToneComboEmoji('')).toBeUndefined();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect horse_racing_tone2', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isHorceRacingSkinToneComboEmoji('🏇🏼')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect horse_racing', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isHorceRacingSkinToneComboEmoji('🏇')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isPersonZwjEmoji', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
|
it('should gracefully handle empty string', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('')).toBe(false);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect couple_mm', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('👨❤️👨')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect couple_with_heart', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('💑')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect couplekiss', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('💏')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect family_mmb', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('👨👨👦')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect family_mwgb', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('👨👩👧👦')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect family', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('👪')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should detect kiss_ww', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('👩❤️💋👩')).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect girl', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('👧')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect girl_tone5', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('👧🏿')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect man', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('👨')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('should not detect woman', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isPersonZwjEmoji('👩')).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('isEmojiUnicodeSupported', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
|
it('should gracefully handle empty string with unicode support', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
|
const isSupported = isEmojiUnicodeSupported({ '1.0': true }, '', '1.0');
|
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSupported).toBe(true);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
|
it('should gracefully handle empty string without unicode support', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
|
const isSupported = isEmojiUnicodeSupported({}, '', '1.0');
|
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSupported).toBeUndefined();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
|
it('bomb(6.0) with 6.0 support', () => {
|
|
|
|
|
const emojiKey = 'bomb';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
const unicodeSupportMap = { ...emptySupportMap, '6.0': true };
|
2017-08-17 22:00:37 +05:30
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSupported).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('bomb(6.0) without 6.0 support', () => {
|
|
|
|
|
const emojiKey = 'bomb';
|
|
|
|
|
const unicodeSupportMap = emptySupportMap;
|
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSupported).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('bomb(6.0) without 6.0 but with 9.0 support', () => {
|
|
|
|
|
const emojiKey = 'bomb';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
const unicodeSupportMap = { ...emptySupportMap, '9.0': true };
|
2017-08-17 22:00:37 +05:30
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSupported).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('construction_worker_tone5(8.0) without skin tone modifier support', () => {
|
|
|
|
|
const emojiKey = 'construction_worker_tone5';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
const unicodeSupportMap = {
|
|
|
|
|
...emptySupportMap,
|
2017-08-17 22:00:37 +05:30
|
|
|
|
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-24 23:13:21 +05:30
|
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSupported).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('use native keycap on >=57 chrome', () => {
|
|
|
|
|
const emojiKey = 'five';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
const unicodeSupportMap = {
|
|
|
|
|
...emptySupportMap,
|
2017-08-17 22:00:37 +05:30
|
|
|
|
'3.0': true,
|
|
|
|
|
meta: {
|
|
|
|
|
isChrome: true,
|
|
|
|
|
chromeVersion: 57,
|
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSupported).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('fallback keycap on <57 chrome', () => {
|
|
|
|
|
const emojiKey = 'five';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
const unicodeSupportMap = {
|
|
|
|
|
...emptySupportMap,
|
2017-08-17 22:00:37 +05:30
|
|
|
|
'3.0': true,
|
|
|
|
|
meta: {
|
|
|
|
|
isChrome: true,
|
|
|
|
|
chromeVersion: 50,
|
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
const isSupported = isEmojiUnicodeSupported(
|
|
|
|
|
unicodeSupportMap,
|
|
|
|
|
emojiFixtureMap[emojiKey].moji,
|
|
|
|
|
emojiFixtureMap[emojiKey].unicodeVersion,
|
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
|
expect(isSupported).toBe(false);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
|
describe('getEmojiInfo', () => {
|
|
|
|
|
it.each(['atom', 'five', 'black_heart'])("should return a correct emoji for '%s'", (name) => {
|
|
|
|
|
expect(getEmojiInfo(name)).toEqual(mockEmojiData[name]);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
});
|
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
|
it('should return fallback emoji by default', () => {
|
|
|
|
|
expect(getEmojiInfo('atjs')).toEqual(mockEmojiData.grey_question);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
});
|
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
|
it('should return null when fallback is false', () => {
|
|
|
|
|
expect(getEmojiInfo('atjs', false)).toBe(null);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
});
|
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
|
describe('when query is undefined', () => {
|
|
|
|
|
it('should return fallback emoji by default', () => {
|
|
|
|
|
expect(getEmojiInfo()).toEqual(mockEmojiData.grey_question);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
});
|
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
|
it('should return null when fallback is false', () => {
|
|
|
|
|
expect(getEmojiInfo(undefined, false)).toBe(null);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
|
describe('searchEmoji', () => {
|
|
|
|
|
it.each([undefined, null, ''])("should return all emoji when the input is '%s'", (input) => {
|
|
|
|
|
const search = searchEmoji(input);
|
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
|
const expected = Object.keys(validEmoji)
|
|
|
|
|
.map((name) => {
|
|
|
|
|
let score = NEUTRAL_INTENT_MULTIPLIER;
|
|
|
|
|
|
|
|
|
|
// Positive intent value retrieved from ~/emoji/intents.json
|
|
|
|
|
if (name === 'thumbsup') {
|
|
|
|
|
score = 0.5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Negative intent value retrieved from ~/emoji/intents.json
|
|
|
|
|
if (name === 'thumbsdown') {
|
|
|
|
|
score = 1.5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
emoji: mockEmojiData[name],
|
|
|
|
|
field: 'd',
|
|
|
|
|
fieldValue: mockEmojiData[name].d,
|
|
|
|
|
score,
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
.sort(sortEmoji);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
|
expect(search).toEqual(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
|
[
|
|
|
|
|
'searching by unicode value',
|
|
|
|
|
'⚛',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'e',
|
|
|
|
|
fieldValue: 'atom',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: NEUTRAL_INTENT_MULTIPLIER,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching by partial alias',
|
|
|
|
|
'_symbol',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'alias',
|
|
|
|
|
fieldValue: 'atom_symbol',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: 16,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching by full alias',
|
|
|
|
|
'atom_symbol',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'alias',
|
|
|
|
|
fieldValue: 'atom_symbol',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: NEUTRAL_INTENT_MULTIPLIER,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
])('should return a correct result when %s', (_, query, searchResult) => {
|
|
|
|
|
const expected = searchResult.map((item) => {
|
|
|
|
|
const { field, score, fieldValue, name } = item;
|
|
|
|
|
|
|
|
|
|
return {
|
2022-01-26 12:08:38 +05:30
|
|
|
|
emoji: mockEmojiData[name],
|
2021-03-11 19:13:27 +05:30
|
|
|
|
field,
|
|
|
|
|
fieldValue,
|
|
|
|
|
score,
|
|
|
|
|
};
|
2021-01-03 14:25:43 +05:30
|
|
|
|
});
|
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
|
expect(searchEmoji(query)).toEqual(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
|
['searching with a non-existing emoji name', 'asdf', []],
|
|
|
|
|
[
|
|
|
|
|
'searching by full name',
|
|
|
|
|
'atom',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'd',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: NEUTRAL_INTENT_MULTIPLIER,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
'searching by full description',
|
|
|
|
|
'atom symbol',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'atom',
|
|
|
|
|
field: 'd',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: NEUTRAL_INTENT_MULTIPLIER,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
'searching by partial name',
|
|
|
|
|
'question',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'grey_question',
|
|
|
|
|
field: 'name',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: 32,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching by partial description',
|
|
|
|
|
'ment',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'grey_question',
|
|
|
|
|
field: 'd',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: 16777216,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching with query "heart"',
|
|
|
|
|
'heart',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'heart',
|
|
|
|
|
field: 'name',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: NEUTRAL_INTENT_MULTIPLIER,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'black_heart',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 64,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching with query "HEART"',
|
|
|
|
|
'HEART',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'heart',
|
|
|
|
|
field: 'name',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: NEUTRAL_INTENT_MULTIPLIER,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'black_heart',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 64,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching with query "star"',
|
|
|
|
|
'star',
|
|
|
|
|
[
|
2022-07-23 23:45:48 +05:30
|
|
|
|
{
|
|
|
|
|
name: 'star',
|
|
|
|
|
field: 'name',
|
|
|
|
|
score: NEUTRAL_INTENT_MULTIPLIER,
|
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
|
{
|
|
|
|
|
name: 'custard',
|
|
|
|
|
field: 'd',
|
2022-07-23 23:45:48 +05:30
|
|
|
|
score: 4,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'searching for emoji with intentions assigned',
|
|
|
|
|
'thumbs',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
name: 'thumbsup',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 0.5,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
{
|
2022-07-23 23:45:48 +05:30
|
|
|
|
name: 'thumbsdown',
|
|
|
|
|
field: 'd',
|
|
|
|
|
score: 1.5,
|
2021-03-11 19:13:27 +05:30
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
])('should return a correct result when %s', (_, query, searchResult) => {
|
|
|
|
|
const expected = searchResult.map((item) => {
|
|
|
|
|
const { field, score, name } = item;
|
|
|
|
|
|
|
|
|
|
return {
|
2022-01-26 12:08:38 +05:30
|
|
|
|
emoji: mockEmojiData[name],
|
2021-03-11 19:13:27 +05:30
|
|
|
|
field,
|
2022-01-26 12:08:38 +05:30
|
|
|
|
fieldValue: mockEmojiData[name][field],
|
2021-03-11 19:13:27 +05:30
|
|
|
|
score,
|
|
|
|
|
};
|
2021-01-03 14:25:43 +05:30
|
|
|
|
});
|
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
|
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' } },
|
2022-07-23 23:45:48 +05:30
|
|
|
|
{ score: 1, fieldValue: '', emoji: { name: 'c' } },
|
2021-03-11 19:13:27 +05:30
|
|
|
|
],
|
|
|
|
|
[
|
2022-07-23 23:45:48 +05:30
|
|
|
|
{ score: 1, fieldValue: '', emoji: { name: 'c' } },
|
2021-03-11 19:13:27 +05:30
|
|
|
|
{ score: 5, fieldValue: '', emoji: { name: 'b' } },
|
|
|
|
|
{ score: 10, fieldValue: '', emoji: { name: 'a' } },
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'should correctly sort by fieldValue',
|
|
|
|
|
[
|
2022-07-23 23:45:48 +05:30
|
|
|
|
{ score: 1, fieldValue: 'y', emoji: { name: 'b' } },
|
|
|
|
|
{ score: 1, fieldValue: 'x', emoji: { name: 'a' } },
|
|
|
|
|
{ score: 1, fieldValue: 'z', emoji: { name: 'c' } },
|
2021-03-11 19:13:27 +05:30
|
|
|
|
],
|
|
|
|
|
[
|
2022-07-23 23:45:48 +05:30
|
|
|
|
{ score: 1, fieldValue: 'x', emoji: { name: 'a' } },
|
|
|
|
|
{ score: 1, fieldValue: 'y', emoji: { name: 'b' } },
|
|
|
|
|
{ score: 1, fieldValue: 'z', emoji: { name: 'c' } },
|
2021-03-11 19:13:27 +05:30
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'should correctly sort by score and then by fieldValue (in order)',
|
|
|
|
|
[
|
|
|
|
|
{ score: 5, fieldValue: 'y', emoji: { name: 'c' } },
|
2022-07-23 23:45:48 +05:30
|
|
|
|
{ score: 1, fieldValue: 'z', emoji: { name: 'a' } },
|
2021-03-11 19:13:27 +05:30
|
|
|
|
{ score: 5, fieldValue: 'x', emoji: { name: 'b' } },
|
|
|
|
|
],
|
|
|
|
|
[
|
2022-07-23 23:45:48 +05:30
|
|
|
|
{ score: 1, fieldValue: 'z', emoji: { name: 'a' } },
|
2021-03-11 19:13:27 +05:30
|
|
|
|
{ score: 5, fieldValue: 'x', emoji: { name: 'b' } },
|
|
|
|
|
{ score: 5, fieldValue: 'y', emoji: { name: 'c' } },
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
it.each(testCases)('%s', (_, scoredItems, expected) => {
|
2022-07-23 23:45:48 +05:30
|
|
|
|
expect(scoredItems.sort(sortEmoji)).toEqual(expected);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
});
|
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
});
|