Skip to content

Commit

Permalink
test case
Browse files Browse the repository at this point in the history
  • Loading branch information
cungminh2710 committed Oct 17, 2023
1 parent e174d20 commit 1e6bf17
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 46 deletions.
106 changes: 61 additions & 45 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { type Emoji, getAllEmojis, hasEmoji, compareVersion, stripEmojies, filterEmojis, getAllComponents, extractEmojis, getEmojisByGroup, isValidEmojiVersion } from '../';
import {
type Emoji,
getAllEmojis,
hasEmoji,
compareVersion,
stripEmojies,
filterEmojis,
getAllComponents,
extractEmojis,
getEmojisByGroup,
isValidEmojiVersion,
} from '../';
import unicodeEmojis from '../unicode-emojis';

const ztring = 'adfsadfs safdsaf dsafds ';
Expand All @@ -8,72 +19,77 @@ const testCases = ['🫶', '👋🏼', '🙏🏿', '👨🏻‍🤝‍👨🏼',
const testEmojis: Array<Emoji> = testCases.map<Emoji>((e) => ({ emoji: e, version: '1.0', group: 'test' }));

test('hasEmoji', () => {
expect(hasEmoji(ztring)).toBe(false);
expect(hasEmoji(ztringWithEmoji)).toBe(true);
expect(hasEmoji(ztring)).toBe(false);
expect(hasEmoji(ztringWithEmoji)).toBe(true);
});

test('stripEmojis', () => {
expect(stripEmojies(ztring)).toBe(ztring);
expect(stripEmojies(ztringWithEmoji)).toBe(ztring);
expect(stripEmojies(ztring)).toBe(ztring);
expect(stripEmojies(ztringWithEmoji)).toBe(ztring);
});

test('extractEmojis', () => {
expect(extractEmojis(ztring)).toEqual([]);
expect(extractEmojis(ztringWithEmoji)).toEqual(['👋🏼', '🫶']);
})
expect(extractEmojis(ztring)).toEqual([]);
expect(extractEmojis(ztringWithEmoji)).toEqual(['👋🏼', '🫶']);
});

test('getAllEmojis', () => {
expect(getAllEmojis(testEmojis)).toEqual(testCases);
expect(getAllEmojis(testEmojis).includes('🧑🏿‍🤝‍🧑🏿')).toBe(false);
expect(getAllEmojis(testEmojis)).toEqual(testCases);
expect(getAllEmojis(testEmojis).includes('🧑🏿‍🤝‍🧑🏿')).toBe(false);

const allEmojis = getAllEmojis();
const allEmojis = getAllEmojis();

for (const testCase of testCases) {
expect(allEmojis.includes(testCase)).toBe(true);
}
for (const testCase of testCases) {
expect(allEmojis.includes(testCase)).toBe(true);
}
});

test('filterEmojis', () => {
expect(filterEmojis('1.0', false, testEmojis)).toEqual(testEmojis);
expect(filterEmojis('1.0', true, testEmojis)).toEqual(testEmojis);
expect(getAllEmojis(filterEmojis('1.0', true)).includes('😂')).toBe(false); // v0.6
expect(getAllEmojis(filterEmojis('1.0', true)).includes('👨🏻‍🤝‍👨🏽')).toBe(false); // v12.1
expect(getAllEmojis(filterEmojis('1.0')).includes('😂')).toBe(true);
expect(getAllEmojis(filterEmojis('1.0')).includes('👨🏻‍🤝‍👨🏽')).toBe(false);
expect(filterEmojis('1.0', false, testEmojis)).toEqual(testEmojis);
expect(filterEmojis('1.0', true, testEmojis)).toEqual(testEmojis);
expect(getAllEmojis(filterEmojis('1.0', true)).includes('😂')).toBe(false); // v0.6
expect(getAllEmojis(filterEmojis('1.0', true)).includes('👨🏻‍🤝‍👨🏽')).toBe(false); // v12.1
expect(getAllEmojis(filterEmojis('15.1', true)).includes('🙂‍↔️')).toBe(false); // v15.1 - head shaking
expect(getAllEmojis(filterEmojis('1.0')).includes('😂')).toBe(true);
expect(getAllEmojis(filterEmojis('1.0')).includes('👨🏻‍🤝‍👨🏽')).toBe(false);
});

test('getEmojisByGroup', () => {
getEmojisByGroup('group', testEmojis).forEach((emojis, key) => expect(emojis.every(emoji => emoji.group === key)).toBe(true));
getEmojisByGroup('group', testEmojis).forEach((emojis, key) =>
expect(emojis.every((emoji) => emoji.group === key)).toBe(true)
);

const emojisByGroup = getEmojisByGroup('group');
emojisByGroup.forEach((emojis, key) => expect(emojis.every(emoji => emoji.group === key)).toBe(true));
const emojisByGroup = getEmojisByGroup('group');
emojisByGroup.forEach((emojis, key) => expect(emojis.every((emoji) => emoji.group === key)).toBe(true));

const emojisByCategory = getEmojisByGroup('category');
emojisByCategory.forEach((emojis, key) => expect(emojis.every(emoji => emoji.category === key)).toBe(true));
const emojisByCategory = getEmojisByGroup('category');
emojisByCategory.forEach((emojis, key) => expect(emojis.every((emoji) => emoji.category === key)).toBe(true));

const emojisBySubgroup = getEmojisByGroup('subgroup');
emojisBySubgroup.forEach((emojis, key) => expect(emojis.every(emoji => emoji.subgroup === key)).toBe(true));
})
const emojisBySubgroup = getEmojisByGroup('subgroup');
emojisBySubgroup.forEach((emojis, key) => expect(emojis.every((emoji) => emoji.subgroup === key)).toBe(true));
});

test('getAllComponents', () => {
expect(getAllComponents()).toEqual(unicodeEmojis.components);
})
expect(getAllComponents()).toEqual(unicodeEmojis.components);
});

test('compareVersion', () => {
expect(compareVersion('0.6', '0.6')).toBe(true);
expect(compareVersion('0.6', '0.6', true)).toBe(true);
expect(compareVersion('0.6', '1.0', true)).toBe(false);
expect(compareVersion('0.6', '12.0')).toBe(true);
expect(compareVersion('12.0', '11.0')).toBe(false);
})
expect(compareVersion('0.6', '0.6')).toBe(true);
expect(compareVersion('0.6', '0.6', true)).toBe(true);
expect(compareVersion('0.6', '1.0', true)).toBe(false);
expect(compareVersion('0.6', '12.0')).toBe(true);
expect(compareVersion('12.0', '11.0')).toBe(false);
expect(compareVersion('12.0', '15.1')).toBe(true);
});

test('isValidEmojiVersion', () => {
expect(isValidEmojiVersion(null)).toBe(false);
expect(isValidEmojiVersion(1)).toBe(false);
expect(isValidEmojiVersion("")).toBe(false);
expect(isValidEmojiVersion("abc")).toBe(false);
expect(isValidEmojiVersion("1.0")).toBe(true);
expect(isValidEmojiVersion("2.0")).toBe(true);
expect(isValidEmojiVersion("14.0")).toBe(true);
expect(isValidEmojiVersion("15.0")).toBe(true);
})
expect(isValidEmojiVersion(null)).toBe(false);
expect(isValidEmojiVersion(1)).toBe(false);
expect(isValidEmojiVersion('')).toBe(false);
expect(isValidEmojiVersion('abc')).toBe(false);
expect(isValidEmojiVersion('1.0')).toBe(true);
expect(isValidEmojiVersion('2.0')).toBe(true);
expect(isValidEmojiVersion('14.0')).toBe(true);
expect(isValidEmojiVersion('15.0')).toBe(true);
expect(isValidEmojiVersion('15.1')).toBe(true);
});
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export function isValidEmojiVersion(version: any): version is EmojiVersion {
version === '13.0' ||
version === '13.1' ||
version === '14.0' ||
version === '15.0'
version === '15.0' ||
version === '15.1'
);
}

Expand Down

0 comments on commit 1e6bf17

Please sign in to comment.