import { emojiSearch } from "pretty-text/emoji";
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
import { emojiUnescape } from "discourse/lib/text";
QUnit.module("lib:emoji");
QUnit.test("emojiUnescape", assert => {
const testUnescape = (input, expected, description, settings = {}) => {
const originalSettings = {};
for (const [key, value] of Object.entries(settings)) {
originalSettings[key] = Discourse.SiteSettings[key];
Discourse.SiteSettings[key] = value;
}
assert.equal(emojiUnescape(input), expected, description);
for (const [key, value] of Object.entries(originalSettings)) {
Discourse.SiteSettings[key] = value;
}
};
testUnescape(
"Not emoji :O) :frog) :smile)",
"Not emoji :O) :frog) :smile)",
"title without emoji"
);
testUnescape(
"Not emoji :frog :smile",
"Not emoji :frog :smile",
"end colon is not optional"
);
testUnescape(
"emoticons :)",
`emoticons `,
"emoticons are still supported"
);
testUnescape(
"With emoji :O: :frog: :smile:",
`With emoji `,
"title with emoji"
);
testUnescape(
"a:smile:a",
"a:smile:a",
"word characters not allowed next to emoji"
);
testUnescape(
"(:frog:) :)",
`() `,
"non-word characters allowed next to emoji"
);
testUnescape(
":smile: hi",
` hi`,
"start of line"
);
testUnescape(
"hi :smile:",
`hi `,
"end of line"
);
testUnescape(
"hi :blonde_woman:t4:",
`hi `,
"support for skin tones"
);
testUnescape(
"hi :blonde_woman:t4: :blonde_man:t6:",
`hi `,
"support for multiple skin tones"
);
testUnescape(
"hi :blonde_man:t6",
"hi :blonde_man:t6",
"end colon not optional for skin tones"
);
testUnescape(
"emoticons :)",
"emoticons :)",
"no emoticons when emojis are disabled",
{ enable_emoji: false }
);
testUnescape(
"emoji :smile:",
"emoji :smile:",
"no emojis when emojis are disabled",
{ enable_emoji: false }
);
testUnescape(
"emoticons :)",
"emoticons :)",
"no emoticons when emoji shortcuts are disabled",
{ enable_emoji_shortcuts: false }
);
});
QUnit.test("Emoji search", assert => {
// able to find an alias
assert.equal(emojiSearch("+1").length, 1);
// able to find middle of line search
assert.equal(emojiSearch("check", { maxResults: 3 }).length, 3);
});