Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

tests: Add comments explaining typeahead sort ordering in tests.

Aman Agrawal9bfd5c9c8e7a
diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjs
index 2c62e2b2382..382833f861c 100644
--- a/web/tests/composebox_typeahead.test.cjs
+++ b/web/tests/composebox_typeahead.test.cjs
@@ -753,19 +753,19 @@ const make_emoji = (emoji_dict) => ({
type: "emoji",
});
-// Sorted by name
+// Alphabetical tiebreaker in compare_by_pms sorts by full_name.
const sorted_user_list = [
- ali_item,
- alice_item,
- cordelia_item,
- hal_item, // Early Hal
- gael_item,
- harry_item,
+ ali_item, // Ali
+ alice_item, // Alice
+ cordelia_item, // Cordelia, Lear's daughter
+ hal_item, // Earl Hal
+ gael_item, // Gaël Twin
+ harry_item, // Harry
hamlet_item, // King Hamlet
- lear_item,
+ lear_item, // King Lear
twin1_item, // Mark Twin
- twin2_item,
- othello_item,
+ twin2_item, // Mark Twin
+ othello_item, // Othello, the Moor of Venice
];
function test(label, f) {
@@ -1575,20 +1575,21 @@ test("initialize", ({override, override_rewire, mock_template}) => {
case $("#private_message_recipient")[0]: {
pill_items = [];
- // This should match the users added at the beginning of this test file.
+ // Users sorted alphabetically by compare_by_pms
+ // tiebreaker, then groups, then welcome_bot.
let actual_value = options.source("");
let expected_value = [
- ali_item,
- alice_item,
- cordelia_item,
- hal_item,
- gael_item,
- harry_item,
- hamlet_item,
- lear_item,
- twin1_item,
- twin2_item,
- othello_item,
+ ali_item, // Ali
+ alice_item, // Alice
+ cordelia_item, // Cordelia, Lear's daughter
+ hal_item, // Earl Hal
+ gael_item, // Gaël Twin
+ harry_item, // Harry
+ hamlet_item, // King Hamlet
+ lear_item, // King Lear
+ twin1_item, // Mark Twin
+ twin2_item, // Mark Twin
+ othello_item, // Othello, the Moor of Venice
hamletcharacters,
backend,
call_center,
@@ -2351,22 +2352,24 @@ test("begins_typeahead", ({override, override_rewire}) => {
]);
const mention_all = broadcast_item(ct.broadcast_mentions()[0]);
+ // compose_state is "private" (from earlier test), so broadcasts
+ // sort after all users; bots alphabetical after non-bots.
const users_and_all_mention = [
...sorted_user_list,
mention_all,
- notification_bot_item,
- welcome_bot_item,
+ notification_bot_item, // Notification Bot
+ welcome_bot_item, // Welcome Bot
];
const users_and_user_groups = [
...sorted_user_list,
- // alphabetical
+ // Groups alphabetical by display name.
hamletcharacters, // "Characters of Hamlet"
backend,
- call_center, // "folks working in support",
+ call_center, // "folks working in support"
admins,
members,
- notification_bot_item,
- welcome_bot_item,
+ notification_bot_item, // Notification Bot
+ welcome_bot_item, // Welcome Bot
];
const mention_everyone = broadcast_item(ct.broadcast_mentions()[1]);
function mentions_with_silent_marker(mentions, is_silent) {
@@ -2384,27 +2387,30 @@ test("begins_typeahead", ({override, override_rewire}) => {
assert_typeahead_equals("@_*", mentions_with_silent_marker(users_and_user_groups, true));
assert_typeahead_equals("@**", mentions_with_silent_marker(users_and_all_mention, false));
assert_typeahead_equals("@_**", mentions_with_silent_marker(users_and_user_groups, true));
+ // "o" is anywhere in each name; Othello starts with "o" so
+ // sorts first. Remaining users alphabetical, then broadcasts
+ // (private mode), then bots alphabetical.
assert_typeahead_equals(
"test @**o",
mentions_with_silent_marker(
[
- othello_item,
- cordelia_item,
- mention_everyone,
- notification_bot_item,
- welcome_bot_item,
+ othello_item, // Othello starts with "o"
+ cordelia_item, // "Cordelia" contains "o"
+ mention_everyone, // broadcast: after users in private mode
+ notification_bot_item, // Notification Bot
+ welcome_bot_item, // Welcome Bot
],
false,
),
);
assert_typeahead_equals(
"test @_**o",
-
mentions_with_silent_marker(
[othello_item, cordelia_item, admins, members, notification_bot_item, welcome_bot_item],
true,
),
);
+ // Same as @**o above.
assert_typeahead_equals(
"test @*o",
mentions_with_silent_marker(
@@ -2418,6 +2424,9 @@ test("begins_typeahead", ({override, override_rewire}) => {
false,
),
);
+ // "k" matches: "King Hamlet" and "King Lear" start with "k"
+ // (best, alphabetical); "Mark Twin" x2 contain "k" (ok,
+ // word-boundary match); "backend" group also matches.
assert_typeahead_equals(
"test @_*k",
mentions_with_silent_marker(
@@ -2425,6 +2434,10 @@ test("begins_typeahead", ({override, override_rewire}) => {
true,
),
);
+ // "h": Harry starts with "h" (best); Earl Hal and King Hamlet
+ // have word-boundary match (ok, alphabetical); Cordelia and
+ // Othello contain "h" but no word-boundary match (worst,
+ // alphabetical).
assert_typeahead_equals(
"test @*h",
mentions_with_silent_marker(
@@ -2449,57 +2462,66 @@ test("begins_typeahead", ({override, override_rewire}) => {
assert_typeahead_equals("@_* ", []);
assert_typeahead_equals("@** ", []);
assert_typeahead_equals("@_** ", []);
+ // "i" has no name-start match; all users whose name contains "i"
+ // are in the worst tier, sorted alphabetically by full_name.
assert_typeahead_equals(
"test\n@i",
mentions_with_silent_marker(
[
- ali_item,
- alice_item,
- cordelia_item,
- gael_item,
- hamlet_item,
- lear_item,
- twin1_item,
- twin2_item,
- othello_item,
- notification_bot_item,
+ ali_item, // Ali
+ alice_item, // Alice
+ cordelia_item, // Cordelia, Lear's daughter
+ gael_item, // Gaël Twin
+ hamlet_item, // King Hamlet
+ lear_item, // King Lear
+ twin1_item, // Mark Twin
+ twin2_item, // Mark Twin
+ othello_item, // Othello, the Moor of Venice
+ notification_bot_item, // Notification Bot (bot tier)
],
false,
),
);
+ // Unlike the non-silent "@i" above, the silent "@_" typeahead offers
+ // every user group (not just those you're allowed to mention), so the
+ // "admins" group appears here; it's the only group whose name has "i".
assert_typeahead_equals(
"test\n@_i",
mentions_with_silent_marker(
[
- ali_item,
- alice_item,
- cordelia_item,
- gael_item,
- hamlet_item,
- lear_item,
- twin1_item,
- twin2_item,
- othello_item,
- admins,
- notification_bot_item,
+ ali_item, // Ali
+ alice_item, // Alice
+ cordelia_item, // Cordelia, Lear's daughter
+ gael_item, // Gaël Twin
+ hamlet_item, // King Hamlet
+ lear_item, // King Lear
+ twin1_item, // Mark Twin
+ twin2_item, // Mark Twin
+ othello_item, // Othello, the Moor of Venice
+ admins, // group: admins
+ notification_bot_item, // Notification Bot (bot tier)
],
true,
),
);
+ // "l": Cordelia and Lear have word-boundary match on "Lear"
+ // (best, alphabetical). Others contain "l" with no word-boundary
+ // match (worst, alphabetical). Broadcast after users (private
+ // mode), then bot.
assert_typeahead_equals(
"test\n @l",
mentions_with_silent_marker(
[
- cordelia_item,
- lear_item,
- ali_item,
- alice_item,
- hal_item,
- gael_item,
- hamlet_item,
- othello_item,
- mention_all,
- welcome_bot_item,
+ cordelia_item, // Cordelia, *L*ear's daughter
+ lear_item, // King *L*ear
+ ali_item, // Ali
+ alice_item, // Alice
+ hal_item, // Earl Hal
+ gael_item, // Gaël Twin
+ hamlet_item, // King Hamlet
+ othello_item, // Othello, the Moor of Venice
+ mention_all, // broadcast "all" (after users)
+ welcome_bot_item, // Welcome Bot (bot tier)
],
false,
),
@@ -2530,6 +2552,7 @@ test("begins_typeahead", ({override, override_rewire}) => {
assert_typeahead_equals("@_ zuli", []);
assert_typeahead_equals(" @zuli", []);
assert_typeahead_equals(" @_zuli", []);
+ // Same ordering logic as @**o above.
assert_typeahead_equals(
"test @o",
mentions_with_silent_marker(
@@ -3030,6 +3053,7 @@ test("typeahead_results", ({override}) => {
assert_mentions_matches("oor ", []);
assert_mentions_matches("oor o", []);
assert_mentions_matches("oor of venice", []);
+ // Both start with "King "; alphabetical: Hamlet < Lear.
assert_mentions_matches("King ", [not_silent(hamlet_item), not_silent(lear_item)]);
assert_mentions_matches("King H", [not_silent(hamlet_item)]);
assert_mentions_matches("King L", [not_silent(lear_item)]);
@@ -3049,33 +3073,37 @@ test("typeahead_results", ({override}) => {
// Verify we suggest only the first matching stream wildcard mention,
// irrespective of how many equivalent stream wildcard mentions match.
const mention_everyone = not_silent(broadcast_item(ct.broadcast_mentions()[1]));
- // Here, we suggest only "everyone" instead of both the matching
- // "everyone" and "stream" wildcard mentions.
+ // compose_state is "stream" here, so broadcasts sort before users.
+ // "everyone" and Earl Hal start with "e" (best, broadcast first);
+ // remaining users contain "e" (worst, alphabetical); then groups
+ // and bots.
assert_mentions_matches("e", [
- not_silent(mention_everyone),
- not_silent(hal_item),
- not_silent(alice_item),
- not_silent(cordelia_item),
- not_silent(gael_item),
- not_silent(hamlet_item),
- not_silent(lear_item),
- not_silent(othello_item),
- not_silent(hamletcharacters),
- not_silent(call_center),
- not_silent(welcome_bot_item),
+ not_silent(mention_everyone), // broadcast: "everyone" starts with "e"
+ not_silent(hal_item), // Earl Hal starts with "e"
+ not_silent(alice_item), // Alice
+ not_silent(cordelia_item), // Cordelia, Lear's daughter
+ not_silent(gael_item), // Gaël Twin
+ not_silent(hamlet_item), // King Hamlet
+ not_silent(lear_item), // King Lear
+ not_silent(othello_item), // Othello, the Moor of Venice
+ not_silent(hamletcharacters), // group
+ not_silent(call_center), // group
+ not_silent(welcome_bot_item), // Welcome Bot (bot tier)
]);
// Verify we suggest both 'the first matching stream wildcard' and
// 'topic wildcard' mentions. Not only one matching wildcard mention.
const mention_topic = broadcast_item(ct.broadcast_mentions()[4]);
- // Here, we suggest both "everyone" and "topic".
+ // Othello starts with "o" (best); everyone/topic broadcasts and
+ // Cordelia contain "o" (worst, broadcasts first in stream mode,
+ // then user); bots alphabetical.
assert_mentions_matches("o", [
- not_silent(othello_item),
- not_silent(mention_everyone),
- not_silent(mention_topic),
- not_silent(cordelia_item),
- not_silent(notification_bot_item),
- not_silent(welcome_bot_item),
+ not_silent(othello_item), // Othello starts with "o"
+ not_silent(mention_everyone), // broadcast (stream mode: first)
+ not_silent(mention_topic), // broadcast (stream mode: first)
+ not_silent(cordelia_item), // "Cordelia" contains "o"
+ not_silent(notification_bot_item), // Notification Bot
+ not_silent(welcome_bot_item), // Welcome Bot
]);
// Autocomplete by slash commands.
diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjs
index 897441642cf..7b4e6d2cd23 100644
--- a/web/tests/search_suggestion.test.cjs
+++ b/web/tests/search_suggestion.test.cjs
@@ -192,13 +192,14 @@ test("get_is_suggestions_for_spectator", () => {
test("dm_suggestions", ({override}) => {
let query = "is:dm";
let suggestions = get_suggestions(query);
+ // Sorted alphabetically by full_name (compare_by_pms tiebreaker).
let expected = [
"is:dm",
- `dm:${alice.user_id}`,
- `dm:${bob.user_id}`,
- `dm:${jeff.user_id}`,
- `dm:${me.user_id}`,
- `dm:${ted.user_id}`,
+ `dm:${alice.user_id}`, // Alice Ignore
+ `dm:${bob.user_id}`, // Bob Roberts
+ `dm:${jeff.user_id}`, // Jeff Zoolipson
+ `dm:${me.user_id}`, // Me Myself
+ `dm:${ted.user_id}`, // Ted Smith
];
assert.deepEqual(suggestions, expected);
@@ -224,14 +225,14 @@ test("dm_suggestions", ({override}) => {
query = "is:private";
suggestions = get_suggestions(query);
- // Same search suggestions as for "is:dm"
+ // Same search suggestions and order as for "is:dm".
expected = [
"is:dm",
- `dm:${alice.user_id}`,
- `dm:${bob.user_id}`,
- `dm:${jeff.user_id}`,
- `dm:${me.user_id}`,
- `dm:${ted.user_id}`,
+ `dm:${alice.user_id}`, // Alice Ignore
+ `dm:${bob.user_id}`, // Bob Roberts
+ `dm:${jeff.user_id}`, // Jeff Zoolipson
+ `dm:${me.user_id}`, // Me Myself
+ `dm:${ted.user_id}`, // Ted Smith
];
assert.deepEqual(suggestions, expected);
@@ -1028,10 +1029,11 @@ test("people_suggestions", ({override}) => {
let suggestions = get_suggestions(query);
+ // Both match "te"; alphabetical tiebreaker: Bob Térry < Ted Smith.
let expected = [
"te",
- `dm:${bob.user_id}`, // bob térry
- `dm:${ted.user_id}`,
+ `dm:${bob.user_id}`, // Bob Térry
+ `dm:${ted.user_id}`, // Ted Smith
`sender:${bob.user_id}`,
`sender:${ted.user_id}`,
`dm-including:${bob.user_id}`,
@@ -1050,11 +1052,12 @@ test("people_suggestions", ({override}) => {
people.add_active_user(accessible_user, "server_events");
suggestions = get_suggestions(query);
+ // Same order with Test unknown user added last (alphabetical).
expected = [
"te",
- `dm:${bob.user_id}`,
- `dm:${ted.user_id}`,
- `dm:${inaccessible_user.user_id}`,
+ `dm:${bob.user_id}`, // Bob Térry
+ `dm:${ted.user_id}`, // Ted Smith
+ `dm:${inaccessible_user.user_id}`, // Test unknown user
`sender:${bob.user_id}`,
`sender:${ted.user_id}`,
`sender:${inaccessible_user.user_id}`,