2017-06-25 15:41:01 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
2017-10-27 17:22:04 +02:00
|
|
|
set_global('page_params', {
|
|
|
|
emojiset: 'google',
|
|
|
|
});
|
2017-06-25 15:41:01 +02:00
|
|
|
set_global('upload_widget', {});
|
2018-04-09 10:55:03 +02:00
|
|
|
set_global('blueslip', global.make_zblueslip());
|
2017-06-25 15:41:01 +02:00
|
|
|
|
2017-11-08 17:16:03 +01:00
|
|
|
zrequire('emoji_codes', 'generated/emoji/emoji_codes');
|
|
|
|
zrequire('emoji');
|
2018-01-15 19:36:32 +01:00
|
|
|
zrequire('markdown');
|
|
|
|
zrequire('util');
|
2017-06-25 15:41:01 +02:00
|
|
|
|
|
|
|
(function test_build_emoji_upload_widget() {
|
|
|
|
var build_widget_stub = false;
|
|
|
|
upload_widget.build_widget = function (
|
|
|
|
get_file_input,
|
|
|
|
file_name_field,
|
|
|
|
input_error,
|
|
|
|
clear_button,
|
|
|
|
upload_button
|
|
|
|
) {
|
|
|
|
assert.deepEqual(get_file_input(), $('#emoji_file_input'));
|
|
|
|
assert.deepEqual(file_name_field, $('#emoji-file-name'));
|
|
|
|
assert.deepEqual(input_error, $('#emoji_file_input_error'));
|
|
|
|
assert.deepEqual(clear_button, $('#emoji_image_clear_button'));
|
|
|
|
assert.deepEqual(upload_button, $('#emoji_upload_button'));
|
|
|
|
build_widget_stub = true;
|
|
|
|
};
|
|
|
|
emoji.build_emoji_upload_widget();
|
|
|
|
assert(build_widget_stub);
|
|
|
|
}());
|
2017-06-25 22:45:47 +02:00
|
|
|
|
|
|
|
(function test_initialize() {
|
|
|
|
var image_stub = false;
|
|
|
|
class Image {
|
|
|
|
set src(data) {
|
2018-03-13 20:34:31 +01:00
|
|
|
assert.equal(data, '/static/generated/emoji/sheet_google_64.png');
|
2017-06-25 22:45:47 +02:00
|
|
|
image_stub = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set_global('Image', Image);
|
|
|
|
emoji.initialize();
|
|
|
|
assert(image_stub);
|
|
|
|
}());
|
2017-09-29 22:14:57 +02:00
|
|
|
|
|
|
|
(function test_get_canonical_name() {
|
|
|
|
emoji.active_realm_emojis = {
|
|
|
|
realm_emoji: 'TBD',
|
|
|
|
};
|
|
|
|
var canonical_name = emoji.get_canonical_name('realm_emoji');
|
|
|
|
assert.equal(canonical_name, 'realm_emoji');
|
|
|
|
|
|
|
|
global.emoji_codes = {
|
|
|
|
name_to_codepoint: {
|
|
|
|
'+1': '1f44d',
|
|
|
|
},
|
|
|
|
codepoint_to_name: {
|
|
|
|
'1f44d': 'thumbs_up',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
canonical_name = emoji.get_canonical_name('+1');
|
|
|
|
assert.equal(canonical_name, 'thumbs_up');
|
|
|
|
|
|
|
|
emoji.active_realm_emojis = {
|
|
|
|
'+1': 'TBD',
|
|
|
|
};
|
|
|
|
canonical_name = emoji.get_canonical_name('+1');
|
|
|
|
assert.equal(canonical_name, '+1');
|
|
|
|
|
2018-04-09 10:55:03 +02:00
|
|
|
blueslip.set_test_data('error', 'Invalid emoji name: non_existent');
|
2017-09-29 22:14:57 +02:00
|
|
|
emoji.get_canonical_name('non_existent');
|
2018-04-09 10:55:03 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('error').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2017-09-29 22:14:57 +02:00
|
|
|
}());
|
2018-01-15 19:36:32 +01:00
|
|
|
|
|
|
|
(function test_translate_emoticons_to_names() {
|
2018-03-25 18:06:06 +02:00
|
|
|
// Simple test
|
|
|
|
var test_text = 'Testing :)';
|
|
|
|
var expected = 'Testing :smiley:';
|
|
|
|
var result = emoji.translate_emoticons_to_names(test_text);
|
|
|
|
assert.equal(expected, result);
|
2018-01-15 19:36:32 +01:00
|
|
|
|
2018-03-25 18:06:06 +02:00
|
|
|
// Extensive tests.
|
|
|
|
// The following code loops over the test cases and each emoticon conversion
|
|
|
|
// to generate multiple test cases.
|
|
|
|
var testcases = [
|
|
|
|
{name: 'only emoticon', original: '<original>', expected: '<converted>'},
|
|
|
|
{name: 'space at start', original: ' <original>', expected: ' <converted>'},
|
|
|
|
{name: 'space at end', original: '<original> ', expected: '<converted> '},
|
|
|
|
{name: 'symbol at end', original: '<original>!', expected: '<converted>!'},
|
|
|
|
{name: 'symbol at start', original: 'Hello,<original>', expected: 'Hello,<converted>'},
|
|
|
|
{name: 'after a word', original: 'Hello<original>', expected: 'Hello<original>'},
|
|
|
|
{name: 'between words', original: 'Hello<original>World', expected: 'Hello<original>World'},
|
|
|
|
{name: 'end of sentence', original: 'End of sentence. <original>', expected: 'End of sentence. <converted>'},
|
|
|
|
{name: 'between symbols', original: 'Hello.<original>! World.', expected: 'Hello.<original>! World.'},
|
|
|
|
{name: 'before end of sentence', original: 'Hello <original>!', expected: 'Hello <converted>!'},
|
|
|
|
];
|
2018-04-12 22:23:50 +02:00
|
|
|
_.each(emoji.EMOTICON_CONVERSIONS, (full_name, shortcut) => {
|
|
|
|
_.each(testcases, (t) => {
|
|
|
|
var converted_value = ':' + full_name + ':';
|
|
|
|
var original = t.original;
|
|
|
|
var expected = t.expected;
|
|
|
|
original = original.replace(/(<original>)/g, shortcut);
|
|
|
|
expected = expected.replace(/(<original>)/g, shortcut)
|
2018-05-07 03:30:13 +02:00
|
|
|
.replace(/(<converted>)/g, converted_value);
|
2018-04-12 22:23:50 +02:00
|
|
|
var result = emoji.translate_emoticons_to_names(original);
|
|
|
|
assert.equal(result, expected);
|
2018-03-25 18:06:06 +02:00
|
|
|
});
|
|
|
|
});
|
2018-01-15 19:36:32 +01:00
|
|
|
}());
|