2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2022-08-19 21:36:33 +02:00
|
|
|
const {mock_banners} = require("./lib/compose_banner");
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2024-07-08 19:00:08 +02:00
|
|
|
const blueslip = require("./lib/zblueslip");
|
2023-02-22 23:04:10 +01:00
|
|
|
const $ = require("./lib/zjquery");
|
2024-02-13 02:08:24 +01:00
|
|
|
const {realm} = require("./lib/zpage_params");
|
2022-08-19 21:36:33 +02:00
|
|
|
|
2024-07-08 19:00:08 +02:00
|
|
|
const user_groups = zrequire("user_groups");
|
|
|
|
|
|
|
|
const nobody = {
|
|
|
|
name: "role:nobody",
|
|
|
|
id: 1,
|
|
|
|
members: new Set([]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
};
|
|
|
|
const everyone = {
|
|
|
|
name: "role:everyone",
|
|
|
|
id: 2,
|
|
|
|
members: new Set([30]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
};
|
|
|
|
user_groups.initialize({realm_user_groups: [nobody, everyone]});
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("document", {
|
2020-12-01 23:21:38 +01:00
|
|
|
to_$: () => $("document-stub"),
|
2017-04-14 15:06:13 +02:00
|
|
|
});
|
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
const autosize = noop;
|
|
|
|
autosize.update = noop;
|
2023-03-06 04:20:23 +01:00
|
|
|
mock_esm("autosize", {default: autosize});
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const channel = mock_esm("../src/channel");
|
|
|
|
const compose_fade = mock_esm("../src/compose_fade", {
|
2021-03-07 13:57:14 +01:00
|
|
|
clear_compose: noop,
|
2023-03-31 06:27:36 +02:00
|
|
|
set_focused_recipient: noop,
|
|
|
|
update_all: noop,
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-09-05 01:31:49 +02:00
|
|
|
const compose_pm_pill = mock_esm("../src/compose_pm_pill", {
|
|
|
|
get_user_ids_string: () => "",
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const compose_ui = mock_esm("../src/compose_ui", {
|
2022-07-10 01:06:33 +02:00
|
|
|
autosize_textarea: noop,
|
2024-06-12 01:01:10 +02:00
|
|
|
is_expanded: () => false,
|
2023-04-27 23:45:30 +02:00
|
|
|
set_focus: noop,
|
2023-05-07 14:45:04 +02:00
|
|
|
compute_placeholder_text: noop,
|
2022-07-10 01:06:33 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const hash_util = mock_esm("../src/hash_util");
|
|
|
|
const narrow_state = mock_esm("../src/narrow_state", {
|
2021-03-07 13:57:14 +01:00
|
|
|
set_compose_defaults: noop,
|
2023-11-03 04:20:28 +01:00
|
|
|
filter: noop,
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-01-08 21:09:41 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/reload_state", {
|
2021-03-06 17:37:51 +01:00
|
|
|
is_in_progress: () => false,
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/drafts", {
|
2020-12-01 23:21:38 +01:00
|
|
|
update_draft: noop,
|
2024-02-07 08:14:58 +01:00
|
|
|
update_compose_draft_count: noop,
|
2024-03-30 04:59:19 +01:00
|
|
|
get_last_restorable_draft_based_on_compose_state: noop,
|
2024-05-07 19:15:04 +02:00
|
|
|
set_compose_draft_id: noop,
|
2020-12-01 23:21:38 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/unread_ops", {
|
2020-12-01 23:21:38 +01:00
|
|
|
notify_server_message_read: noop,
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/message_lists", {
|
2021-03-30 02:21:21 +02:00
|
|
|
current: {
|
|
|
|
can_mark_messages_read: () => true,
|
2020-12-01 23:21:38 +01:00
|
|
|
},
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/resize", {
|
2022-02-02 06:06:56 +01:00
|
|
|
reset_compose_message_max_height: noop,
|
compose-box: Fix compose-box from covering last messages of stream.
While writing a long message in compose-box, the last few messages of
the current stream gets covered by the compose-box and it gets pretty
annoying sometimes trying to figure out a way to read the last message
of the stream while writing. Right now, the only way to get past this
is to resize `compose-textarea` by using the resize tool at the
bottom-right corner of the `compose-textarea`. But, that small resize
tool is not always readily visible to the user.
The proposed solution in this commit is to reset the `max-height`
property of `#compose-textarea` everytime `bottom_whitespace_height`
is resized such that the total height of `#compose` is always less
than or equal to the height of `bottom_whitespace_height`. Doing
this, the compose-box never covers the last message of the current
stream.
The only problem with this is that if the compose-box is closed at the
time of bottom-whitespace resize, we cannot find the
`compose_non_textarea_height` and so, we cannot reset the max-height
of `#compose-textarea`. To solve this, max-height of
`compose-textarea` is also reset everytime a new compose-box is opened
according to the value of `bottom_whitespace_height` at that time.
Thus, if the compose-box is already open at the time of
bottom-whitespace resize, the max-height of `#compose-textarea` will
also get reset at the same time, whereas, if the compose-box is closed
at the time of bottom-whitespace resize, the max-height of
`#compose-textarea` won't get reset at that time, but it will surely
get reset whenever the user will open the compose-box.
Tested on my Ubuntu Development Environment on Chrome and Firefox browsers.
Fixes: #16038.
2021-01-18 14:23:29 +01:00
|
|
|
});
|
2023-10-23 04:23:05 +02:00
|
|
|
mock_esm("../src/popovers", {
|
|
|
|
hide_all: noop,
|
|
|
|
});
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = zrequire("people");
|
2021-03-06 17:37:51 +01:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const compose_state = zrequire("compose_state");
|
|
|
|
const compose_actions = zrequire("compose_actions");
|
2023-10-06 01:43:50 +02:00
|
|
|
const compose_reply = zrequire("compose_reply");
|
2021-03-30 02:21:21 +02:00
|
|
|
const message_lists = zrequire("message_lists");
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
2023-03-31 06:27:36 +02:00
|
|
|
const compose_recipient = zrequire("compose_recipient");
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const start = compose_actions.start;
|
|
|
|
const cancel = compose_actions.cancel;
|
2023-10-06 01:43:50 +02:00
|
|
|
const respond_to_message = compose_reply.respond_to_message;
|
|
|
|
const reply_with_mention = compose_reply.reply_with_mention;
|
|
|
|
const quote_and_reply = compose_reply.quote_and_reply;
|
2017-04-14 15:06:13 +02:00
|
|
|
|
|
|
|
function assert_visible(sel) {
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($(sel).visible());
|
2017-04-14 15:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function assert_hidden(sel) {
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$(sel).visible());
|
2017-04-14 15:06:13 +02:00
|
|
|
}
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
function override_private_message_recipient({override}) {
|
|
|
|
let recipient;
|
|
|
|
override(compose_pm_pill, "set_from_emails", (value) => {
|
|
|
|
recipient = value;
|
|
|
|
});
|
|
|
|
override(compose_pm_pill, "get_emails", () => recipient, {unused: false});
|
2021-03-13 19:26:32 +01:00
|
|
|
}
|
|
|
|
|
2021-03-14 15:37:38 +01:00
|
|
|
function test(label, f) {
|
2022-07-09 23:25:05 +02:00
|
|
|
run_test(label, (helpers) => {
|
2021-06-04 19:27:45 +02:00
|
|
|
// We don't test the css calls; we just skip over them.
|
2023-12-14 23:51:33 +01:00
|
|
|
$("#compose").css = noop;
|
|
|
|
$(".new_message_textarea").css = noop;
|
2021-06-04 19:27:45 +02:00
|
|
|
|
2021-03-14 15:37:38 +01:00
|
|
|
people.init();
|
2024-01-07 23:28:42 +01:00
|
|
|
compose_state.set_message_type(undefined);
|
2022-07-09 23:25:05 +02:00
|
|
|
f(helpers);
|
2021-03-14 15:37:38 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
test("initial_state", () => {
|
2017-04-15 01:15:59 +02:00
|
|
|
assert.equal(compose_state.composing(), false);
|
2024-01-07 23:28:42 +01:00
|
|
|
assert.equal(compose_state.get_message_type(), undefined);
|
2017-04-15 01:15:59 +02:00
|
|
|
assert.equal(compose_state.has_message_content(), false);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-15 01:15:59 +02:00
|
|
|
|
2023-05-07 14:45:04 +02:00
|
|
|
test("start", ({override, override_rewire, mock_template}) => {
|
2022-08-19 21:36:33 +02:00
|
|
|
mock_banners();
|
2022-07-10 01:06:33 +02:00
|
|
|
override_private_message_recipient({override});
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(compose_actions, "autosize_message_content", noop);
|
|
|
|
override_rewire(compose_actions, "expand_compose_box", noop);
|
|
|
|
override_rewire(compose_actions, "complete_starting_tasks", noop);
|
|
|
|
override_rewire(compose_actions, "blur_compose_inputs", noop);
|
|
|
|
override_rewire(compose_actions, "clear_textarea", noop);
|
|
|
|
override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);
|
|
|
|
override_rewire(compose_recipient, "check_posting_policy_for_compose_box", noop);
|
|
|
|
mock_template("inline_decorated_stream_name.hbs", false, noop);
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
let compose_defaults;
|
|
|
|
override(narrow_state, "set_compose_defaults", () => compose_defaults);
|
2024-08-13 11:12:10 +02:00
|
|
|
override(
|
|
|
|
compose_ui,
|
|
|
|
"insert_and_scroll_into_view",
|
|
|
|
(content, $textarea, replace_all, replace_all_without_undo_support) => {
|
|
|
|
$textarea.val(content);
|
|
|
|
assert.ok(!replace_all);
|
|
|
|
assert.ok(replace_all_without_undo_support);
|
|
|
|
},
|
|
|
|
);
|
2021-02-24 13:30:27 +01:00
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
// Start stream message
|
2021-02-24 13:30:27 +01:00
|
|
|
compose_defaults = {
|
2023-09-26 20:28:39 +02:00
|
|
|
stream_id: undefined,
|
2021-02-24 13:30:27 +01:00
|
|
|
topic: "topic1",
|
2017-04-14 15:06:13 +02:00
|
|
|
};
|
|
|
|
|
2024-04-04 02:38:16 +02:00
|
|
|
let opts = {
|
|
|
|
message_type: "stream",
|
|
|
|
};
|
|
|
|
start(opts);
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2023-10-03 18:18:55 +02:00
|
|
|
assert_visible("#compose_recipient_box");
|
2023-04-15 03:35:23 +02:00
|
|
|
assert_hidden("#compose-direct-recipient");
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2023-05-07 14:45:04 +02:00
|
|
|
assert.equal(compose_state.stream_name(), "");
|
2022-10-27 00:30:06 +02:00
|
|
|
assert.equal(compose_state.topic(), "topic1");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(compose_state.get_message_type(), "stream");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_state.composing());
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2019-07-27 08:12:14 +02:00
|
|
|
// Autofill stream field for single subscription
|
2019-11-02 00:06:25 +01:00
|
|
|
const denmark = {
|
2019-07-27 08:12:14 +02:00
|
|
|
subscribed: true,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
|
|
|
name: "Denmark",
|
2019-07-27 08:12:14 +02:00
|
|
|
stream_id: 1,
|
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(denmark);
|
2019-07-27 08:12:14 +02:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
compose_defaults = {
|
2023-10-03 21:43:55 +02:00
|
|
|
trigger: "clear topic button",
|
2019-07-27 08:12:14 +02:00
|
|
|
};
|
|
|
|
|
2024-04-04 02:38:16 +02:00
|
|
|
opts = {
|
|
|
|
message_type: "stream",
|
|
|
|
};
|
|
|
|
start(opts);
|
2022-10-27 00:30:06 +02:00
|
|
|
assert.equal(compose_state.stream_name(), "Denmark");
|
|
|
|
assert.equal(compose_state.topic(), "");
|
2019-07-27 08:12:14 +02:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
compose_defaults = {
|
|
|
|
trigger: "compose_hotkey",
|
2019-07-27 08:12:14 +02:00
|
|
|
};
|
|
|
|
|
2024-04-04 02:38:16 +02:00
|
|
|
opts = {
|
|
|
|
message_type: "stream",
|
|
|
|
};
|
|
|
|
start(opts);
|
2022-10-27 00:30:06 +02:00
|
|
|
assert.equal(compose_state.stream_name(), "Denmark");
|
|
|
|
assert.equal(compose_state.topic(), "");
|
2019-07-27 08:12:14 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const social = {
|
2019-07-27 08:12:14 +02:00
|
|
|
subscribed: true,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "red",
|
|
|
|
name: "social",
|
2019-07-27 08:12:14 +02:00
|
|
|
stream_id: 2,
|
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(social);
|
2019-07-27 08:12:14 +02:00
|
|
|
|
2023-06-27 01:40:25 +02:00
|
|
|
compose_state.set_stream_id("");
|
2019-07-27 08:12:14 +02:00
|
|
|
// More than 1 subscription, do not autofill
|
2024-04-04 02:38:16 +02:00
|
|
|
opts = {
|
|
|
|
message_type: "stream",
|
|
|
|
};
|
|
|
|
start(opts);
|
2022-10-27 00:30:06 +02:00
|
|
|
assert.equal(compose_state.stream_name(), "");
|
|
|
|
assert.equal(compose_state.topic(), "");
|
2019-07-27 08:12:14 +02:00
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
|
2023-06-16 17:37:19 +02:00
|
|
|
// Start direct message
|
2021-02-24 13:30:27 +01:00
|
|
|
compose_defaults = {
|
|
|
|
private_message_recipient: "foo@example.com",
|
2017-04-14 15:06:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
opts = {
|
2024-04-04 02:38:16 +02:00
|
|
|
message_type: "private",
|
2020-07-15 01:29:15 +02:00
|
|
|
content: "hello",
|
2017-04-14 15:06:13 +02:00
|
|
|
};
|
2017-06-14 20:28:55 +02:00
|
|
|
|
2024-04-04 02:38:16 +02:00
|
|
|
start(opts);
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2023-11-02 19:29:54 +01:00
|
|
|
assert_hidden("input#stream_message_recipient_topic");
|
2023-04-15 03:35:23 +02:00
|
|
|
assert_visible("#compose-direct-recipient");
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(compose_state.private_message_recipient(), "foo@example.com");
|
2023-11-02 19:29:54 +01:00
|
|
|
assert.equal($("textarea#compose-textarea").val(), "hello");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(compose_state.get_message_type(), "private");
|
2021-07-05 11:48:15 +02:00
|
|
|
assert.ok(compose_state.composing());
|
|
|
|
|
2023-06-16 11:56:47 +02:00
|
|
|
// Triggered by new direct message
|
2021-07-05 11:48:15 +02:00
|
|
|
opts = {
|
2024-04-04 02:38:16 +02:00
|
|
|
message_type: "private",
|
2023-06-16 11:56:47 +02:00
|
|
|
trigger: "new direct message",
|
2021-07-05 11:48:15 +02:00
|
|
|
};
|
|
|
|
|
2024-04-04 02:38:16 +02:00
|
|
|
start(opts);
|
2021-07-05 11:48:15 +02:00
|
|
|
|
|
|
|
assert.equal(compose_state.private_message_recipient(), "");
|
|
|
|
assert.equal(compose_state.get_message_type(), "private");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_state.composing());
|
2017-04-14 15:06:13 +02:00
|
|
|
|
|
|
|
// Cancel compose.
|
2019-11-02 00:06:25 +01:00
|
|
|
let pill_cleared;
|
2021-02-23 14:37:26 +01:00
|
|
|
compose_pm_pill.clear = () => {
|
2018-03-06 15:07:55 +01:00
|
|
|
pill_cleared = true;
|
|
|
|
};
|
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
let abort_xhr_called = false;
|
2024-03-15 21:51:16 +01:00
|
|
|
compose_actions.register_compose_cancel_hook(() => {
|
2019-11-21 05:24:55 +01:00
|
|
|
abort_xhr_called = true;
|
2021-02-28 00:51:57 +01:00
|
|
|
});
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").set_height(50);
|
2021-02-08 16:27:29 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_hidden("#compose_controls");
|
2017-04-14 15:06:13 +02:00
|
|
|
cancel();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(abort_xhr_called);
|
|
|
|
assert.ok(pill_cleared);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_visible("#compose_controls");
|
2023-04-15 03:35:23 +02:00
|
|
|
assert_hidden("#compose-direct-recipient");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!compose_state.composing());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-14 16:26:00 +02:00
|
|
|
|
2023-05-07 14:45:04 +02:00
|
|
|
test("respond_to_message", ({override, override_rewire, mock_template}) => {
|
2022-08-19 21:36:33 +02:00
|
|
|
mock_banners();
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(compose_actions, "complete_starting_tasks", noop);
|
|
|
|
override_rewire(compose_actions, "clear_textarea", noop);
|
2023-04-15 03:35:23 +02:00
|
|
|
override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);
|
2023-05-12 23:48:00 +02:00
|
|
|
override_rewire(compose_recipient, "check_posting_policy_for_compose_box", noop);
|
2022-07-10 01:06:33 +02:00
|
|
|
override_private_message_recipient({override});
|
2023-12-14 23:51:33 +01:00
|
|
|
mock_template("inline_decorated_stream_name.hbs", false, noop);
|
2021-03-13 19:26:32 +01:00
|
|
|
|
2023-06-16 17:37:19 +02:00
|
|
|
// Test direct message
|
2019-11-02 00:06:25 +01:00
|
|
|
const person = {
|
2017-04-14 19:24:43 +02:00
|
|
|
user_id: 22,
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@example.com",
|
|
|
|
full_name: "Alice",
|
2017-04-14 19:24:43 +02:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(person);
|
2017-04-14 19:24:43 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let msg = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2017-04-14 19:24:43 +02:00
|
|
|
sender_id: person.user_id,
|
|
|
|
};
|
2023-10-05 22:50:01 +02:00
|
|
|
override(message_lists.current, "get", (id) => (id === 100 ? msg : undefined));
|
2017-04-14 19:24:43 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let opts = {
|
2020-07-15 01:29:15 +02:00
|
|
|
reply_type: "personal",
|
2023-10-05 22:50:01 +02:00
|
|
|
message_id: 100,
|
2017-04-14 19:24:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
respond_to_message(opts);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(compose_state.private_message_recipient(), "alice@example.com");
|
2017-04-14 19:24:43 +02:00
|
|
|
|
|
|
|
// Test stream
|
2023-05-07 14:45:04 +02:00
|
|
|
const denmark = {
|
|
|
|
subscribed: true,
|
|
|
|
color: "blue",
|
|
|
|
name: "Denmark",
|
|
|
|
stream_id: 1,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(denmark);
|
2023-06-27 01:40:25 +02:00
|
|
|
|
|
|
|
msg = {
|
|
|
|
type: "stream",
|
|
|
|
stream_id: denmark.stream_id,
|
|
|
|
topic: "python",
|
|
|
|
};
|
2023-10-05 22:50:01 +02:00
|
|
|
override(message_lists.current, "selected_message", () => msg);
|
2023-06-27 01:40:25 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
opts = {};
|
2017-04-14 19:24:43 +02:00
|
|
|
|
|
|
|
respond_to_message(opts);
|
2023-05-07 14:45:04 +02:00
|
|
|
assert.equal(compose_state.stream_name(), "Denmark");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-14 19:24:43 +02:00
|
|
|
|
2023-05-07 14:45:04 +02:00
|
|
|
test("reply_with_mention", ({override, override_rewire, mock_template}) => {
|
2022-08-19 21:36:33 +02:00
|
|
|
mock_banners();
|
2021-03-16 12:16:19 +01:00
|
|
|
compose_state.set_message_type("stream");
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);
|
|
|
|
override_rewire(compose_actions, "complete_starting_tasks", noop);
|
|
|
|
override_rewire(compose_actions, "clear_textarea", noop);
|
2022-07-10 01:06:33 +02:00
|
|
|
override_private_message_recipient({override});
|
2023-05-12 23:48:00 +02:00
|
|
|
override_rewire(compose_recipient, "check_posting_policy_for_compose_box", noop);
|
2023-12-14 23:51:33 +01:00
|
|
|
mock_template("inline_decorated_stream_name.hbs", false, noop);
|
2023-05-07 14:45:04 +02:00
|
|
|
|
|
|
|
const denmark = {
|
|
|
|
subscribed: true,
|
|
|
|
color: "blue",
|
|
|
|
name: "Denmark",
|
|
|
|
stream_id: 1,
|
|
|
|
};
|
|
|
|
stream_data.add_sub(denmark);
|
2021-03-13 19:26:32 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2023-06-27 01:40:25 +02:00
|
|
|
stream_id: denmark.stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "python",
|
|
|
|
sender_full_name: "Bob Roberts",
|
2018-10-13 02:03:43 +02:00
|
|
|
sender_id: 40,
|
2017-04-14 19:24:43 +02:00
|
|
|
};
|
2021-03-30 02:21:21 +02:00
|
|
|
override(message_lists.current, "selected_message", () => msg);
|
2017-04-14 19:24:43 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let syntax_to_insert;
|
2022-07-10 01:06:33 +02:00
|
|
|
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
2018-02-26 16:04:40 +01:00
|
|
|
syntax_to_insert = syntax;
|
2021-02-21 12:29:02 +01:00
|
|
|
});
|
2018-02-26 16:04:40 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const opts = {};
|
2017-04-14 19:24:43 +02:00
|
|
|
|
|
|
|
reply_with_mention(opts);
|
2023-05-07 14:45:04 +02:00
|
|
|
assert.equal(compose_state.stream_name(), "Denmark");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(syntax_to_insert, "@**Bob Roberts**");
|
2018-10-13 02:03:43 +02:00
|
|
|
|
|
|
|
// Test for extended mention syntax
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob_1 = {
|
2018-10-13 02:03:43 +02:00
|
|
|
user_id: 30,
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "bob1@example.com",
|
|
|
|
full_name: "Bob Roberts",
|
2018-10-13 02:03:43 +02:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(bob_1);
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob_2 = {
|
2018-10-13 02:03:43 +02:00
|
|
|
user_id: 40,
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "bob2@example.com",
|
|
|
|
full_name: "Bob Roberts",
|
2018-10-13 02:03:43 +02:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(bob_2);
|
2018-10-13 02:03:43 +02:00
|
|
|
|
|
|
|
reply_with_mention(opts);
|
2023-05-07 14:45:04 +02:00
|
|
|
assert.equal(compose_state.stream_name(), "Denmark");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(syntax_to_insert, "@**Bob Roberts|40**");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-14 16:26:00 +02:00
|
|
|
|
2022-07-09 23:25:05 +02:00
|
|
|
test("quote_and_reply", ({disallow, override, override_rewire}) => {
|
2023-08-04 23:40:48 +02:00
|
|
|
override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);
|
message_view: Allow quoting selected message text, via hotkey and menu.
Whenever the user has text selected within a single message, and uses
the hotkey to quote and reply, this selection will be quoted. In case of
no selection or selection not within a single message, the entirety of
the currently focused message will be quoted like before.
Similarly, when the user selects text within a single message, opens
that message's actions menu, and clicks the "Quote and reply" option,
the selected text will be quoted. In case of no selection or selection
containing any other message/s, the entirety of the message whose menu
was opened will be quoted like before.
When partially quoting a message, it is the markdown version of the
selection that is quoted, hence preserving any formatting. Any other
elements of the message, outside of the content, selected presumably by
accident (like the timestamp or sender name), are ignored.
Fixes: #19712.
2024-02-01 19:23:17 +01:00
|
|
|
override_rewire(compose_reply, "selection_within_message_id", () => undefined);
|
2024-07-08 19:00:08 +02:00
|
|
|
override(realm, "realm_direct_message_permission_group", nobody.id);
|
|
|
|
override(realm, "realm_direct_message_initiator_group", everyone.id);
|
2023-08-04 23:40:48 +02:00
|
|
|
|
2022-08-19 21:36:33 +02:00
|
|
|
mock_banners();
|
2021-03-16 12:16:19 +01:00
|
|
|
compose_state.set_message_type("stream");
|
2021-03-14 15:37:38 +01:00
|
|
|
const steve = {
|
|
|
|
user_id: 90,
|
|
|
|
email: "steve@example.com",
|
|
|
|
full_name: "Steve Stephenson",
|
|
|
|
};
|
|
|
|
people.add_active_user(steve);
|
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(compose_actions, "complete_starting_tasks", noop);
|
|
|
|
override_rewire(compose_actions, "clear_textarea", noop);
|
2022-07-10 01:06:33 +02:00
|
|
|
override_private_message_recipient({override});
|
2021-03-13 19:26:32 +01:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
let selected_message;
|
2023-10-05 23:30:37 +02:00
|
|
|
override(message_lists.current, "get", (id) => (id === 100 ? selected_message : undefined));
|
2021-02-24 13:30:27 +01:00
|
|
|
|
|
|
|
let expected_replacement;
|
|
|
|
let replaced;
|
2022-07-10 01:06:33 +02:00
|
|
|
override(compose_ui, "replace_syntax", (syntax, replacement) => {
|
2021-11-28 05:57:08 +01:00
|
|
|
assert.equal(syntax, "translated: [Quoting…]");
|
2021-02-24 13:30:27 +01:00
|
|
|
assert.equal(replacement, expected_replacement);
|
|
|
|
replaced = true;
|
|
|
|
});
|
|
|
|
|
2023-07-26 22:07:21 +02:00
|
|
|
const denmark_stream = {
|
|
|
|
subscribed: false,
|
|
|
|
name: "Denmark",
|
|
|
|
stream_id: 20,
|
|
|
|
};
|
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
selected_message = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_id: denmark_stream.stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "python",
|
2021-03-14 15:37:38 +01:00
|
|
|
sender_full_name: "Steve Stephenson",
|
|
|
|
sender_id: 90,
|
2018-11-01 23:43:29 +01:00
|
|
|
};
|
2022-03-01 19:14:26 +01:00
|
|
|
hash_util.by_conversation_and_time_url = () =>
|
2024-06-07 08:47:51 +02:00
|
|
|
"https://chat.zulip.org/#narrow/channel/92-learning/topic/Tornado";
|
2021-03-16 12:06:21 +01:00
|
|
|
|
|
|
|
let success_function;
|
|
|
|
override(channel, "get", (opts) => {
|
|
|
|
success_function = opts.success;
|
2019-08-26 08:10:46 +02:00
|
|
|
});
|
2018-11-01 23:43:29 +01:00
|
|
|
|
2023-06-29 21:59:08 +02:00
|
|
|
override(compose_ui, "insert_syntax_and_focus", (syntax, _$textarea, mode) => {
|
2023-01-30 12:05:09 +01:00
|
|
|
assert.equal(syntax, "translated: [Quoting…]");
|
|
|
|
assert.equal(mode, "block");
|
2021-02-28 01:26:48 +01:00
|
|
|
});
|
2018-11-01 23:43:29 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {
|
2020-07-15 01:29:15 +02:00
|
|
|
reply_type: "personal",
|
2023-10-05 23:30:37 +02:00
|
|
|
message_id: 100,
|
2018-11-01 23:43:29 +01:00
|
|
|
};
|
|
|
|
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").caret = noop;
|
2023-10-06 00:36:11 +02:00
|
|
|
$("textarea#compose-textarea").attr("id", "compose-textarea");
|
2019-01-16 16:29:18 +01:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
replaced = false;
|
2021-03-14 15:37:38 +01:00
|
|
|
expected_replacement =
|
2024-06-07 08:47:51 +02:00
|
|
|
"translated: @_**Steve Stephenson|90** [said](https://chat.zulip.org/#narrow/channel/92-learning/topic/Tornado):\n```quote\nTesting.\n```";
|
2021-02-24 13:30:27 +01:00
|
|
|
|
2018-11-01 23:43:29 +01:00
|
|
|
quote_and_reply(opts);
|
2021-03-16 12:06:21 +01:00
|
|
|
|
|
|
|
success_function({
|
|
|
|
raw_content: "Testing.",
|
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(replaced);
|
2018-11-11 19:36:26 +01:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
selected_message = {
|
2021-02-23 14:37:26 +01:00
|
|
|
type: "stream",
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_id: denmark_stream.stream_id,
|
2021-02-23 14:37:26 +01:00
|
|
|
topic: "test",
|
2021-03-14 15:37:38 +01:00
|
|
|
sender_full_name: "Steve Stephenson",
|
|
|
|
sender_id: 90,
|
2021-02-23 14:37:26 +01:00
|
|
|
raw_content: "Testing.",
|
2021-02-24 13:30:27 +01:00
|
|
|
};
|
2018-11-11 19:36:26 +01:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
replaced = false;
|
2022-07-09 23:25:05 +02:00
|
|
|
disallow(channel, "get");
|
|
|
|
quote_and_reply(opts);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(replaced);
|
2019-08-26 09:04:34 +02:00
|
|
|
|
2023-10-05 23:30:37 +02:00
|
|
|
delete opts.message_id;
|
|
|
|
override(message_lists.current, "selected_id", () => 100);
|
|
|
|
override(message_lists.current, "selected_message", () => selected_message);
|
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
selected_message = {
|
2021-02-23 14:37:26 +01:00
|
|
|
type: "stream",
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_id: denmark_stream.stream_id,
|
2021-02-23 14:37:26 +01:00
|
|
|
topic: "test",
|
2021-03-14 15:37:38 +01:00
|
|
|
sender_full_name: "Steve Stephenson",
|
|
|
|
sender_id: 90,
|
2021-02-23 14:37:26 +01:00
|
|
|
raw_content: "```\nmultiline code block\nshoudln't mess with quotes\n```",
|
2019-08-26 09:04:34 +02:00
|
|
|
};
|
2021-02-24 13:30:27 +01:00
|
|
|
|
|
|
|
replaced = false;
|
|
|
|
expected_replacement =
|
2024-06-07 08:47:51 +02:00
|
|
|
"translated: @_**Steve Stephenson|90** [said](https://chat.zulip.org/#narrow/channel/92-learning/topic/Tornado):\n````quote\n```\nmultiline code block\nshoudln't mess with quotes\n```\n````";
|
2019-08-26 09:04:34 +02:00
|
|
|
quote_and_reply(opts);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(replaced);
|
2018-11-01 23:43:29 +01:00
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("focus_in_empty_compose", () => {
|
2022-01-07 10:21:55 +01:00
|
|
|
document.activeElement = {id: "compose-textarea"};
|
2022-07-10 01:06:33 +02:00
|
|
|
compose_state.set_message_type("stream");
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_state.focus_in_empty_compose());
|
2017-09-18 21:54:06 +02:00
|
|
|
|
2024-01-07 23:28:42 +01:00
|
|
|
compose_state.set_message_type(undefined);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!compose_state.focus_in_empty_compose());
|
2017-09-18 21:54:06 +02:00
|
|
|
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("foo");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!compose_state.focus_in_empty_compose());
|
2017-09-18 21:54:06 +02:00
|
|
|
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").trigger("blur");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!compose_state.focus_in_empty_compose());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-05-28 12:17:42 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("on_narrow", ({override, override_rewire}) => {
|
2021-02-24 13:30:27 +01:00
|
|
|
let narrowed_by_topic_reply;
|
|
|
|
override(narrow_state, "narrowed_by_topic_reply", () => narrowed_by_topic_reply);
|
|
|
|
|
|
|
|
let narrowed_by_pm_reply;
|
|
|
|
override(narrow_state, "narrowed_by_pm_reply", () => narrowed_by_pm_reply);
|
|
|
|
|
2022-11-04 18:56:56 +01:00
|
|
|
const steve = {
|
|
|
|
user_id: 90,
|
|
|
|
email: "steve@example.com",
|
|
|
|
full_name: "Steve Stephenson",
|
|
|
|
is_bot: false,
|
|
|
|
};
|
|
|
|
people.add_active_user(steve);
|
|
|
|
|
|
|
|
const bot = {
|
|
|
|
user_id: 91,
|
|
|
|
email: "bot@example.com",
|
|
|
|
full_name: "Steve's bot",
|
|
|
|
is_bot: true,
|
|
|
|
};
|
|
|
|
people.add_active_user(bot);
|
|
|
|
|
2024-07-08 19:00:08 +02:00
|
|
|
user_groups.initialize({realm_user_groups: [nobody, everyone]});
|
2019-11-02 00:06:25 +01:00
|
|
|
let cancel_called = false;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(compose_actions, "cancel", () => {
|
2018-05-28 12:17:42 +02:00
|
|
|
cancel_called = true;
|
2021-02-28 21:32:22 +01:00
|
|
|
});
|
2018-05-28 12:17:42 +02:00
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: true,
|
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(cancel_called);
|
2018-05-28 12:17:42 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let on_topic_narrow_called = false;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(compose_actions, "on_topic_narrow", () => {
|
2018-05-28 12:17:42 +02:00
|
|
|
on_topic_narrow_called = true;
|
2021-02-28 21:32:22 +01:00
|
|
|
});
|
2021-02-24 13:30:27 +01:00
|
|
|
narrowed_by_topic_reply = true;
|
2018-05-28 12:17:42 +02:00
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(on_topic_narrow_called);
|
2018-05-28 12:17:42 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let update_message_list_called = false;
|
2021-02-24 13:30:27 +01:00
|
|
|
narrowed_by_topic_reply = false;
|
2021-02-23 14:37:26 +01:00
|
|
|
compose_fade.update_message_list = () => {
|
2018-05-28 12:17:42 +02:00
|
|
|
update_message_list_called = true;
|
|
|
|
};
|
2022-07-10 01:06:33 +02:00
|
|
|
compose_state.message_content("foo");
|
2018-05-28 12:17:42 +02:00
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(update_message_list_called);
|
2018-05-28 12:17:42 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
compose_state.message_content("");
|
2019-11-02 00:06:25 +01:00
|
|
|
let start_called = false;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(compose_actions, "start", () => {
|
2018-05-28 12:17:42 +02:00
|
|
|
start_called = true;
|
2021-02-28 21:32:22 +01:00
|
|
|
});
|
2021-02-24 13:30:27 +01:00
|
|
|
narrowed_by_pm_reply = true;
|
2024-07-08 19:00:08 +02:00
|
|
|
realm.realm_direct_message_permission_group = nobody.id;
|
|
|
|
realm.realm_direct_message_initiator_group = everyone.id;
|
2022-11-04 18:56:56 +01:00
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
trigger: "not-search",
|
|
|
|
private_message_recipient: "steve@example.com",
|
|
|
|
});
|
|
|
|
assert.ok(!start_called);
|
|
|
|
|
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
trigger: "not-search",
|
|
|
|
private_message_recipient: "bot@example.com",
|
|
|
|
});
|
|
|
|
assert.ok(start_called);
|
|
|
|
|
2024-07-08 19:00:08 +02:00
|
|
|
realm.realm_direct_message_permission_group = everyone.id;
|
|
|
|
blueslip.expect("warn", "Unknown emails");
|
2018-05-28 12:17:42 +02:00
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
trigger: "not-search",
|
|
|
|
private_message_recipient: "not@empty.com",
|
2018-05-28 12:17:42 +02:00
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(start_called);
|
2018-05-28 12:17:42 +02:00
|
|
|
|
|
|
|
start_called = false;
|
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
trigger: "search",
|
|
|
|
private_message_recipient: "",
|
2018-05-28 12:17:42 +02:00
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!start_called);
|
2018-05-28 12:17:42 +02:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
narrowed_by_pm_reply = false;
|
2018-05-28 12:17:42 +02:00
|
|
|
cancel_called = false;
|
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(cancel_called);
|
2018-05-28 12:17:42 +02:00
|
|
|
});
|