Skip to content

Commit

Permalink
node_tests: Add tests covering user groups in PM recipient typeahead.
Browse files Browse the repository at this point in the history
  • Loading branch information
synicalsyntax committed Jul 26, 2018
1 parent 37a5221 commit 1bab817
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions frontend_tests/node_tests/composebox_typeahead.js
@@ -1,4 +1,5 @@
set_global('i18n', global.stub_i18n);
zrequire('dict');
zrequire('compose_state');
zrequire('ui_util');
zrequire('pm_conversations');
Expand All @@ -12,6 +13,7 @@ zrequire('user_groups');
zrequire('stream_data');
zrequire('user_pill');
zrequire('compose_pm_pill');
zrequire('recent_senders');
zrequire('composebox_typeahead');
set_global('md5', function (s) {
return 'md5-' + s;
Expand All @@ -23,6 +25,9 @@ set_global('topic_data', {
var ct = composebox_typeahead;
var noop = function () {};

set_global('blueslip', {});
blueslip.warn = noop;

var emoji_stadium = {
emoji_name: 'stadium',
emoji_url: 'TBD',
Expand Down Expand Up @@ -163,7 +168,7 @@ var hamletcharacters = {
name: "hamletcharacters",
id: 1,
description: "Characters of Hamlet",
members: [],
members: [100, 104],
};

var backend = {
Expand Down Expand Up @@ -470,7 +475,7 @@ run_test('initialize', () => {
$('#private_message_recipient').typeahead = function (options) {
// This should match the users added at the beginning of this test file.
var actual_value = options.source();
var expected_value = [hamlet, othello, cordelia, lear];
var expected_value = [hamlet, othello, cordelia, lear, hamletcharacters, backend];
assert.deepEqual(actual_value, expected_value);

// Even though the items passed to .highlighter() are the full
Expand Down Expand Up @@ -531,7 +536,7 @@ run_test('initialize', () => {
// A literal match at the beginning of an element puts it at the top.
options.query = 'co'; // Matches everything ("x@zulip.COm")
actual_value = options.sorter([othello, deactivated_user, cordelia]);
expected_value = [cordelia, deactivated_user, othello];
expected_value = [cordelia, othello, deactivated_user];
assert.deepEqual(actual_value, expected_value);

options.query = 'non-existing-user';
Expand Down Expand Up @@ -571,6 +576,29 @@ run_test('initialize', () => {
actual_value = options.updater(othello, click_event);
assert.equal(appended_name, 'Othello, the Moor of Venice');

var appended_names = [];
people.get_person_from_user_id = function (user_id) {
var users = {100: hamlet, 104: lear};
return users[user_id];
};
people.my_current_email = function () {
return 'hamlet@zulip.com';
};
compose_pm_pill.set_from_typeahead = function (item) {
appended_names.push(item.full_name);
};

var cleared = false;
function fake_clear() {
cleared = true;
}
compose_pm_pill.widget = {clear_text: fake_clear};

options.query = 'hamletchar';
options.updater(hamletcharacters, event);
assert.deepEqual(appended_names, ['King Lear']);
assert(cleared);

pm_recipient_typeahead_called = true;
};

Expand Down

0 comments on commit 1bab817

Please sign in to comment.