You've already forked element-web
mirror of
https://github.com/element-hq/element-web.git
synced 2025-08-06 16:22:46 +03:00
* Update react monorepo to v19 * Import JSX explicitly for React 19 compatibility Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update usages of refs for React 19 compatibility Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update react imports Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Avoid legacy contexts as much as possible Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Avoid deprecated React symbols Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Stash Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update usages of refs for React 19 compatibility Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Switch pillify to use a html-react-parser approach rather than DOM muddling Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate react html parsing Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate react html parsing Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate html parsing Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Memoize the EventContentBody component Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate html parsing Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Simplify Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Discard changes to src/Linkify.tsx * Discard changes to src/components/views/messages/TextualBody.tsx * Discard changes to src/settings/handlers/AbstractLocalStorageSettingsHandler.ts * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Prepare for React 19 upgrade Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Remove stale comment Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
95 lines
3.7 KiB
TypeScript
95 lines
3.7 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 OR LicenseRef-Element-Commercial
|
|
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: "βοΈ" }];
|
|
|
|
interface CompletionComponentProps {
|
|
title: string;
|
|
}
|
|
|
|
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 as CompletionComponentProps).title).toEqual(":heartpulse:");
|
|
expect((completionsList[1]?.component?.props as CompletionComponentProps).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 as CompletionComponentProps).title).toEqual(":heart:");
|
|
expect((completionsList[1]?.component?.props as CompletionComponentProps).title).toEqual(":heartpulse:");
|
|
expect((completionsList[2]?.component?.props as CompletionComponentProps).title).toEqual(":heart_eyes:");
|
|
});
|
|
});
|