2019-03-15 12:44:49 +08:00
|
|
|
import { emojiSearch } from "pretty-text/emoji";
|
|
|
|
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
|
2016-06-15 02:31:51 +08:00
|
|
|
import { emojiUnescape } from "discourse/lib/text";
|
2020-07-10 03:54:53 +08:00
|
|
|
import { discourseModule } from "helpers/qunit-helpers";
|
2015-06-01 10:33:42 +08:00
|
|
|
|
2020-07-10 03:54:53 +08:00
|
|
|
discourseModule("lib:emoji");
|
2015-06-01 10:33:42 +08:00
|
|
|
|
2020-07-10 03:54:53 +08:00
|
|
|
QUnit.test("emojiUnescape", function(assert) {
|
2019-05-21 22:56:51 +08:00
|
|
|
const testUnescape = (input, expected, description, settings = {}) => {
|
|
|
|
const originalSettings = {};
|
|
|
|
for (const [key, value] of Object.entries(settings)) {
|
2020-07-10 03:54:53 +08:00
|
|
|
originalSettings[key] = this.siteSettings[key];
|
|
|
|
this.siteSettings[key] = value;
|
2019-05-21 22:56:51 +08:00
|
|
|
}
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(emojiUnescape(input), expected, description);
|
2019-05-21 22:56:51 +08:00
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(originalSettings)) {
|
2020-07-10 03:54:53 +08:00
|
|
|
this.siteSettings[key] = value;
|
2019-05-21 22:56:51 +08:00
|
|
|
}
|
2017-06-15 01:57:58 +08:00
|
|
|
};
|
2015-08-27 02:57:47 +08:00
|
|
|
|
|
|
|
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"
|
2017-06-05 20:06:23 +08:00
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"emoticons :)",
|
|
|
|
`emoticons <img src='/images/emoji/emoji_one/slight_smile.png?v=${v}' title='slight_smile' alt='slight_smile' class='emoji'>`,
|
|
|
|
"emoticons are still supported"
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2015-08-27 02:57:47 +08:00
|
|
|
testUnescape(
|
|
|
|
"With emoji :O: :frog: :smile:",
|
2016-03-05 03:20:44 +08:00
|
|
|
`With emoji <img src='/images/emoji/emoji_one/o.png?v=${v}' title='O' alt='O' class='emoji'> <img src='/images/emoji/emoji_one/frog.png?v=${v}' title='frog' alt='frog' class='emoji'> <img src='/images/emoji/emoji_one/smile.png?v=${v}' title='smile' alt='smile' class='emoji'>`,
|
2015-08-27 02:57:47 +08:00
|
|
|
"title with emoji"
|
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"a:smile:a",
|
|
|
|
"a:smile:a",
|
|
|
|
"word characters not allowed next to emoji"
|
|
|
|
);
|
2016-03-05 03:20:44 +08:00
|
|
|
testUnescape(
|
|
|
|
"(:frog:) :)",
|
|
|
|
`(<img src='/images/emoji/emoji_one/frog.png?v=${v}' title='frog' alt='frog' class='emoji'>) <img src='/images/emoji/emoji_one/slight_smile.png?v=${v}' title='slight_smile' alt='slight_smile' class='emoji'>`,
|
|
|
|
"non-word characters allowed next to emoji"
|
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
":smile: hi",
|
|
|
|
`<img src='/images/emoji/emoji_one/smile.png?v=${v}' title='smile' alt='smile' class='emoji'> hi`,
|
|
|
|
"start of line"
|
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"hi :smile:",
|
|
|
|
`hi <img src='/images/emoji/emoji_one/smile.png?v=${v}' title='smile' alt='smile' class='emoji'>`,
|
|
|
|
"end of line"
|
2017-06-05 20:06:23 +08:00
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"hi :blonde_woman:t4:",
|
|
|
|
`hi <img src='/images/emoji/emoji_one/blonde_woman/4.png?v=${v}' title='blonde_woman:t4' alt='blonde_woman:t4' class='emoji'>`,
|
|
|
|
"support for skin tones"
|
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"hi :blonde_woman:t4: :blonde_man:t6:",
|
|
|
|
`hi <img src='/images/emoji/emoji_one/blonde_woman/4.png?v=${v}' title='blonde_woman:t4' alt='blonde_woman:t4' class='emoji'> <img src='/images/emoji/emoji_one/blonde_man/6.png?v=${v}' title='blonde_man:t6' alt='blonde_man:t6' class='emoji'>`,
|
|
|
|
"support for multiple skin tones"
|
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"hi :blonde_man:t6",
|
|
|
|
"hi :blonde_man:t6",
|
|
|
|
"end colon not optional for skin tones"
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2019-05-21 22:56:51 +08:00
|
|
|
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 }
|
|
|
|
);
|
2019-12-04 00:32:33 +08:00
|
|
|
testUnescape(
|
|
|
|
"Hello 😊 World",
|
|
|
|
`Hello <img src='/images/emoji/emoji_one/blush.png?v=${v}' title='blush' alt='blush' class='emoji'> World`,
|
|
|
|
"emoji from Unicode emoji"
|
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"Hello😊World",
|
|
|
|
"Hello😊World",
|
|
|
|
"keeps Unicode emoji when inline translation disabled",
|
|
|
|
{
|
|
|
|
enable_inline_emoji_translation: false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"Hello😊World",
|
|
|
|
`Hello<img src='/images/emoji/emoji_one/blush.png?v=${v}' title='blush' alt='blush' class='emoji'>World`,
|
|
|
|
"emoji from Unicode emoji when inline translation enabled",
|
|
|
|
{
|
|
|
|
enable_inline_emoji_translation: true
|
|
|
|
}
|
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"hi:smile:",
|
|
|
|
"hi:smile:",
|
|
|
|
"no emojis when inline translation disabled",
|
|
|
|
{
|
|
|
|
enable_inline_emoji_translation: false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
testUnescape(
|
|
|
|
"hi:smile:",
|
|
|
|
`hi<img src='/images/emoji/emoji_one/smile.png?v=${v}' title='smile' alt='smile' class='emoji'>`,
|
|
|
|
"emoji when inline translation enabled",
|
|
|
|
{ enable_inline_emoji_translation: true }
|
|
|
|
);
|
2015-08-27 02:57:47 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("Emoji search", assert => {
|
2015-06-01 10:33:42 +08:00
|
|
|
// able to find an alias
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(emojiSearch("+1").length, 1);
|
2015-06-01 10:33:42 +08:00
|
|
|
|
2016-07-04 17:16:08 +08:00
|
|
|
// able to find middle of line search
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(emojiSearch("check", { maxResults: 3 }).length, 3);
|
2015-06-01 10:33:42 +08:00
|
|
|
});
|