2019-11-02 00:06:25 +01:00
|
|
|
const noop = function () {};
|
|
|
|
const return_false = function () { return false; };
|
|
|
|
const return_true = function () { return true; };
|
2017-04-14 15:06:13 +02:00
|
|
|
|
|
|
|
set_global('document', {
|
2018-04-12 18:06:39 +02:00
|
|
|
location: {}, // we need this to load compose.js
|
2017-04-14 15:06:13 +02:00
|
|
|
});
|
|
|
|
|
dependencies: Remove WebSockets system for sending messages.
Zulip has had a small use of WebSockets (specifically, for the code
path of sending messages, via the webapp only) since ~2013. We
originally added this use of WebSockets in the hope that the latency
benefits of doing so would allow us to avoid implementing a markdown
local echo; they were not. Further, HTTP/2 may have eliminated the
latency difference we hoped to exploit by using WebSockets in any
case.
While we’d originally imagined using WebSockets for other endpoints,
there was never a good justification for moving more components to the
WebSockets system.
This WebSockets code path had a lot of downsides/complexity,
including:
* The messy hack involving constructing an emulated request object to
hook into doing Django requests.
* The `message_senders` queue processor system, which increases RAM
needs and must be provisioned independently from the rest of the
server).
* A duplicate check_send_receive_time Nagios test specific to
WebSockets.
* The requirement for users to have their firewalls/NATs allow
WebSocket connections, and a setting to disable them for networks
where WebSockets don’t work.
* Dependencies on the SockJS family of libraries, which has at times
been poorly maintained, and periodically throws random JavaScript
exceptions in our production environments without a deep enough
traceback to effectively investigate.
* A total of about 1600 lines of our code related to the feature.
* Increased load on the Tornado system, especially around a Zulip
server restart, and especially for large installations like
zulipchat.com, resulting in extra delay before messages can be sent
again.
As detailed in
https://github.com/zulip/zulip/pull/12862#issuecomment-536152397, it
appears that removing WebSockets moderately increases the time it
takes for the `send_message` API query to return from the server, but
does not significantly change the time between when a message is sent
and when it is received by clients. We don’t understand the reason
for that change (suggesting the possibility of a measurement error),
and even if it is a real change, we consider that potential small
latency regression to be acceptable.
If we later want WebSockets, we’ll likely want to just use Django
Channels.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-23 01:43:40 +02:00
|
|
|
set_global('page_params', {});
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2017-06-20 04:34:04 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
2018-03-06 15:07:55 +01:00
|
|
|
set_global('compose_pm_pill', {
|
|
|
|
});
|
|
|
|
|
2019-08-26 08:10:46 +02:00
|
|
|
set_global('hash_util', {
|
|
|
|
});
|
|
|
|
|
2017-11-08 16:57:05 +01:00
|
|
|
zrequire('people');
|
|
|
|
zrequire('compose_ui');
|
|
|
|
zrequire('compose');
|
|
|
|
zrequire('compose_state');
|
|
|
|
zrequire('compose_actions');
|
2019-08-26 09:04:34 +02:00
|
|
|
zrequire('fenced_code');
|
2019-07-27 08:12:14 +02:00
|
|
|
zrequire('stream_data');
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2018-04-12 18:06:39 +02:00
|
|
|
set_global('document', 'document-stub');
|
|
|
|
|
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
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const compose_state = global.compose_state;
|
2017-04-15 01:15:59 +02:00
|
|
|
|
2019-12-02 17:53:55 +01:00
|
|
|
compose_state.private_message_recipient = (function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
let recipient;
|
2018-03-06 15:07:55 +01:00
|
|
|
|
|
|
|
return function (arg) {
|
|
|
|
if (arg === undefined) {
|
|
|
|
return recipient;
|
|
|
|
}
|
|
|
|
|
|
|
|
recipient = arg;
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
|
2018-08-04 15:40:25 +02:00
|
|
|
set_global('reload_state', {
|
2017-04-14 15:06:13 +02:00
|
|
|
is_in_progress: return_false,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('notifications', {
|
|
|
|
clear_compose_notifications: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('compose_fade', {
|
|
|
|
clear_compose: noop,
|
|
|
|
});
|
|
|
|
|
2017-04-14 19:24:43 +02:00
|
|
|
set_global('drafts', {
|
|
|
|
update_draft: noop,
|
|
|
|
});
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
set_global('narrow_state', {
|
|
|
|
set_compose_defaults: noop,
|
|
|
|
});
|
|
|
|
|
2017-04-14 19:24:43 +02:00
|
|
|
set_global('unread_ops', {
|
2018-04-04 21:32:45 +02:00
|
|
|
notify_server_message_read: noop,
|
2017-04-14 19:24:43 +02:00
|
|
|
});
|
|
|
|
|
2017-06-22 22:08:43 +02:00
|
|
|
set_global('common', {
|
|
|
|
status_classes: 'status_classes',
|
|
|
|
});
|
2017-04-14 15:06:13 +02:00
|
|
|
|
2017-04-14 19:24:43 +02:00
|
|
|
function stub_selected_message(msg) {
|
|
|
|
set_global('current_msg_list', {
|
|
|
|
selected_message: function () {
|
|
|
|
return msg;
|
|
|
|
},
|
2019-07-10 02:03:41 +02:00
|
|
|
can_mark_messages_read: function () {
|
|
|
|
return true;
|
|
|
|
},
|
2017-04-14 19:24:43 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-01 23:43:29 +01:00
|
|
|
function stub_channel_get(success_value) {
|
|
|
|
set_global('channel', {
|
|
|
|
get: function (opts) {
|
|
|
|
opts.success(success_value);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
function assert_visible(sel) {
|
|
|
|
assert($(sel).visible());
|
|
|
|
}
|
|
|
|
|
|
|
|
function assert_hidden(sel) {
|
|
|
|
assert(!$(sel).visible());
|
|
|
|
}
|
|
|
|
|
2018-05-15 12:40:07 +02: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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('start', () => {
|
2017-04-14 16:26:00 +02:00
|
|
|
compose_actions.autosize_message_content = noop;
|
|
|
|
compose_actions.expand_compose_box = noop;
|
|
|
|
compose_actions.set_focus = noop;
|
|
|
|
compose_actions.complete_starting_tasks = noop;
|
|
|
|
compose_actions.blur_textarea = noop;
|
|
|
|
compose_actions.clear_textarea = noop;
|
2017-04-14 15:06:13 +02:00
|
|
|
|
|
|
|
// Start stream message
|
2017-12-02 03:13:43 +01:00
|
|
|
global.narrow_state.set_compose_defaults = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {};
|
2017-04-14 15:06:13 +02:00
|
|
|
opts.stream = 'stream1';
|
2018-11-15 19:14:16 +01:00
|
|
|
opts.topic = 'topic1';
|
2017-12-02 03:13:43 +01:00
|
|
|
return opts;
|
2017-04-14 15:06:13 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let opts = {};
|
2017-04-14 15:06:13 +02:00
|
|
|
start('stream', opts);
|
|
|
|
|
|
|
|
assert_visible('#stream-message');
|
|
|
|
assert_hidden('#private-message');
|
|
|
|
|
2018-11-13 17:16:02 +01:00
|
|
|
assert.equal($('#stream_message_recipient_stream').val(), 'stream1');
|
|
|
|
assert.equal($('#stream_message_recipient_topic').val(), 'topic1');
|
2017-04-15 01:15:59 +02:00
|
|
|
assert.equal(compose_state.get_message_type(), 'stream');
|
|
|
|
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,
|
|
|
|
color: 'blue',
|
|
|
|
name: 'Denmark',
|
|
|
|
stream_id: 1,
|
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(denmark);
|
2019-07-27 08:12:14 +02:00
|
|
|
|
|
|
|
global.narrow_state.set_compose_defaults = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {};
|
2019-07-27 08:12:14 +02:00
|
|
|
opts.trigger = "new topic button";
|
|
|
|
return opts;
|
|
|
|
};
|
|
|
|
|
|
|
|
opts = {};
|
|
|
|
start('stream', opts);
|
|
|
|
assert.equal($('#stream_message_recipient_stream').val(), 'Denmark');
|
|
|
|
assert.equal($('#stream_message_recipient_topic').val(), '');
|
|
|
|
|
|
|
|
global.narrow_state.set_compose_defaults = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {};
|
2019-07-27 08:12:14 +02:00
|
|
|
opts.trigger = "compose_hotkey";
|
|
|
|
return opts;
|
|
|
|
};
|
|
|
|
|
|
|
|
opts = {};
|
|
|
|
start('stream', opts);
|
|
|
|
assert.equal($('#stream_message_recipient_stream').val(), 'Denmark');
|
|
|
|
assert.equal($('#stream_message_recipient_topic').val(), '');
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const social = {
|
2019-07-27 08:12:14 +02:00
|
|
|
subscribed: true,
|
|
|
|
color: 'red',
|
|
|
|
name: 'social',
|
|
|
|
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 = {};
|
|
|
|
start('stream', opts);
|
|
|
|
assert.equal($('#stream_message_recipient_stream').val(), '');
|
|
|
|
assert.equal($('#stream_message_recipient_topic').val(), '');
|
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
// Start PM
|
2017-12-02 03:13:43 +01:00
|
|
|
global.narrow_state.set_compose_defaults = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {};
|
2017-04-14 15:06:13 +02:00
|
|
|
opts.private_message_recipient = 'foo@example.com';
|
2017-12-02 03:13:43 +01:00
|
|
|
return opts;
|
2017-04-14 15:06:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
opts = {
|
|
|
|
content: 'hello',
|
|
|
|
};
|
2017-06-14 20:28:55 +02:00
|
|
|
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').trigger = noop;
|
2017-04-14 15:06:13 +02:00
|
|
|
start('private', opts);
|
|
|
|
|
|
|
|
assert_hidden('#stream-message');
|
|
|
|
assert_visible('#private-message');
|
|
|
|
|
2019-12-02 17:53:55 +01:00
|
|
|
assert.equal(compose_state.private_message_recipient(), 'foo@example.com');
|
2017-11-26 20:37:44 +01:00
|
|
|
assert.equal($('#compose-textarea').val(), 'hello');
|
2017-04-15 01:15:59 +02:00
|
|
|
assert.equal(compose_state.get_message_type(), 'private');
|
|
|
|
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;
|
2018-03-06 15:07:55 +01:00
|
|
|
compose_pm_pill.clear = function () {
|
|
|
|
pill_cleared = true;
|
|
|
|
};
|
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
let abort_xhr_called = false;
|
|
|
|
compose.abort_xhr = () => {
|
|
|
|
abort_xhr_called = true;
|
|
|
|
};
|
|
|
|
|
2017-04-14 15:06:13 +02:00
|
|
|
assert_hidden('#compose_controls');
|
|
|
|
cancel();
|
2019-11-21 05:24:55 +01:00
|
|
|
assert(abort_xhr_called);
|
2018-03-06 15:07:55 +01:00
|
|
|
assert(pill_cleared);
|
2017-04-14 15:06:13 +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
|
|
|
|
2018-05-15 12:40:07 +02: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,
|
|
|
|
email: 'alice@example.com',
|
|
|
|
full_name: 'Alice',
|
|
|
|
};
|
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 = {
|
2017-04-14 19:24:43 +02:00
|
|
|
type: 'private',
|
|
|
|
sender_id: person.user_id,
|
|
|
|
};
|
|
|
|
stub_selected_message(msg);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let opts = {
|
2017-04-14 19:24:43 +02:00
|
|
|
reply_type: 'personal',
|
|
|
|
};
|
|
|
|
|
|
|
|
respond_to_message(opts);
|
2019-12-02 17:53:55 +01:00
|
|
|
assert.equal(compose_state.private_message_recipient(), 'alice@example.com');
|
2017-04-14 19:24:43 +02:00
|
|
|
|
|
|
|
// Test stream
|
|
|
|
msg = {
|
|
|
|
type: 'stream',
|
|
|
|
stream: 'devel',
|
2018-12-23 16:49:14 +01:00
|
|
|
topic: 'python',
|
2017-04-14 19:24:43 +02:00
|
|
|
reply_to: 'bob', // compose.start needs this for dubious reasons
|
|
|
|
};
|
|
|
|
stub_selected_message(msg);
|
|
|
|
|
|
|
|
opts = {
|
|
|
|
};
|
|
|
|
|
|
|
|
respond_to_message(opts);
|
2018-11-13 17:16:02 +01: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
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('reply_with_mention', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg = {
|
2017-04-14 19:24:43 +02:00
|
|
|
type: 'stream',
|
|
|
|
stream: 'devel',
|
2018-12-23 16:49:14 +01:00
|
|
|
topic: 'python',
|
2017-04-14 19:24:43 +02:00
|
|
|
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;
|
2018-02-26 16:04:40 +01:00
|
|
|
compose_ui.insert_syntax_and_focus = function (syntax) {
|
|
|
|
syntax_to_insert = syntax;
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {
|
2017-04-14 19:24:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
reply_with_mention(opts);
|
2018-11-13 17:16:02 +01:00
|
|
|
assert.equal($('#stream_message_recipient_stream').val(), 'devel');
|
2018-02-26 16:04:40 +01:00
|
|
|
assert.equal(syntax_to_insert, '@**Bob Roberts**');
|
2017-04-15 01:15:59 +02:00
|
|
|
assert(compose_state.has_message_content());
|
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,
|
|
|
|
email: 'bob1@example.com',
|
|
|
|
full_name: 'Bob Roberts',
|
|
|
|
};
|
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,
|
|
|
|
email: 'bob2@example.com',
|
|
|
|
full_name: 'Bob Roberts',
|
|
|
|
};
|
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);
|
2018-11-13 17:16:02 +01:00
|
|
|
assert.equal($('#stream_message_recipient_stream').val(), 'devel');
|
2018-10-13 02:03:43 +02:00
|
|
|
assert.equal(syntax_to_insert, '@**Bob Roberts|40**');
|
|
|
|
assert(compose_state.has_message_content());
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-14 16:26:00 +02:00
|
|
|
|
2018-11-01 23:43:29 +01:00
|
|
|
run_test('quote_and_reply', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg = {
|
2018-11-01 23:43:29 +01:00
|
|
|
type: 'stream',
|
|
|
|
stream: 'devel',
|
2018-12-23 16:49:14 +01:00
|
|
|
topic: 'python',
|
2018-11-01 23:43:29 +01:00
|
|
|
reply_to: 'bob',
|
|
|
|
sender_full_name: 'Bob Roberts',
|
|
|
|
sender_id: 40,
|
|
|
|
};
|
2019-08-26 08:10:46 +02:00
|
|
|
hash_util.by_conversation_and_time_uri = () => 'link_to_message';
|
2018-11-01 23:43:29 +01:00
|
|
|
stub_selected_message(msg);
|
2019-08-26 08:10:46 +02:00
|
|
|
stub_channel_get({
|
|
|
|
raw_content: 'Testing.',
|
|
|
|
});
|
2018-11-01 23:43:29 +01:00
|
|
|
|
|
|
|
current_msg_list.selected_id = function () {
|
|
|
|
return 100;
|
|
|
|
};
|
|
|
|
|
|
|
|
compose_ui.insert_syntax_and_focus = function (syntax) {
|
|
|
|
assert.equal(syntax, '[Quoting…]\n');
|
|
|
|
};
|
|
|
|
|
|
|
|
compose_ui.replace_syntax = function (syntax, replacement) {
|
|
|
|
assert.equal(syntax, '[Quoting…]');
|
2019-08-26 08:10:46 +02:00
|
|
|
assert.equal(replacement, '@_**Bob Roberts|40** [said](link_to_message):\n```quote\nTesting.\n```');
|
2018-11-01 23:43:29 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const opts = {
|
2018-11-01 23:43:29 +01:00
|
|
|
reply_type: 'personal',
|
|
|
|
};
|
|
|
|
|
2019-01-16 16:29:18 +01:00
|
|
|
$('#compose-textarea').caret = (pos) => {
|
|
|
|
assert.equal(pos, 0);
|
|
|
|
};
|
|
|
|
|
2018-11-01 23:43:29 +01:00
|
|
|
quote_and_reply(opts);
|
2018-11-11 19:36:26 +01:00
|
|
|
|
|
|
|
current_msg_list.selected_message = function () {
|
|
|
|
return {
|
|
|
|
type: 'stream',
|
|
|
|
stream: 'devel',
|
2018-12-23 16:49:14 +01:00
|
|
|
topic: 'test',
|
2018-11-11 19:36:26 +01:00
|
|
|
reply_to: 'bob',
|
2019-08-26 08:10:46 +02:00
|
|
|
sender_full_name: 'Bob Roberts',
|
2018-11-11 19:36:26 +01:00
|
|
|
sender_id: 40,
|
|
|
|
raw_content: 'Testing.',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.get = function () {
|
|
|
|
assert.fail('channel.get should not be used if raw_content is present');
|
|
|
|
};
|
|
|
|
|
|
|
|
quote_and_reply(opts);
|
2019-08-26 09:04:34 +02:00
|
|
|
|
|
|
|
current_msg_list.selected_message = function () {
|
|
|
|
return {
|
|
|
|
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```',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
compose_ui.replace_syntax = function (syntax, replacement) {
|
|
|
|
assert.equal(syntax, '[Quoting…]');
|
|
|
|
assert.equal(replacement, '@_**Bob Roberts|40** [said](link_to_message):\n````quote\n```\nmultiline code block\nshoudln\'t mess with quotes\n```\n````');
|
|
|
|
};
|
|
|
|
quote_and_reply(opts);
|
2018-11-01 23:43:29 +01:00
|
|
|
});
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('get_focus_area', () => {
|
2018-11-13 17:16:02 +01:00
|
|
|
assert.equal(get_focus_area('private', {}), '#private_message_recipient');
|
2017-04-14 16:26:00 +02:00
|
|
|
assert.equal(get_focus_area('private', {
|
2018-11-13 17:16:02 +01:00
|
|
|
private_message_recipient: 'bob@example.com'}), '#compose-textarea');
|
|
|
|
assert.equal(get_focus_area('stream', {}), '#stream_message_recipient_stream');
|
2017-04-14 16:26:00 +02:00
|
|
|
assert.equal(get_focus_area('stream', {stream: 'fun'}),
|
2018-11-13 17:16:02 +01:00
|
|
|
'#stream_message_recipient_topic');
|
2017-04-14 16:26:00 +02:00
|
|
|
assert.equal(get_focus_area('stream', {stream: 'fun',
|
2018-11-15 19:14:16 +01:00
|
|
|
topic: 'more'}),
|
2018-11-13 17:16:02 +01:00
|
|
|
'#compose-textarea');
|
2017-04-14 16:26:00 +02:00
|
|
|
assert.equal(get_focus_area('stream', {stream: 'fun',
|
2018-11-15 19:14:16 +01:00
|
|
|
topic: 'more',
|
2017-04-14 16:26:00 +02:00
|
|
|
trigger: 'new topic button'}),
|
2018-11-13 17:16:02 +01:00
|
|
|
'#stream_message_recipient_topic');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-09-18 21:54:06 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('focus_in_empty_compose', () => {
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').is = function (attr) {
|
2017-09-18 21:54:06 +02:00
|
|
|
assert.equal(attr, ':focus');
|
2017-11-26 20:37:44 +01:00
|
|
|
return $('#compose-textarea').is_focused;
|
2017-09-18 21:54:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
compose_state.composing = return_true;
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').val('');
|
|
|
|
$('#compose-textarea').focus();
|
2017-09-18 21:54:06 +02:00
|
|
|
assert(compose_state.focus_in_empty_compose());
|
|
|
|
|
|
|
|
compose_state.composing = return_false;
|
|
|
|
assert(!compose_state.focus_in_empty_compose());
|
|
|
|
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').val('foo');
|
2017-09-18 21:54:06 +02:00
|
|
|
assert(!compose_state.focus_in_empty_compose());
|
|
|
|
|
2017-11-26 20:37:44 +01:00
|
|
|
$('#compose-textarea').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
|
|
|
|
|
|
|
run_test('on_narrow', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let cancel_called = false;
|
2018-05-28 12:17:42 +02:00
|
|
|
compose_actions.cancel = function () {
|
|
|
|
cancel_called = true;
|
|
|
|
};
|
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: true,
|
|
|
|
});
|
|
|
|
assert(cancel_called);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let on_topic_narrow_called = false;
|
2018-05-28 12:17:42 +02:00
|
|
|
compose_actions.on_topic_narrow = function () {
|
|
|
|
on_topic_narrow_called = true;
|
|
|
|
};
|
|
|
|
narrow_state.narrowed_by_topic_reply = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
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;
|
2018-05-28 12:17:42 +02:00
|
|
|
narrow_state.narrowed_by_topic_reply = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
compose_fade.update_message_list = function () {
|
|
|
|
update_message_list_called = true;
|
|
|
|
};
|
|
|
|
compose_state.has_message_content = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
});
|
|
|
|
assert(update_message_list_called);
|
|
|
|
|
|
|
|
compose_state.has_message_content = function () {
|
|
|
|
return false;
|
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
let start_called = false;
|
2018-05-28 12:17:42 +02:00
|
|
|
compose_actions.start = function () {
|
|
|
|
start_called = true;
|
|
|
|
};
|
|
|
|
narrow_state.narrowed_by_pm_reply = function () {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
trigger: 'not-search',
|
|
|
|
private_message_recipient: 'not@empty.com',
|
|
|
|
});
|
|
|
|
assert(start_called);
|
|
|
|
|
|
|
|
start_called = false;
|
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
trigger: 'search',
|
|
|
|
private_message_recipient: '',
|
|
|
|
});
|
|
|
|
assert(!start_called);
|
|
|
|
|
|
|
|
narrow_state.narrowed_by_pm_reply = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
cancel_called = false;
|
|
|
|
compose_actions.on_narrow({
|
|
|
|
force_close: false,
|
|
|
|
});
|
|
|
|
assert(cancel_called);
|
|
|
|
});
|