Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: prevents error with emoji autocomplete #16465

Merged
merged 2 commits into from Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/assets/javascripts/discourse/app/components/d-editor.js
Expand Up @@ -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 });
Expand Down
22 changes: 21 additions & 1 deletion 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";

Expand Down Expand Up @@ -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"));
});
});