2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
zjsunit: Remove rewiremock dependency.
We now just use a module._load hook to inject
stubs into our code.
For conversion purposes I temporarily maintain
the API of rewiremock, apart from the enable/disable
pieces, but I will make a better wrapper in an
upcoming commit.
We can detect when rewiremock is called after
zrequire now, and I fix all the violations in
this commit, mostly by using override.
We can also detect when a mock is needlessly
created, and I fix all the violations in this
commit.
The one minor nuisance that this commit introduces
is that you can only stub out modules in the Zulip
source tree, which is now static/js. This should
not really be a problem--there are usually better
techniques to deal with third party depenencies.
In the prior commit I show a typical workaround,
which is to create a one-line wrapper in your
test code. It's often the case that you can simply
use override(), as well.
In passing I kill off `reset_modules`, and I
eliminated the second argument to zrequire,
which dates back to pre-es6 days.
2021-03-06 12:47:54 +01:00
|
|
|
const {rewiremock, set_global, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
const noop = () => {};
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
set_global("page_params", {});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("document", {
|
2018-04-12 18:06:39 +02:00
|
|
|
location: {}, // we need this to load compose.js
|
2020-12-01 23:21:38 +01:00
|
|
|
to_$: () => $("document-stub"),
|
2017-04-14 15:06:13 +02:00
|
|
|
});
|
|
|
|
|
2021-03-06 17:37:51 +01:00
|
|
|
const compose_pm_pill = {};
|
2021-02-28 00:38:58 +01:00
|
|
|
|
|
|
|
rewiremock("../../static/js/compose_pm_pill").with(compose_pm_pill);
|
2021-03-06 17:37:51 +01:00
|
|
|
const hash_util = {};
|
2021-02-28 01:07:13 +01:00
|
|
|
|
|
|
|
rewiremock("../../static/js/hash_util").with(hash_util);
|
2021-02-28 01:06:34 +01:00
|
|
|
rewiremock("../../static/js/notifications").with({
|
2020-12-01 23:21:38 +01:00
|
|
|
clear_compose_notifications: noop,
|
|
|
|
});
|
2021-03-06 17:37:51 +01:00
|
|
|
rewiremock("../../static/js/reload_state").with({
|
|
|
|
is_in_progress: () => false,
|
|
|
|
});
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2021-02-28 00:49:06 +01:00
|
|
|
const compose_fade = {
|
2020-12-01 23:21:38 +01:00
|
|
|
clear_compose: noop,
|
2021-02-28 00:49:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
rewiremock("../../static/js/compose_fade").with(compose_fade);
|
2021-02-28 00:37:57 +01:00
|
|
|
rewiremock("../../static/js/drafts").with({
|
2020-12-01 23:21:38 +01:00
|
|
|
update_draft: noop,
|
|
|
|
});
|
|
|
|
|
2021-02-28 00:47:56 +01:00
|
|
|
const narrow_state = {
|
2020-12-01 23:21:38 +01:00
|
|
|
set_compose_defaults: noop,
|
2021-02-28 00:47:56 +01:00
|
|
|
};
|
|
|
|
|
2021-03-06 17:37:51 +01:00
|
|
|
rewiremock("../../static/js/common").with({
|
|
|
|
status_classes: "status_classes",
|
|
|
|
});
|
2021-02-28 00:47:56 +01:00
|
|
|
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
2021-02-28 21:30:08 +01:00
|
|
|
rewiremock("../../static/js/unread_ops").with({
|
2020-12-01 23:21:38 +01:00
|
|
|
notify_server_message_read: noop,
|
|
|
|
});
|
|
|
|
set_global("current_msg_list", {
|
|
|
|
can_mark_messages_read() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-03-06 17:37:51 +01:00
|
|
|
const channel = {};
|
2021-02-28 00:39:51 +01:00
|
|
|
|
|
|
|
rewiremock("../../static/js/channel").with(channel);
|
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_ui = zrequire("compose_ui");
|
|
|
|
const compose = zrequire("compose");
|
|
|
|
const compose_state = zrequire("compose_state");
|
|
|
|
const compose_actions = zrequire("compose_actions");
|
|
|
|
const stream_data = zrequire("stream_data");
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2021-02-28 21:32:22 +01:00
|
|
|
compose_actions.__Rewire__("update_placeholder_text", noop);
|
2020-07-29 17:32:39 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const start = compose_actions.start;
|
|
|
|
const cancel = compose_actions.cancel;
|
|
|
|
const get_focus_area = compose_actions._get_focus_area;
|
|
|
|
const respond_to_message = compose_actions.respond_to_message;
|
|
|
|
const reply_with_mention = compose_actions.reply_with_mention;
|
|
|
|
const quote_and_reply = compose_actions.quote_and_reply;
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2021-02-28 00:50:52 +01:00
|
|
|
compose_state.__Rewire__(
|
|
|
|
"private_message_recipient",
|
|
|
|
(function () {
|
|
|
|
let recipient;
|
|
|
|
|
|
|
|
return function (arg) {
|
|
|
|
if (arg === undefined) {
|
|
|
|
return recipient;
|
|
|
|
}
|
|
|
|
|
|
|
|
recipient = arg;
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
})(),
|
|
|
|
);
|
2018-03-06 15:07:55 +01:00
|
|
|
|
2017-04-14 19:24:43 +02:00
|
|
|
function stub_selected_message(msg) {
|
2020-12-01 23:21:38 +01:00
|
|
|
current_msg_list.selected_message = () => msg;
|
2017-04-14 19:24:43 +02:00
|
|
|
}
|
|
|
|
|
2018-11-01 23:43:29 +01:00
|
|
|
function stub_channel_get(success_value) {
|
2020-12-01 23:21:38 +01:00
|
|
|
channel.get = (opts) => {
|
|
|
|
opts.success(success_value);
|
|
|
|
};
|
2018-11-01 23:43:29 +01:00
|
|
|
}
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
function assert_visible(sel) {
|
|
|
|
assert($(sel).visible());
|
|
|
|
}
|
|
|
|
|
|
|
|
function assert_hidden(sel) {
|
|
|
|
assert(!$(sel).visible());
|
|
|
|
}
|
|
|
|
|
2021-02-23 13:14:54 +01:00
|
|
|
run_test("initial_state", () => {
|
2017-04-15 01:15:59 +02:00
|
|
|
assert.equal(compose_state.composing(), false);
|
|
|
|
assert.equal(compose_state.get_message_type(), false);
|
|
|
|
assert.equal(compose_state.has_message_content(), false);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-15 01:15:59 +02:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
run_test("start", (override) => {
|
2021-02-28 21:32:22 +01:00
|
|
|
compose_actions.__Rewire__("autosize_message_content", noop);
|
|
|
|
compose_actions.__Rewire__("expand_compose_box", noop);
|
|
|
|
compose_actions.__Rewire__("set_focus", noop);
|
|
|
|
compose_actions.__Rewire__("complete_starting_tasks", noop);
|
|
|
|
compose_actions.__Rewire__("blur_compose_inputs", noop);
|
|
|
|
compose_actions.__Rewire__("clear_textarea", 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);
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
// Start stream message
|
2021-02-24 13:30:27 +01:00
|
|
|
compose_defaults = {
|
|
|
|
stream: "stream1",
|
|
|
|
topic: "topic1",
|
2017-04-14 15:06:13 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let opts = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
start("stream", opts);
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_visible("#stream-message");
|
|
|
|
assert_hidden("#private-message");
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#stream_message_recipient_stream").val(), "stream1");
|
|
|
|
assert.equal($("#stream_message_recipient_topic").val(), "topic1");
|
|
|
|
assert.equal(compose_state.get_message_type(), "stream");
|
2017-04-15 01:15:59 +02:00
|
|
|
assert(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 = {
|
|
|
|
trigger: "new topic button",
|
2019-07-27 08:12:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
opts = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
start("stream", opts);
|
|
|
|
assert.equal($("#stream_message_recipient_stream").val(), "Denmark");
|
|
|
|
assert.equal($("#stream_message_recipient_topic").val(), "");
|
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
|
|
|
};
|
|
|
|
|
|
|
|
opts = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
start("stream", opts);
|
|
|
|
assert.equal($("#stream_message_recipient_stream").val(), "Denmark");
|
|
|
|
assert.equal($("#stream_message_recipient_topic").val(), "");
|
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
|
|
|
|
|
|
|
// More than 1 subscription, do not autofill
|
|
|
|
opts = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
start("stream", opts);
|
|
|
|
assert.equal($("#stream_message_recipient_stream").val(), "");
|
|
|
|
assert.equal($("#stream_message_recipient_topic").val(), "");
|
2019-07-27 08:12:14 +02:00
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
// Start PM
|
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 = {
|
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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
start("private", opts);
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_hidden("#stream-message");
|
|
|
|
assert_visible("#private-message");
|
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");
|
|
|
|
assert.equal($("#compose-textarea").val(), "hello");
|
|
|
|
assert.equal(compose_state.get_message_type(), "private");
|
2017-04-15 01:15:59 +02:00
|
|
|
assert(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;
|
2021-02-28 00:51:57 +01:00
|
|
|
compose.__Rewire__("abort_xhr", () => {
|
2019-11-21 05:24:55 +01:00
|
|
|
abort_xhr_called = true;
|
2021-02-28 00:51:57 +01:00
|
|
|
});
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2021-02-08 16:27:29 +01:00
|
|
|
$("#compose-textarea").set_height(50);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_hidden("#compose_controls");
|
2017-04-14 15:06:13 +02:00
|
|
|
cancel();
|
2019-11-21 05:24:55 +01:00
|
|
|
assert(abort_xhr_called);
|
2018-03-06 15:07:55 +01:00
|
|
|
assert(pill_cleared);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert_visible("#compose_controls");
|
|
|
|
assert_hidden("#private-message");
|
2017-04-15 01:15:59 +02:00
|
|
|
assert(!compose_state.composing());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-14 16:26:00 +02:00
|
|
|
|
2021-02-23 13:14:54 +01:00
|
|
|
run_test("respond_to_message", () => {
|
2017-04-14 19:24:43 +02:00
|
|
|
// Test PM
|
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,
|
|
|
|
};
|
|
|
|
stub_selected_message(msg);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let opts = {
|
2020-07-15 01:29:15 +02:00
|
|
|
reply_type: "personal",
|
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
|
|
|
|
msg = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
|
|
|
stream: "devel",
|
|
|
|
topic: "python",
|
|
|
|
reply_to: "bob", // compose.start needs this for dubious reasons
|
2017-04-14 19:24:43 +02:00
|
|
|
};
|
|
|
|
stub_selected_message(msg);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
opts = {};
|
2017-04-14 19:24:43 +02:00
|
|
|
|
|
|
|
respond_to_message(opts);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#stream_message_recipient_stream").val(), "devel");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-14 19:24:43 +02:00
|
|
|
|
2021-02-23 13:14:54 +01:00
|
|
|
run_test("reply_with_mention", (override) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
|
|
|
stream: "devel",
|
|
|
|
topic: "python",
|
|
|
|
reply_to: "bob", // compose.start needs this for dubious reasons
|
|
|
|
sender_full_name: "Bob Roberts",
|
2018-10-13 02:03:43 +02:00
|
|
|
sender_id: 40,
|
2017-04-14 19:24:43 +02:00
|
|
|
};
|
|
|
|
stub_selected_message(msg);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let syntax_to_insert;
|
2021-02-21 12:29:02 +01: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);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#stream_message_recipient_stream").val(), "devel");
|
|
|
|
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);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#stream_message_recipient_stream").val(), "devel");
|
|
|
|
assert.equal(syntax_to_insert, "@**Bob Roberts|40**");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-14 16:26:00 +02:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
run_test("quote_and_reply", (override) => {
|
|
|
|
let selected_message;
|
|
|
|
override(current_msg_list, "selected_message", () => selected_message);
|
|
|
|
|
|
|
|
let expected_replacement;
|
|
|
|
let replaced;
|
|
|
|
override(compose_ui, "replace_syntax", (syntax, replacement) => {
|
|
|
|
assert.equal(syntax, "[Quoting…]");
|
|
|
|
assert.equal(replacement, expected_replacement);
|
|
|
|
replaced = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
selected_message = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
|
|
|
stream: "devel",
|
|
|
|
topic: "python",
|
|
|
|
reply_to: "bob",
|
|
|
|
sender_full_name: "Bob Roberts",
|
2018-11-01 23:43:29 +01:00
|
|
|
sender_id: 40,
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
hash_util.by_conversation_and_time_uri = () => "link_to_message";
|
2019-08-26 08:10:46 +02:00
|
|
|
stub_channel_get({
|
2020-07-15 01:29:15 +02:00
|
|
|
raw_content: "Testing.",
|
2019-08-26 08:10:46 +02:00
|
|
|
});
|
2018-11-01 23:43:29 +01:00
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
current_msg_list.selected_id = () => 100;
|
2018-11-01 23:43:29 +01:00
|
|
|
|
2021-02-28 01:26:48 +01:00
|
|
|
compose_ui.__Rewire__("insert_syntax_and_focus", (syntax) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(syntax, "[Quoting…]\n");
|
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",
|
2018-11-01 23:43:29 +01:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-textarea").caret = (pos) => {
|
2019-01-16 16:29:18 +01:00
|
|
|
assert.equal(pos, 0);
|
|
|
|
};
|
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
replaced = false;
|
|
|
|
expected_replacement = "@_**Bob Roberts|40** [said](link_to_message):\n```quote\nTesting.\n```";
|
|
|
|
|
2018-11-01 23:43:29 +01:00
|
|
|
quote_and_reply(opts);
|
2021-02-24 13:30:27 +01:00
|
|
|
assert(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",
|
|
|
|
stream: "devel",
|
|
|
|
topic: "test",
|
|
|
|
reply_to: "bob",
|
|
|
|
sender_full_name: "Bob Roberts",
|
|
|
|
sender_id: 40,
|
|
|
|
raw_content: "Testing.",
|
2021-02-24 13:30:27 +01:00
|
|
|
};
|
2018-11-11 19:36:26 +01:00
|
|
|
|
2021-02-28 17:48:20 +01:00
|
|
|
channel.get = () => {
|
|
|
|
assert.fail("channel.get should not be used if raw_content is present");
|
|
|
|
};
|
2018-11-11 19:36:26 +01:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
replaced = false;
|
2018-11-11 19:36:26 +01:00
|
|
|
quote_and_reply(opts);
|
2021-02-24 13:30:27 +01:00
|
|
|
assert(replaced);
|
2019-08-26 09:04:34 +02:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
selected_message = {
|
2021-02-23 14:37:26 +01:00
|
|
|
type: "stream",
|
|
|
|
stream: "devel",
|
|
|
|
topic: "test",
|
|
|
|
reply_to: "bob",
|
|
|
|
sender_full_name: "Bob Roberts",
|
|
|
|
sender_id: 40,
|
|
|
|
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 =
|
|
|
|
"@_**Bob Roberts|40** [said](link_to_message):\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-02-24 13:30:27 +01:00
|
|
|
assert(replaced);
|
2018-11-01 23:43:29 +01:00
|
|
|
});
|
|
|
|
|
2021-02-23 13:14:54 +01:00
|
|
|
run_test("get_focus_area", () => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(get_focus_area("private", {}), "#private_message_recipient");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
get_focus_area("private", {
|
|
|
|
private_message_recipient: "bob@example.com",
|
|
|
|
}),
|
|
|
|
"#compose-textarea",
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(get_focus_area("stream", {}), "#stream_message_recipient_stream");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(get_focus_area("stream", {stream: "fun"}), "#stream_message_recipient_topic");
|
|
|
|
assert.equal(get_focus_area("stream", {stream: "fun", topic: "more"}), "#compose-textarea");
|
|
|
|
assert.equal(
|
|
|
|
get_focus_area("stream", {stream: "fun", topic: "more", trigger: "new topic button"}),
|
|
|
|
"#stream_message_recipient_topic",
|
|
|
|
);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-09-18 21:54:06 +02:00
|
|
|
|
2021-02-23 13:14:54 +01:00
|
|
|
run_test("focus_in_empty_compose", () => {
|
2021-02-23 14:37:26 +01:00
|
|
|
$("#compose-textarea").is = (attr) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(attr, ":focus");
|
|
|
|
return $("#compose-textarea").is_focused;
|
2017-09-18 21:54:06 +02:00
|
|
|
};
|
|
|
|
|
2021-02-28 00:50:52 +01:00
|
|
|
compose_state.__Rewire__("composing", () => true);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-textarea").val("");
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#compose-textarea").trigger("focus");
|
2017-09-18 21:54:06 +02:00
|
|
|
assert(compose_state.focus_in_empty_compose());
|
|
|
|
|
2021-02-28 00:50:52 +01:00
|
|
|
compose_state.__Rewire__("composing", () => false);
|
2017-09-18 21:54:06 +02:00
|
|
|
assert(!compose_state.focus_in_empty_compose());
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-textarea").val("foo");
|
2017-09-18 21:54:06 +02:00
|
|
|
assert(!compose_state.focus_in_empty_compose());
|
|
|
|
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#compose-textarea").trigger("blur");
|
2017-09-18 21:54:06 +02:00
|
|
|
assert(!compose_state.focus_in_empty_compose());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-05-28 12:17:42 +02:00
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
run_test("on_narrow", (override) => {
|
|
|
|
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);
|
|
|
|
|
|
|
|
let has_message_content;
|
|
|
|
override(compose_state, "has_message_content", () => has_message_content);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let cancel_called = false;
|
2021-02-28 21:32:22 +01:00
|
|
|
compose_actions.__Rewire__("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,
|
|
|
|
});
|
|
|
|
assert(cancel_called);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let on_topic_narrow_called = false;
|
2021-02-28 21:32:22 +01:00
|
|
|
compose_actions.__Rewire__("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,
|
|
|
|
});
|
|
|
|
assert(on_topic_narrow_called);
|
|
|
|
|
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;
|
|
|
|
};
|
2021-02-24 13:30:27 +01:00
|
|
|
has_message_content = true;
|
2018-05-28 12:17:42 +02:00
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
});
|
|
|
|
assert(update_message_list_called);
|
|
|
|
|
2021-02-24 13:30:27 +01:00
|
|
|
has_message_content = false;
|
2019-11-02 00:06:25 +01:00
|
|
|
let start_called = false;
|
2021-02-28 21:32:22 +01:00
|
|
|
compose_actions.__Rewire__("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;
|
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
|
|
|
});
|
|
|
|
assert(start_called);
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
assert(!start_called);
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
assert(cancel_called);
|
|
|
|
});
|