Skip to content

armgit / ente

Public Imported from GitHub
0

๐Ÿ’š End-to-end encrypted cloud for everything.

3.3 KB
Raw Blame
import { describe, expect, test } from "vitest";
import {
    emojiName,
    emojiWithSkinTone,
    quickReactionEmojis,
    searchEmojis,
    spaceEmojis,
} from "../src/data/emojis";

describe("quick reactions", () => {
    test("keeps the defaults when no reaction is selected", () => {
        expect(quickReactionEmojis()).toEqual([
            "โค๏ธ",
            "๐Ÿ˜‚",
            "๐Ÿ˜ฎ",
            "๐Ÿ˜ข",
            "๐Ÿ™",
            "๐Ÿ‘",
        ]);
    });

    test.each(["โค๏ธ", "๐Ÿ˜‚", "๐Ÿ˜ฎ", "๐Ÿ˜ข", "๐Ÿ™", "๐Ÿ‘"])(
        "keeps selected default %s in its usual slot",
        (selected) => {
            expect(quickReactionEmojis(selected)).toEqual([
                "โค๏ธ",
                "๐Ÿ˜‚",
                "๐Ÿ˜ฎ",
                "๐Ÿ˜ข",
                "๐Ÿ™",
                "๐Ÿ‘",
            ]);
        },
    );

    test.each(["๐Ÿ”ฅ", "๐Ÿชฟ"])(
        "includes a selected %s outside the defaults",
        (selected) => {
            expect(quickReactionEmojis(selected)).toEqual([
                "โค๏ธ",
                "๐Ÿ˜‚",
                "๐Ÿ˜ฎ",
                "๐Ÿ˜ข",
                "๐Ÿ™",
                selected,
            ]);
        },
    );

    test("preserves skin tones and the selected variant's usual slot", () => {
        expect(quickReactionEmojis("๐Ÿ™๐Ÿฝ")).toEqual([
            "โค๏ธ",
            "๐Ÿ˜‚",
            "๐Ÿ˜ฎ",
            "๐Ÿ˜ข",
            "๐Ÿ™๐Ÿฝ",
            "๐Ÿ‘๐Ÿฝ",
        ]);
    });
});

describe("emoji search", () => {
    test("finds aliases, multiple words and literal toned emoji", () => {
        expect(
            searchEmojis(spaceEmojis, " LOL ").map((item) => item.emoji),
        ).toContain("๐Ÿ˜‚");
        expect(
            searchEmojis(spaceEmojis, "blue heart").map((item) => item.emoji),
        ).toEqual(["๐Ÿ’™", "๐Ÿฉต"]);
        expect(
            searchEmojis(spaceEmojis, "๐Ÿ‘๐Ÿฝ").map((item) => item.emoji),
        ).toEqual(["๐Ÿ‘"]);
        expect(searchEmojis(spaceEmojis, "no-such-emoji")).toEqual([]);
    });

    test("inserts tones before joined professions and drops the text selector", () => {
        const peace = spaceEmojis.find((entry) => entry.emoji == "โœŒ๏ธ")!;
        const developer = spaceEmojis.find((entry) => entry.emoji == "๐Ÿง‘โ€๐Ÿ’ป")!;
        expect(emojiWithSkinTone(peace, "๐Ÿฝ")).toBe("โœŒ๐Ÿฝ");
        expect(emojiWithSkinTone(developer, "๐Ÿฟ")).toBe("๐Ÿง‘๐Ÿฟโ€๐Ÿ’ป");
        expect(emojiName("๐Ÿง‘๐Ÿฟโ€๐Ÿ’ป")).toBe("Developer");
        expect(
            emojiWithSkinTone(
                spaceEmojis.find((entry) => entry.emoji == "โค๏ธ")!,
                "๐Ÿฝ",
            ),
        ).toBe("โค๏ธ");
    });

    test("catalog entries and all tone variants contain a single grapheme", () => {
        const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
        expect(new Set(spaceEmojis.map((entry) => entry.emoji)).size).toBe(
            spaceEmojis.length,
        );
        for (const entry of spaceEmojis) {
            for (const tone of ["", "๐Ÿป", "๐Ÿผ", "๐Ÿฝ", "๐Ÿพ", "๐Ÿฟ"]) {
                expect(
                    [...segmenter.segment(emojiWithSkinTone(entry, tone))],
                    entry.name,
                ).toHaveLength(1);
            }
        }
    });
});