| 1 | import path from 'node:path'; |
| 2 | import { EMOJI, type Emoji, FEMALE, flattenEmojiData, MALE, TEXT } from 'emojibase'; |
| 3 | |
| 4 | const localeCache: Record<string, Emoji[]> = {}; |
| 5 | |
| 6 | function loadFlatEmojiData(): Emoji[] { |
| 7 | const locale = process.env.TEST_LOCALE ?? 'en'; |
| 8 | |
| 9 | if (localeCache[locale]) { |
| 10 | return localeCache[locale]; |
| 11 | } |
| 12 | |
| 13 | localeCache[locale] = flattenEmojiData( |
| 14 | require(path.join(__dirname, '..', locale, 'data.raw.json')), |
| 15 | ); |
| 16 | |
| 17 | return localeCache[locale]; |
| 18 | } |
| 19 | |
| 20 | describe('data', () => { |
| 21 | // Skin modifications and certain sequences are missing specific |
| 22 | // fields, like tags, annotations, and more. And since we flattened |
| 23 | // our data, we'll need to wrap tests in conditional blocks. |
| 24 | loadFlatEmojiData().forEach((emoji) => { |
| 25 | const { hexcode } = emoji; |
| 26 | const unicode = emoji.emoji || emoji.text; |
| 27 | |
| 28 | if ('group' in emoji) { |
| 29 | it(`defines a group for ${unicode} (${hexcode})`, () => { |
| 30 | expect(emoji.group).toBeGreaterThanOrEqual(0); |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | if ('subgroup' in emoji) { |
| 35 | it(`defines a subgroup for ${unicode} (${hexcode})`, () => { |
| 36 | expect(emoji.subgroup).toBeGreaterThanOrEqual(0); |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | if ('order' in emoji) { |
| 41 | it(`defines an order for ${unicode} (${hexcode})`, () => { |
| 42 | expect(emoji.order).toBeGreaterThanOrEqual(0); |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | it(`defines an emoji version for ${unicode} (${hexcode})`, () => { |
| 47 | expect(emoji.version).toBeDefined(); |
| 48 | }); |
| 49 | |
| 50 | it(`defines a type presentation for ${unicode} (${hexcode})`, () => { |
| 51 | // @ts-expect-error Missing expect |
| 52 | expect(emoji.type).toBeOneOf([EMOJI, TEXT]); |
| 53 | }); |
| 54 | |
| 55 | if ('label' in emoji) { |
| 56 | it(`defines an label for ${unicode} (${hexcode})`, () => { |
| 57 | expect(emoji.label).not.toBe(''); |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | if ('tags' in emoji) { |
| 62 | it(`defines tags for ${unicode} (${hexcode})`, () => { |
| 63 | expect(emoji.tags?.length).toBeGreaterThanOrEqual(1); |
| 64 | |
| 65 | emoji.tags?.forEach((tag) => { |
| 66 | expect(tag).not.toBe(''); |
| 67 | }); |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | if ('gender' in emoji) { |
| 72 | it(`defines a gender for ${unicode} (${hexcode})`, () => { |
| 73 | // @ts-expect-error Missing expect |
| 74 | expect(emoji.gender).toBeOneOf([MALE, FEMALE]); |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | if ('skins' in emoji) { |
| 79 | it(`defines skin modifications for ${unicode} (${hexcode})`, () => { |
| 80 | expect(emoji.skins).toHaveLength(5); |
| 81 | }); |
| 82 | } |
| 83 | }); |
| 84 | }); |