forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prioritize stream subscribers in typeahead list.
When autocompleting names using @mention, subscribers of the stream would appear at the top of the list. Added new test module to reflect this change.
- Loading branch information
Showing
2 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
var th = require('js/typeahead_helper.js'); | ||
|
||
global.stub_out_jquery(); | ||
|
||
set_global('compose', {}); | ||
set_global('page_params', {is_zephyr_mirror_realm: false}); | ||
|
||
add_dependencies({ | ||
stream_data: 'js/stream_data.js', | ||
people: 'js/people.js', | ||
}); | ||
|
||
stream_data.create_streams([ | ||
{name: 'Dev', subscribed: true, color: 'blue', stream_id: 1}, | ||
{name: 'Linux', subscribed: true, color: 'red', stream_id: 2} | ||
]); | ||
|
||
var matches = [ | ||
{ | ||
email: "[email protected]", | ||
full_name: "A zulip test bot", | ||
is_admin: false, | ||
is_bot: true, | ||
user_id: 1, | ||
}, { | ||
email: "[email protected]", | ||
full_name: "A zulip user", | ||
is_admin: false, | ||
is_bot: false, | ||
user_id: 2, | ||
}, { | ||
email: "[email protected]", | ||
full_name: "Bob 1", | ||
is_admin: false, | ||
is_bot: false, | ||
user_id: 3, | ||
}, { | ||
email: "[email protected]", | ||
full_name: "Bob 2", | ||
is_admin: true, | ||
is_bot: false, | ||
user_id: 4, | ||
}, { | ||
email: "[email protected]", | ||
full_name: "B bot", | ||
is_admin: false, | ||
is_bot: true, | ||
user_id: 5, | ||
}, { | ||
email: "[email protected]", | ||
full_name: "Zman", | ||
is_admin: false, | ||
is_bot: false, | ||
user_id: 6, | ||
} | ||
]; | ||
|
||
_.each(matches, function (person) { | ||
global.people.add_in_realm(person); | ||
}); | ||
|
||
(function test_sort_recipients() { | ||
function get_typeahead_result(query) { | ||
var result = th.sort_recipients(global.people.get_realm_persons(), query); | ||
return _.map(result, function (person) { | ||
return person.email; | ||
}); | ||
} | ||
|
||
global.compose.stream_name = function () { return ""; }; | ||
assert.deepEqual(get_typeahead_result("b"), [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]' | ||
]); | ||
|
||
global.compose.stream_name = function () { return "Dev"; }; | ||
var subscriber_email = "[email protected]"; | ||
stream_data.add_subscriber("Dev", people.get_user_id(subscriber_email)); | ||
assert.deepEqual(get_typeahead_result("b"), [ | ||
subscriber_email, | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]' | ||
]); | ||
|
||
// No match | ||
global.compose.stream_name = function () { return "Linux"; }; | ||
assert.deepEqual(get_typeahead_result("h"), [ | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]' | ||
]); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters