`,
);
});
run_test("urls", () => {
people.add_active_user(ray);
people.add_active_user(alice);
people.add_active_user(me);
people.initialize_current_user(me.user_id);
let url = hash_util.pm_with_url(ray.email);
assert.equal(url, "#narrow/dm/22-Raymond");
url = hash_util.huddle_with_url("22,23");
assert.equal(url, "#narrow/dm/22,23-group");
url = hash_util.by_sender_url(ray.email);
assert.equal(url, "#narrow/sender/22-Raymond");
let emails = hash_util.decode_operand("dm", "22,23-group");
assert.equal(emails, "alice@example.com,ray@example.com");
emails = hash_util.decode_operand("dm", "5,22,23-group");
assert.equal(emails, "alice@example.com,ray@example.com");
emails = hash_util.decode_operand("dm", "5-group");
assert.equal(emails, "me@example.com");
// Even though we renamed "pm-with" to "dm", preexisting
// links/URLs with "pm-with" operator are decoded correctly.
emails = hash_util.decode_operand("pm-with", "22,23-group");
assert.equal(emails, "alice@example.com,ray@example.com");
emails = hash_util.decode_operand("pm-with", "5,22,23-group");
assert.equal(emails, "alice@example.com,ray@example.com");
emails = hash_util.decode_operand("pm-with", "5-group");
assert.equal(emails, "me@example.com");
});
run_test("show_empty_narrow_message", ({mock_template}) => {
page_params.stop_words = [];
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
narrow_state.reset_current_filter();
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: There are no messages here.",
'translated HTML: Why not start the conversation?',
),
);
// for non-existent or private stream
set_filter([["stream", "Foo"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: This stream does not exist or is private."),
);
// for non-subbed public stream
stream_data.add_sub({name: "ROME", stream_id: 99});
set_filter([["stream", "Rome"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You aren't subscribed to this stream and nobody has talked about that yet!",
'translated HTML: ',
),
);
// for non-web-public stream for spectator
page_params.is_spectator = true;
set_filter([["stream", "Rome"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"",
'translated HTML: This is not a publicly accessible conversation.',
),
);
set_filter([
["stream", "Rome"],
["topic", "foo"],
]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"",
'translated HTML: This is not a publicly accessible conversation.',
),
);
// for web-public stream for spectator
stream_data.add_sub({name: "web-public-stream", stream_id: 1231, is_web_public: true});
set_filter([
["stream", "web-public-stream"],
["topic", "foo"],
]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: There are no messages here."),
);
page_params.is_spectator = false;
set_filter([["is", "starred"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no starred messages.",
'translated HTML: Learn more about starring messages here.',
),
);
set_filter([["is", "mentioned"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You haven't been mentioned yet!",
'translated HTML: Learn more about mentions here.',
),
);
// organization has disabled sending direct messages
page_params.realm_private_message_policy =
settings_config.private_message_policy_values.disabled.code;
set_filter([["is", "dm"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You are not allowed to send direct messages in this organization.",
),
);
// sending direct messages enabled
page_params.realm_private_message_policy =
settings_config.private_message_policy_values.by_anyone.code;
set_filter([["is", "dm"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no direct messages yet!",
'translated HTML: Why not start the conversation?',
),
);
set_filter([["is", "unread"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You have no unread messages!"),
);
set_filter([["is", "resolved"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: No topics are marked as resolved."),
);
// organization has disabled sending direct messages
page_params.realm_private_message_policy =
settings_config.private_message_policy_values.disabled.code;
// prioritize information about invalid user(s) in narrow/search
set_filter([["dm", ["Yo"]]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: This user does not exist!"),
);
people.add_active_user(alice);
set_filter([["dm", ["alice@example.com", "Yo"]]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: One or more of these users do not exist!"),
);
set_filter([["dm", "alice@example.com"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You are not allowed to send direct messages in this organization.",
),
);
// direct messages with a bot are possible even though
// the organization has disabled sending direct messages
people.add_active_user(bot);
set_filter([["dm", "bot@example.com"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no direct messages with Example Bot yet.",
'translated HTML: Why not start the conversation?',
),
);
// group direct messages with bots are not possible when
// sending direct messages is disabled
set_filter([["dm", bot.email + "," + alice.email]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You are not allowed to send direct messages in this organization.",
),
);
// sending direct messages enabled
page_params.realm_private_message_policy =
settings_config.private_message_policy_values.by_anyone.code;
set_filter([["dm", "alice@example.com"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no direct messages with Alice Smith yet.",
'translated HTML: Why not start the conversation?',
),
);
people.add_active_user(me);
people.initialize_current_user(me.user_id);
set_filter([["dm", me.email]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have not sent any direct messages to yourself yet!",
'translated HTML: Why not start a conversation with yourself?',
),
);
set_filter([["dm", me.email + "," + alice.email]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no direct messages with these users yet.",
'translated HTML: Why not start the conversation?',
),
);
// organization has disabled sending direct messages
page_params.realm_private_message_policy =
settings_config.private_message_policy_values.disabled.code;
// prioritize information about invalid user in narrow/search
set_filter([["dm-including", ["Yo"]]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: This user does not exist!"),
);
set_filter([["dm-including", "alice@example.com"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You are not allowed to send direct messages in this organization.",
),
);
// direct messages with a bot are possible even though
// the organization has disabled sending direct messages
set_filter([["dm-including", "bot@example.com"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You have no direct messages including Example Bot yet."),
);
// sending direct messages enabled
page_params.realm_private_message_policy =
settings_config.private_message_policy_values.by_anyone.code;
set_filter([["dm-including", "alice@example.com"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You have no direct messages including Alice Smith yet."),
);
set_filter([["dm-including", me.email]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You don't have any direct message conversations yet."),
);
set_filter([["sender", "ray@example.com"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You haven't received any messages sent by Raymond yet."),
);
set_filter([["sender", "sinwar@example.com"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: This user does not exist!"),
);
set_filter([
["sender", "alice@example.com"],
["stream", "Rome"],
]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: No search results."),
);
set_filter([["is", "invalid"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: There are no messages here.",
'translated HTML: Why not start the conversation?',
),
);
const my_stream = {
name: "my stream",
stream_id: 103,
};
stream_data.add_sub(my_stream);
stream_data.subscribe_myself(my_stream);
set_filter([["stream", "my stream"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: There are no messages here.",
'translated HTML: Why not start the conversation?',
),
);
set_filter([["stream", ""]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: This stream does not exist or is private."),
);
});
run_test("show_empty_narrow_message_with_search", ({mock_template}) => {
page_params.stop_words = [];
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
narrow_state.reset_current_filter();
set_filter([["search", "grail"]]);
narrow_banner.show_empty_narrow_message();
assert.match($(".empty_feed_notice_main").html(), /grail<\/span>/);
});
run_test("hide_empty_narrow_message", () => {
narrow_banner.hide_empty_narrow_message();
assert.equal($(".empty_feed_notice").text(), "never-been-set");
});
run_test("show_search_stopwords", ({mock_template}) => {
page_params.stop_words = ["what", "about"];
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
const expected_search_data = {
has_stop_word: true,
query_words: [
{query_word: "what", is_stop_word: true},
{query_word: "about", is_stop_word: true},
{query_word: "grail", is_stop_word: false},
],
};
narrow_state.reset_current_filter();
set_filter([["search", "what about grail"]]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: No search results.", undefined, expected_search_data),
);
const expected_stream_search_data = {
has_stop_word: true,
stream_query: "streamA",
query_words: [
{query_word: "what", is_stop_word: true},
{query_word: "about", is_stop_word: true},
{query_word: "grail", is_stop_word: false},
],
};
set_filter([
["stream", "streamA"],
["search", "what about grail"],
]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: No search results.", undefined, expected_stream_search_data),
);
const expected_stream_topic_search_data = {
has_stop_word: true,
stream_query: "streamA",
topic_query: "topicA",
query_words: [
{query_word: "what", is_stop_word: true},
{query_word: "about", is_stop_word: true},
{query_word: "grail", is_stop_word: false},
],
};
set_filter([
["stream", "streamA"],
["topic", "topicA"],
["search", "what about grail"],
]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: No search results.",
undefined,
expected_stream_topic_search_data,
),
);
});
run_test("show_invalid_narrow_message", ({mock_template}) => {
narrow_state.reset_current_filter();
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
stream_data.add_sub({name: "streamA", stream_id: 88});
stream_data.add_sub({name: "streamB", stream_id: 77});
set_filter([
["stream", "streamA"],
["stream", "streamB"],
]);
narrow_banner.show_empty_narrow_message();
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: No search results.",
"translated HTML:
You are searching for messages that belong to more than one stream, which is not possible.