mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-24 17:38:40 +08:00
c05c429803
Co-authored-by: github-merge-queue <118344674+github-merge-queue@users.noreply.github.com> Co-authored-by: github-merge-queue <github-merge-queue@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Florian Duros <florian.duros@ormaz.fr> Co-authored-by: Kim Brose <kim.brose@nordeck.net> Co-authored-by: Florian Duros <florianduros@element.io> Co-authored-by: R Midhun Suresh <hi@midhun.dev> Co-authored-by: dbkr <986903+dbkr@users.noreply.github.com> Co-authored-by: ElementRobot <releases@riot.im> Co-authored-by: dbkr <dbkr@users.noreply.github.com> Co-authored-by: David Baker <dbkr@users.noreply.github.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Co-authored-by: David Langley <davidl@element.io> Co-authored-by: Michael Weimann <michaelw@matrix.org> Co-authored-by: Timshel <Timshel@users.noreply.github.com> Co-authored-by: Sahil Silare <32628578+sahil9001@users.noreply.github.com> Co-authored-by: Will Hunt <will@half-shot.uk> Co-authored-by: Hubert Chathi <hubert@uhoreg.ca> Co-authored-by: Andrew Ferrazzutti <andrewf@element.io> Co-authored-by: Robin <robin@robin.town> Co-authored-by: Tulir Asokan <tulir@maunium.net>
91 lines
3.5 KiB
TypeScript
91 lines
3.5 KiB
TypeScript
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
Copyright 2022 Ryan Browne <code@commonlawfeature.com>
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import EmojiProvider from "../../../src/autocomplete/EmojiProvider";
|
|
import { mkStubRoom } from "../../test-utils/test-utils";
|
|
import { add } from "../../../src/emojipicker/recent";
|
|
import { stubClient } from "../../test-utils";
|
|
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
|
|
|
const EMOJI_SHORTCODES = [
|
|
":+1",
|
|
":heart",
|
|
":grinning",
|
|
":hand",
|
|
":man",
|
|
":sweat",
|
|
":monkey",
|
|
":boat",
|
|
":mailbox",
|
|
":cop",
|
|
":bow",
|
|
":kiss",
|
|
":golf",
|
|
];
|
|
|
|
// Some emoji shortcodes are too short and do not actually trigger autocompletion until the ending `:`.
|
|
// This means that we cannot compare their autocompletion before and after the ending `:` and have
|
|
// to simply assert that the final completion with the colon is the exact emoji.
|
|
const TOO_SHORT_EMOJI_SHORTCODE = [{ emojiShortcode: ":o", expectedEmoji: "⭕️" }];
|
|
|
|
describe("EmojiProvider", function () {
|
|
const testRoom = mkStubRoom(undefined, undefined, undefined);
|
|
stubClient();
|
|
MatrixClientPeg.safeGet();
|
|
|
|
it.each(EMOJI_SHORTCODES)("Returns consistent results after final colon %s", async function (emojiShortcode) {
|
|
const ep = new EmojiProvider(testRoom);
|
|
const range = { beginning: true, start: 0, end: 3 };
|
|
const completionsBeforeColon = await ep.getCompletions(emojiShortcode, range);
|
|
const completionsAfterColon = await ep.getCompletions(emojiShortcode + ":", range);
|
|
|
|
const firstCompletionWithoutColon = completionsBeforeColon[0].completion;
|
|
const firstCompletionWithColon = completionsAfterColon[0].completion;
|
|
|
|
expect(firstCompletionWithoutColon).toEqual(firstCompletionWithColon);
|
|
});
|
|
|
|
it.each(TOO_SHORT_EMOJI_SHORTCODE)(
|
|
"Returns correct results after final colon $emojiShortcode",
|
|
async ({ emojiShortcode, expectedEmoji }) => {
|
|
const ep = new EmojiProvider(testRoom);
|
|
const range = { beginning: true, start: 0, end: 3 };
|
|
const completions = await ep.getCompletions(emojiShortcode + ":", range);
|
|
|
|
expect(completions[0].completion).toEqual(expectedEmoji);
|
|
},
|
|
);
|
|
|
|
it("Recently used emojis are correctly sorted", async function () {
|
|
add("😘"); //kissing_heart
|
|
add("💗"); //heartpulse
|
|
add("💗"); //heartpulse
|
|
add("😍"); //heart_eyes
|
|
|
|
const ep = new EmojiProvider(testRoom);
|
|
const completionsList = await ep.getCompletions(":heart", { beginning: true, start: 0, end: 6 });
|
|
expect(completionsList[0]?.component?.props.title).toEqual(":heartpulse:");
|
|
expect(completionsList[1]?.component?.props.title).toEqual(":heart_eyes:");
|
|
});
|
|
|
|
it("Exact match in recently used takes the lead", async function () {
|
|
add("😘"); //kissing_heart
|
|
add("💗"); //heartpulse
|
|
add("💗"); //heartpulse
|
|
add("😍"); //heart_eyes
|
|
|
|
add("❤️"); //heart
|
|
const ep = new EmojiProvider(testRoom);
|
|
const completionsList = await ep.getCompletions(":heart", { beginning: true, start: 0, end: 6 });
|
|
|
|
expect(completionsList[0]?.component?.props.title).toEqual(":heart:");
|
|
expect(completionsList[1]?.component?.props.title).toEqual(":heartpulse:");
|
|
expect(completionsList[2]?.component?.props.title).toEqual(":heart_eyes:");
|
|
});
|
|
});
|