2016-06-15 02:31:51 +08:00
|
|
|
import { emojiSearch, IMAGE_VERSION as v } from 'pretty-text/emoji';
|
|
|
|
import { emojiUnescape } from 'discourse/lib/text';
|
2015-06-01 10:33:42 +08:00
|
|
|
|
2016-06-15 02:31:51 +08:00
|
|
|
module('lib:emoji');
|
2015-06-01 10:33:42 +08:00
|
|
|
|
2016-06-15 02:31:51 +08:00
|
|
|
function testUnescape(input, expected, description) {
|
|
|
|
equal(emojiUnescape(input), expected, description);
|
2015-08-27 02:57:47 +08:00
|
|
|
};
|
|
|
|
|
2016-06-15 02:31:51 +08:00
|
|
|
test("emojiUnescape", () => {
|
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");
|
2016-07-26 06:53:48 +08:00
|
|
|
testUnescape("emoticons :)", "emoticons <img src='/images/emoji/emoji_one/slight_smile.png?v=3' title='slight_smile' alt='slight_smile' class='emoji'>", "emoticons are still supported");
|
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");
|
2015-08-27 02:57:47 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-06-15 02:31:51 +08:00
|
|
|
test("Emoji search", () => {
|
2015-06-01 10:33:42 +08:00
|
|
|
|
|
|
|
// able to find an alias
|
2016-06-15 02:31:51 +08:00
|
|
|
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
|
2016-06-15 02:31:51 +08:00
|
|
|
equal(emojiSearch("check", {maxResults: 3}).length, 3);
|
2016-07-04 17:16:08 +08:00
|
|
|
|
2015-06-01 10:33:42 +08:00
|
|
|
});
|