FIX: Don't display duplicated emoji in picker

This commit is contained in:
Jarek Radosz 2022-01-11 02:34:22 +01:00 committed by Alan Guo Xiang Tan
parent 22249806a8
commit 2dcad9772f
3 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import {
acceptance,
exists,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, visit } from "@ember/test-helpers";
@ -28,6 +29,15 @@ acceptance("EmojiPicker", function (needs) {
assert.notOk(exists(".emoji-picker.opened"), "it closes the picker");
});
test("filters emoji", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
await fillIn(".emoji-picker input.filter", "guitar");
assert.strictEqual(query(`.emoji-picker .results img`).title, "guitar");
});
test("emoji picker triggers event when picking emoji", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");

View File

@ -150,4 +150,12 @@ discourseModule("Unit | Utility | emoji", function () {
"green_apple",
]);
});
test("search does not return duplicated results", function (assert) {
const matches = emojiSearch("bow").filter(
(emoji) => emoji === "bowing_man"
);
assert.deepEqual(matches, ["bowing_man"]);
});
});

View File

@ -223,7 +223,9 @@ export function emojiSearch(term, options) {
}
if (searchAliases[term]) {
results.push.apply(results, searchAliases[term]);
for (const emoji of searchAliases[term]) {
addResult(emoji);
}
}
for (let i = 0; i < toSearch.length; i++) {