FIX: prevents error with emoji autocomplete (#16465)

The error would happen when emoji_autocomplete_min_chars site setting is set to anything superior to 0, in this case until we reach the min chars length, emojiSearch would return "skip" and the code was currently expecting an array.
This commit is contained in:
Joffrey JAFFEUX 2022-04-13 15:32:24 +02:00 committed by GitHub
parent eb5a3cfded
commit 3e0c8d48e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View File

@ -576,11 +576,15 @@ export default Component.extend(TextareaTextManipulation, {
return resolve(options);
})
.then((list) =>
list.map((code) => {
.then((list) => {
if (list === SKIP) {
return [];
}
return list.map((code) => {
return { code, src: emojiUrlFor(code) };
});
})
)
.then((list) => {
if (list.length) {
list.push({ label: I18n.t("composer.more_emoji"), term });

View File

@ -1,9 +1,10 @@
import {
acceptance,
exists,
normalizeHtml,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, visit } from "@ember/test-helpers";
import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
@ -36,4 +37,23 @@ acceptance("Emoji", function (needs) {
)
);
});
needs.settings({
emoji_autocomplete_min_chars: 2,
});
test("siteSetting:emoji_autocomplete_min_chars", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await fillIn(".d-editor-input", ":s");
await triggerKeyEvent(".d-editor-input", "keyup", 40); // ensures a keyup is triggered
assert.notOk(exists(".autocomplete.ac-emoji"));
await fillIn(".d-editor-input", ":sw");
await triggerKeyEvent(".d-editor-input", "keyup", 40); // ensures a keyup is triggered
assert.ok(exists(".autocomplete.ac-emoji"));
});
});