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.

composebox_typeahead: Test existing channel-link selection behavior.

Shubham Padia54fc0eca3165
diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjs
index 9ac05043f54..a23560412df 100644
--- a/web/tests/composebox_typeahead.test.cjs
+++ b/web/tests/composebox_typeahead.test.cjs
@@ -737,6 +737,18 @@ const broken_link_stream = stream_item(
can_create_topic_group: members.id,
}),
);
+const empty_topic_only_stream = stream_item(
+ make_stream({
+ name: "Announce",
+ description: "A channel that only allows the empty topic",
+ stream_id: 7,
+ subscribed: true,
+ topics_policy: "empty_topic_only",
+ can_administer_channel_group: support.id,
+ can_add_subscribers_group: support.id,
+ can_create_topic_group: members.id,
+ }),
+);
stream_data.add_sub_for_tests(sweden_stream);
stream_data.add_sub_for_tests(denmark_stream);
@@ -744,6 +756,7 @@ stream_data.add_sub_for_tests(netherland_stream);
stream_data.add_sub_for_tests(mobile_stream);
stream_data.add_sub_for_tests(mobile_team_stream);
stream_data.add_sub_for_tests(broken_link_stream);
+stream_data.add_sub_for_tests(empty_topic_only_stream);
const make_emoji = (emoji_dict) => ({
emoji_name: emoji_dict.name,
@@ -1139,7 +1152,11 @@ test("content_typeahead_selected", ({override}) => {
ct.get_or_set_completing_for_tests("stream");
let warned_for_stream_link = false;
override(compose_validate, "warn_if_private_stream_is_linked", (linked_stream) => {
- assert.ok(linked_stream === sweden_stream || linked_stream === broken_link_stream);
+ assert.ok(
+ linked_stream === sweden_stream ||
+ linked_stream === broken_link_stream ||
+ linked_stream === empty_topic_only_stream,
+ );
warned_for_stream_link = true;
});
@@ -1173,6 +1190,25 @@ test("content_typeahead_selected", ({override}) => {
expected_value = "[#A* Algorithm](#narrow/channel/6-A.2A-Algorithm)>";
assert.equal(actual_value, expected_value);
+ // A channel that only allows the empty topic gets a complete channel
+ // link, and no topic typeahead is reopened for it.
+ query = "#Announ";
+ ct.get_or_set_token_for_testing("Announ");
+ actual_value = ct.content_typeahead_selected(empty_topic_only_stream, query, input_element);
+ expected_value = "#**Announce**";
+ assert.equal(actual_value, expected_value);
+
+ // Pressing ">" on such a channel still opens topic completion via the
+ // partial syntax, for the user who explicitly wants a topic link.
+ query = "#Announ";
+ ct.get_or_set_token_for_testing("Announ");
+ actual_value = ct.content_typeahead_selected(empty_topic_only_stream, query, input_element, {
+ type: "keydown",
+ key: ">",
+ });
+ expected_value = "#**Announce>";
+ assert.equal(actual_value, expected_value);
+
// topic_list
ct.get_or_set_completing_for_tests("topic_list");
@@ -1326,6 +1362,94 @@ test("content_typeahead_selected", ({override}) => {
"Hello [#A* Algorithm > fast](#narrow/channel/6-A.2A-Algorithm/topic/fast) ";
assert.equal(actual_value, expected_value);
+ // Selecting a topic from the complete channel link form (the link
+ // inserted on channel selection, followed by the partially typed
+ // topic) rewrites the whole span into the full stream+topic link.
+ query = "Hello #**Sweden**plan";
+ ct.get_or_set_token_for_testing("plan");
+ actual_value = ct.content_typeahead_selected(
+ {
+ topic: "planning",
+ topic_display_name: "planning",
+ type: "topic_list",
+ used_syntax_prefix: "#**",
+ is_channel_link: false,
+ stream_data: {
+ name: "Sweden",
+ },
+ },
+ query,
+ input_element,
+ );
+ expected_value = "Hello #**Sweden>planning** ";
+ assert.equal(actual_value, expected_value);
+
+ // The same, but for the complete fallback markdown link form used
+ // for channel names with special characters.
+ query = "Hello [#A* Algorithm](#narrow/channel/6-A.2A-Algorithm)fas";
+ ct.get_or_set_token_for_testing("fas");
+ actual_value = ct.content_typeahead_selected(
+ {
+ topic: "fast",
+ topic_display_name: "fast",
+ type: "topic_list",
+ used_syntax_prefix: "[#",
+ is_channel_link: false,
+ stream_data: {
+ name: "A* Algorithm",
+ },
+ },
+ query,
+ input_element,
+ );
+ expected_value =
+ "Hello [#A* Algorithm > fast](#narrow/channel/6-A.2A-Algorithm/topic/fast) ";
+ assert.equal(actual_value, expected_value);
+
+ // Selecting the "(link to channel)" option from the complete link
+ // form keeps the channel link as-is, dropping any partially typed
+ // topic text.
+ query = "Hello #**Sweden**plan";
+ ct.get_or_set_token_for_testing("plan");
+ actual_value = ct.content_typeahead_selected(
+ {
+ topic: "Sweden",
+ topic_display_name: "Sweden",
+ type: "topic_list",
+ used_syntax_prefix: "#**",
+ is_channel_link: true,
+ stream_data: {
+ name: "Sweden",
+ },
+ },
+ query,
+ input_element,
+ );
+ expected_value = "Hello #**Sweden** ";
+ assert.equal(actual_value, expected_value);
+
+ // Escape resolves the partial stream+topic syntax to a channel
+ // link, keeping any partially typed topic as plain text.
+ query = "Hello #**Sweden>plan";
+ ct.get_or_set_token_for_testing("plan");
+ actual_value = ct.content_typeahead_selected(
+ {
+ topic: "planning",
+ topic_display_name: "planning",
+ type: "topic_list",
+ used_syntax_prefix: "#**",
+ is_channel_link: false,
+ stream_data: {
+ name: "Sweden",
+ },
+ },
+ query,
+ input_element,
+ {key: "Escape"},
+ );
+ expected_value = "Hello #**Sweden** plan";
+ assert.equal(actual_value, expected_value);
+
// syntax
ct.get_or_set_completing_for_tests("syntax");
@@ -2789,6 +2913,25 @@ test("begins_typeahead", ({override, override_rewire}) => {
);
assert_typeahead_equals("#**Sweden>\n\nmore ice", typed_topics("Sweden", []));
+ // A complete channel link is a valid final form, so it only triggers
+ // topic completion while the typeahead is already open (the state
+ // right after a channel is selected). With the typeahead closed, the
+ // cursor merely sitting after a channel link offers nothing.
+ assert_typeahead_equals("#**Sweden**", []);
+
+ // The complete channel link inserted on channel selection reopens the
+ // topic typeahead, so the user can still pick a topic; selecting one
+ // rewrites the link into the partial-then-completed form. Typing after
+ // the link filters topics just like the `>` syntax does.
+ compose_ui.compose_textarea_typeahead = {shown: true};
+ // A space immediately after the complete link means the user has
+ // moved on to the message body, so no topic typeahead is offered.
+ assert_typeahead_equals("#**Sweden** more ice", []);
+ // A channel that only allows the empty topic gets a complete channel
+ // link with no topic completion offered.
+ assert_typeahead_equals("#**Announce**", []);
+ compose_ui.compose_textarea_typeahead = undefined;
+
// time_jump
const time_jump = [
{