Add support for m.recent_emoji account data event (#33172)

* Improve types in AccountSettingsHandler

* Add support for `m.recent_emoji` account data event

Maintains read-compatibility with `io.element.recent_emoji`

* Iterate

* Make ts happier

* Improve coverage

* Improve coverage

* Improve coverage
This commit is contained in:
Michael Telatynski
2026-05-26 09:30:02 +01:00
committed by GitHub
parent 5cfb68962d
commit f0342ddbd2
6 changed files with 211 additions and 69 deletions
@@ -13,6 +13,7 @@ import userEvent from "@testing-library/user-event";
import EmojiPicker from "../../../../../src/components/views/emojipicker/EmojiPicker";
import { stubClient } from "../../../../test-utils";
import SettingsStore from "../../../../../src/settings/SettingsStore";
import { SettingLevel } from "../../../../../src/settings/SettingLevel.ts";
describe("EmojiPicker", function () {
stubClient();
@@ -23,10 +24,7 @@ describe("EmojiPicker", function () {
beforeEach(() => {
// Clear recent emojis to prevent test pollution
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName) => {
if (settingName === "recent_emoji") return [] as any;
return jest.requireActual("../../../../../src/settings/SettingsStore").default.getValue(settingName);
});
SettingsStore.reset();
});
afterEach(() => {
@@ -98,10 +96,11 @@ describe("EmojiPicker", function () {
it("should initialize categories with recent as firstVisible when recent emojis exist", () => {
// Mock recent emojis
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName) => {
if (settingName === "recent_emoji") return ["😀", "🎉", "❤️"] as any;
return jest.requireActual("../../../../../src/settings/SettingsStore").default.getValue(settingName);
});
SettingsStore.setValue("recent_emoji", null, SettingLevel.ACCOUNT, [
{ emoji: "😀", total: 3 },
{ emoji: "🎉", total: 2 },
{ emoji: "❤️", total: 2 },
]);
const ref = createRef<EmojiPicker>();
render(<EmojiPicker ref={ref} onChoose={(str: string) => false} onFinished={jest.fn()} />);
@@ -394,10 +393,10 @@ describe("EmojiPicker", function () {
it("check tabindex for recent category when recent emojis exist", async () => {
// Mock recent emojis
jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName) => {
if (settingName === "recent_emoji") return ["😀", "🎉"] as any;
return jest.requireActual("../../../../../src/settings/SettingsStore").default.getValue(settingName);
});
SettingsStore.setValue("recent_emoji", null, SettingLevel.ACCOUNT, [
{ emoji: "😀", total: 3 },
{ emoji: "🎉", total: 2 },
]);
const { container } = render(<EmojiPicker onChoose={jest.fn()} onFinished={jest.fn()} />);
@@ -0,0 +1,45 @@
/*
Copyright 2026 Element Creations Ltd.
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 { translateLegacyEmojiData, mergeEmojiData } from "../../../../../src/emojipicker/recent.ts";
describe("recent", () => {
describe("translateLegacyEmojiData", () => {
it("should correctly translate to the new format", () => {
expect(
translateLegacyEmojiData([
["🤩", 1],
["😀", 2],
]),
).toEqual([
{ emoji: "🤩", total: 1 },
{ emoji: "😀", total: 2 },
]);
});
});
describe("mergeEmojiData", () => {
it("should merge given data correctly", () => {
expect(
mergeEmojiData(
[{ emoji: "🤩", total: 1 }],
[
{ emoji: "🤩", total: 2 },
{ emoji: "😀", total: 1 },
],
),
).toEqual([
{ emoji: "🤩", total: 2 },
{ emoji: "😀", total: 1 },
]);
});
it("should handle data2 being undefined", () => {
expect(mergeEmojiData([{ emoji: "🤩", total: 1 }])).toEqual([{ emoji: "🤩", total: 1 }]);
});
});
});