From 3e0c8d48e9a142a6776f074b4d3a5cac59e1eb85 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 13 Apr 2022 15:32:24 +0200 Subject: [PATCH] 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. --- .../discourse/app/components/d-editor.js | 12 ++++++---- .../discourse/tests/acceptance/emoji-test.js | 22 ++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/d-editor.js b/app/assets/javascripts/discourse/app/components/d-editor.js index 8e86af03e4c..afae9e0428e 100644 --- a/app/assets/javascripts/discourse/app/components/d-editor.js +++ b/app/assets/javascripts/discourse/app/components/d-editor.js @@ -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 }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/emoji-test.js b/app/assets/javascripts/discourse/tests/acceptance/emoji-test.js index 367fcf340e4..eb551cf2a82 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/emoji-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/emoji-test.js @@ -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")); + }); });