mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
emoji: Create tests to check the typeahead resuts.
Also, this commit exports the typeahead matcher and sorter functions. Fixes #4126.
This commit is contained in:
@@ -874,3 +874,32 @@ global.people.add(deactivated_user);
|
||||
assert(th_render_stream_called);
|
||||
assert(th_render_typeahead_item_called);
|
||||
}());
|
||||
|
||||
(function test_typeahead_results() {
|
||||
function compose_typeahead_results(completing,items,token) {
|
||||
// items -> emoji array, token -> simulates text in input
|
||||
var matcher = ct.compose_content_matcher.bind({completing: completing, token: token});
|
||||
var sorter = ct.compose_matches_sorter.bind({completing: completing, token: token});
|
||||
var matches = [];
|
||||
_.each(items, function (item) {
|
||||
if (matcher(item)) {
|
||||
matches.push(item);
|
||||
}
|
||||
});
|
||||
var sorted_matches = sorter(matches);
|
||||
return sorted_matches;
|
||||
}
|
||||
|
||||
function assert_emoji_matches(input, expected) {
|
||||
var returned = compose_typeahead_results('emoji', emoji_list, input);
|
||||
assert.deepEqual(returned, expected);
|
||||
}
|
||||
|
||||
assert_emoji_matches('da',[{emoji_name: "tada", emoji_url: "TBD"},
|
||||
{emoji_name: "panda_face", emoji_url: "TBD"}]);
|
||||
assert_emoji_matches('da_', [{emoji_name: "panda_face", emoji_url: "TBD"}]);
|
||||
assert_emoji_matches('da ', [{emoji_name: "panda_face", emoji_url: "TBD"}]);
|
||||
assert_emoji_matches('japanese_post_', [{emoji_name: "japanese_post_office", emoji_url: "TBD"}]);
|
||||
assert_emoji_matches('japanese post ', [{emoji_name: "japanese_post_office", emoji_url: "TBD"}]);
|
||||
assert_emoji_matches('notaemoji', []);
|
||||
}());
|
||||
|
||||
@@ -378,6 +378,31 @@ exports.content_typeahead_selected = function (item) {
|
||||
return beginning + rest;
|
||||
};
|
||||
|
||||
exports.compose_content_matcher = function (item) {
|
||||
if (this.completing === 'emoji') {
|
||||
return query_matches_emoji(this.token, item);
|
||||
} else if (this.completing === 'mention') {
|
||||
return query_matches_person(this.token, item);
|
||||
} else if (this.completing === 'stream') {
|
||||
return query_matches_stream(this.token, item);
|
||||
} else if (this.completing === 'syntax') {
|
||||
return query_matches_language(this.token, item);
|
||||
}
|
||||
};
|
||||
|
||||
exports.compose_matches_sorter = function (matches) {
|
||||
if (this.completing === 'emoji') {
|
||||
return typeahead_helper.sort_emojis(matches, this.token);
|
||||
} else if (this.completing === 'mention') {
|
||||
return typeahead_helper.sort_recipients(matches, this.token,
|
||||
compose_state.stream_name());
|
||||
} else if (this.completing === 'stream') {
|
||||
return typeahead_helper.sort_streams(matches, this.token);
|
||||
} else if (this.completing === 'syntax') {
|
||||
return typeahead_helper.sort_languages(matches, this.token);
|
||||
}
|
||||
};
|
||||
|
||||
exports.initialize_compose_typeahead = function (selector, completions) {
|
||||
completions = $.extend(
|
||||
{mention: false, emoji: false, stream: false, syntax: false}, completions);
|
||||
@@ -388,30 +413,8 @@ exports.initialize_compose_typeahead = function (selector, completions) {
|
||||
fixed: true,
|
||||
source: exports.compose_content_begins_typeahead,
|
||||
highlighter: exports.content_highlighter,
|
||||
matcher: function (item) {
|
||||
if (this.completing === 'emoji') {
|
||||
return query_matches_emoji(this.token, item);
|
||||
} else if (this.completing === 'mention') {
|
||||
return query_matches_person(this.token, item);
|
||||
} else if (this.completing === 'stream') {
|
||||
return query_matches_stream(this.token, item);
|
||||
} else if (this.completing === 'syntax') {
|
||||
return query_matches_language(this.token, item);
|
||||
}
|
||||
},
|
||||
sorter: function (matches) {
|
||||
if (this.completing === 'emoji') {
|
||||
return typeahead_helper.sort_emojis(matches, this.token);
|
||||
} else if (this.completing === 'mention') {
|
||||
return typeahead_helper.sort_recipients(matches, this.token,
|
||||
compose_state.stream_name(),
|
||||
compose_state.subject());
|
||||
} else if (this.completing === 'stream') {
|
||||
return typeahead_helper.sort_streams(matches, this.token);
|
||||
} else if (this.completing === 'syntax') {
|
||||
return typeahead_helper.sort_languages(matches, this.token);
|
||||
}
|
||||
},
|
||||
matcher: exports.compose_content_matcher,
|
||||
sorter: exports.compose_matches_sorter,
|
||||
updater: exports.content_typeahead_selected,
|
||||
stopAdvance: true, // Do not advance to the next field on a tab or enter
|
||||
completions: completions,
|
||||
|
||||
Reference in New Issue
Block a user