File
Blob: tests/shared/emoji.test.ts
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { buildEmojiAssetUrl, getEmojiAsset, getEmojiAssetUrl, normalizeEmoji } from "@/shared/emoji"; |
| 3 | |
| 4 | describe("shared emoji helpers", () => { |
| 5 | it("strips Unicode variation selectors (FE0E / FE0F) so glyph keys match the asset map", () => { |
| 6 | // Variation selector 16 normalizes to the bare base glyph. |
| 7 | expect(normalizeEmoji("❤️")).toBe("❤"); |
| 8 | expect(normalizeEmoji("❤︎")).toBe("❤"); |
| 9 | expect(normalizeEmoji("❤")).toBe("❤"); |
| 10 | }); |
| 11 | |
| 12 | it("builds the Apple CDN asset URL from a filename", () => { |
| 13 | expect(buildEmojiAssetUrl("1f604.png")).toBe( |
| 14 | "https://cdn.jsdelivr.net/npm/emoji-datasource-apple/img/apple/64/1f604.png", |
| 15 | ); |
| 16 | }); |
| 17 | |
| 18 | it("resolves common emoji glyphs to Apple asset filenames", () => { |
| 19 | expect(getEmojiAsset("\u{1F604}")).toMatch(/^1f604\.png$/); |
| 20 | expect(getEmojiAsset("\u{1F44D}")).toBeTruthy(); // thumbs up |
| 21 | }); |
| 22 | |
| 23 | it("resolves common emoji glyphs to absolute Apple CDN URLs", () => { |
| 24 | const url = getEmojiAssetUrl("\u{1F604}"); |
| 25 | expect(url).toBe("https://cdn.jsdelivr.net/npm/emoji-datasource-apple/img/apple/64/1f604.png"); |
| 26 | }); |
| 27 | |
| 28 | it("returns null for non-emoji strings (the helper is glyph-based, not shortcode-based)", () => { |
| 29 | expect(getEmojiAssetUrl("smile")).toBeNull(); |
| 30 | expect(getEmojiAssetUrl("")).toBeNull(); |
| 31 | expect(getEmojiAssetUrl("not an emoji")).toBeNull(); |
| 32 | }); |
| 33 | |
| 34 | it("derives an asset filename for skin-tone-modified emoji from their code points", () => { |
| 35 | // thumbs up + medium skin tone => combined code points hex-joined |
| 36 | const url = getEmojiAssetUrl("\u{1F44D}\u{1F3FD}"); |
| 37 | expect(url).toMatch(/1f44d-1f3fd\.png$/); |
| 38 | }); |
| 39 | }); |