2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
const MockDate = require("mockdate");
|
2020-02-28 23:59:07 +01:00
|
|
|
|
2024-11-13 07:05:32 +01:00
|
|
|
const {mock_banners} = require("./lib/compose_banner.cjs");
|
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace.cjs");
|
|
|
|
const {run_test, noop} = require("./lib/test.cjs");
|
|
|
|
const $ = require("./lib/zjquery.cjs");
|
|
|
|
const {page_params} = require("./lib/zpage_params.cjs");
|
2022-08-19 21:36:33 +02:00
|
|
|
|
2024-07-08 19:00:08 +02:00
|
|
|
const user_groups = zrequire("user_groups");
|
2023-01-03 08:29:15 +01:00
|
|
|
|
2022-02-14 17:43:32 +01:00
|
|
|
set_global("document", {
|
2022-11-17 23:33:43 +01:00
|
|
|
querySelector() {},
|
2022-02-14 17:43:32 +01:00
|
|
|
});
|
2021-05-19 21:09:57 +02:00
|
|
|
set_global("navigator", {});
|
2022-04-19 02:45:44 +02:00
|
|
|
set_global(
|
|
|
|
"ResizeObserver",
|
|
|
|
class ResizeObserver {
|
|
|
|
observe() {}
|
|
|
|
},
|
|
|
|
);
|
2021-02-10 04:53:22 +01:00
|
|
|
|
2021-02-05 21:20:14 +01:00
|
|
|
const fake_now = 555;
|
|
|
|
|
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");
|
2023-06-18 08:49:55 +02:00
|
|
|
const compose_actions = mock_esm("../src/compose_actions", {
|
|
|
|
register_compose_cancel_hook: noop,
|
|
|
|
register_compose_box_clear_hook: noop,
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const compose_fade = mock_esm("../src/compose_fade");
|
2023-10-16 12:55:24 +02:00
|
|
|
const compose_notifications = mock_esm("../src/compose_notifications");
|
2023-02-22 23:04:10 +01:00
|
|
|
const compose_pm_pill = mock_esm("../src/compose_pm_pill");
|
|
|
|
const loading = mock_esm("../src/loading");
|
|
|
|
const markdown = mock_esm("../src/markdown");
|
2023-01-03 08:29:15 +01:00
|
|
|
const narrow_state = mock_esm("../src/narrow_state");
|
2023-02-22 23:04:10 +01:00
|
|
|
const rendered_markdown = mock_esm("../src/rendered_markdown");
|
|
|
|
const resize = mock_esm("../src/resize");
|
|
|
|
const sent_messages = mock_esm("../src/sent_messages");
|
|
|
|
const server_events = mock_esm("../src/server_events");
|
|
|
|
const transmit = mock_esm("../src/transmit");
|
|
|
|
const upload = mock_esm("../src/upload");
|
2023-12-02 13:34:05 +01:00
|
|
|
const onboarding_steps = mock_esm("../src/onboarding_steps");
|
2021-05-19 18:03:57 +02:00
|
|
|
|
2022-07-28 09:31:57 +02:00
|
|
|
const compose_ui = zrequire("compose_ui");
|
2023-02-02 03:38:52 +01:00
|
|
|
const compose_banner = zrequire("compose_banner");
|
2021-05-11 22:04:35 +02:00
|
|
|
const compose_closed_ui = zrequire("compose_closed_ui");
|
2023-03-31 06:27:36 +02:00
|
|
|
const compose_recipient = zrequire("compose_recipient");
|
2021-05-19 19:34:42 +02:00
|
|
|
const compose_state = zrequire("compose_state");
|
|
|
|
const compose = zrequire("compose");
|
2023-10-05 21:02:57 +02:00
|
|
|
const compose_setup = zrequire("compose_setup");
|
2024-02-17 20:03:03 +01:00
|
|
|
const drafts = zrequire("drafts");
|
2021-05-19 19:34:42 +02:00
|
|
|
const echo = zrequire("echo");
|
|
|
|
const people = zrequire("people");
|
2024-10-09 22:44:13 +02:00
|
|
|
const {set_current_user, set_realm} = zrequire("state_data");
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
2024-10-09 08:44:21 +02:00
|
|
|
const {initialize_user_settings} = zrequire("user_settings");
|
|
|
|
|
2024-10-09 22:44:13 +02:00
|
|
|
const realm = {};
|
|
|
|
set_realm(realm);
|
|
|
|
const current_user = {};
|
|
|
|
set_current_user(current_user);
|
2024-10-09 08:44:21 +02:00
|
|
|
const user_settings = {};
|
|
|
|
initialize_user_settings({user_settings});
|
2017-02-24 16:18:56 +01:00
|
|
|
|
2020-04-08 00:23:15 +02:00
|
|
|
function reset_jquery() {
|
|
|
|
// Avoid leaks.
|
2021-02-21 15:01:54 +01:00
|
|
|
$.clear_all_elements();
|
2020-04-08 00:23:15 +02:00
|
|
|
}
|
|
|
|
|
2020-02-04 21:50:55 +01:00
|
|
|
const new_user = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "new_user@example.com",
|
2020-02-04 21:50:55 +01:00
|
|
|
user_id: 101,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "New User",
|
2020-02-04 21:50:55 +01:00
|
|
|
date_joined: new Date(),
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "me@example.com",
|
2017-02-24 23:51:23 +01:00
|
|
|
user_id: 30,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Me Myself",
|
2018-08-13 00:46:29 +02:00
|
|
|
date_joined: new Date(),
|
2017-02-24 23:51:23 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@example.com",
|
2017-02-24 23:51:23 +01:00
|
|
|
user_id: 31,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice",
|
2023-01-03 08:29:15 +01:00
|
|
|
is_bot: false,
|
2017-02-24 23:51:23 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "bob@example.com",
|
2017-02-24 23:51:23 +01:00
|
|
|
user_id: 32,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Bob",
|
2017-02-24 23:51:23 +01:00
|
|
|
};
|
|
|
|
|
2023-01-03 08:29:15 +01:00
|
|
|
const bot = {
|
|
|
|
email: "bot@example.com",
|
|
|
|
user_id: 33,
|
|
|
|
full_name: "Bot",
|
|
|
|
is_bot: true,
|
|
|
|
};
|
|
|
|
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(new_user);
|
|
|
|
people.add_active_user(me);
|
2017-02-24 23:51:23 +01:00
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(alice);
|
|
|
|
people.add_active_user(bob);
|
2023-01-03 08:29:15 +01:00
|
|
|
people.add_active_user(bot);
|
2017-02-24 23:51:23 +01:00
|
|
|
|
2021-05-19 20:12:32 +02:00
|
|
|
const social = {
|
2021-05-19 18:55:36 +02:00
|
|
|
stream_id: 101,
|
|
|
|
name: "social",
|
|
|
|
subscribed: true,
|
|
|
|
};
|
2021-05-19 20:12:32 +02:00
|
|
|
stream_data.add_sub(social);
|
2021-05-19 18:55:36 +02:00
|
|
|
|
2024-07-08 19:00:08 +02:00
|
|
|
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]});
|
|
|
|
|
2021-02-23 12:09:35 +01:00
|
|
|
function test_ui(label, f) {
|
2021-05-19 20:08:09 +02:00
|
|
|
// TODO: initialize data more aggressively.
|
|
|
|
run_test(label, f);
|
|
|
|
}
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
function initialize_handlers({override}) {
|
2024-02-13 02:08:24 +01:00
|
|
|
override(realm, "realm_available_video_chat_providers", {disabled: {id: 0}});
|
|
|
|
override(realm, "realm_video_chat_provider", 0);
|
2023-12-14 23:51:33 +01:00
|
|
|
override(resize, "watch_manual_resize", noop);
|
2023-10-05 21:02:57 +02:00
|
|
|
compose_setup.initialize();
|
2021-02-23 12:09:35 +01:00
|
|
|
}
|
|
|
|
|
2023-10-16 12:55:24 +02:00
|
|
|
test_ui("send_message_success", ({override, override_rewire}) => {
|
2022-08-19 21:36:33 +02:00
|
|
|
mock_banners();
|
2023-10-16 12:55:24 +02:00
|
|
|
|
2024-02-17 20:03:03 +01:00
|
|
|
let draft_deleted;
|
|
|
|
let reify_message_id_checked;
|
2023-10-16 12:55:24 +02:00
|
|
|
function reset() {
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("foobarfoobar");
|
|
|
|
$("textarea#compose-textarea").trigger("blur");
|
2023-10-16 12:55:24 +02:00
|
|
|
$(".compose-submit-button .loader").show();
|
2024-02-17 20:03:03 +01:00
|
|
|
draft_deleted = false;
|
|
|
|
reify_message_id_checked = false;
|
2023-10-16 12:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
reset();
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
|
2024-02-17 20:03:03 +01:00
|
|
|
const draft_model = drafts.draft_model;
|
|
|
|
override(draft_model, "deleteDraft", (draft_id) => {
|
|
|
|
assert.equal(draft_id, 100);
|
|
|
|
draft_deleted = true;
|
|
|
|
});
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(echo, "reify_message_id", (local_id, message_id) => {
|
2020-02-12 09:32:25 +01:00
|
|
|
assert.equal(local_id, "1001");
|
2017-06-29 06:54:10 +02:00
|
|
|
assert.equal(message_id, 12);
|
|
|
|
reify_message_id_checked = true;
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
|
2023-12-02 13:34:05 +01:00
|
|
|
override(
|
|
|
|
onboarding_steps,
|
|
|
|
"ONE_TIME_NOTICES_TO_DISPLAY",
|
|
|
|
new Set(["visibility_policy_banner"]),
|
|
|
|
);
|
|
|
|
|
2023-10-16 12:55:24 +02:00
|
|
|
override(compose_notifications, "notify_automatic_new_visibility_policy", (message, data) => {
|
|
|
|
assert.equal(message.type, "stream");
|
|
|
|
assert.equal(message.stream_id, 1);
|
|
|
|
assert.equal(message.topic, "test");
|
|
|
|
assert.equal(data.id, 12);
|
|
|
|
assert.equal(data.automatic_new_visibility_policy, 2);
|
|
|
|
});
|
|
|
|
|
|
|
|
let request = {
|
|
|
|
locally_echoed: false,
|
|
|
|
local_id: "1001",
|
2024-02-17 20:03:03 +01:00
|
|
|
draft_id: 100,
|
2023-10-16 12:55:24 +02:00
|
|
|
type: "stream",
|
|
|
|
stream_id: 1,
|
|
|
|
topic: "test",
|
|
|
|
};
|
|
|
|
let data = {id: 12, automatic_new_visibility_policy: 2};
|
|
|
|
compose.send_message_success(request, data);
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
|
2023-11-02 19:29:54 +01:00
|
|
|
assert.equal($("textarea#compose-textarea").val(), "");
|
|
|
|
assert.ok($("textarea#compose-textarea").is_focused());
|
2023-04-25 10:02:12 +02:00
|
|
|
assert.ok(!$(".compose-submit-button .loader").visible());
|
2023-10-16 12:55:24 +02:00
|
|
|
assert.ok(reify_message_id_checked);
|
2024-02-17 20:03:03 +01:00
|
|
|
assert.ok(draft_deleted);
|
2023-10-16 12:55:24 +02:00
|
|
|
|
|
|
|
reset();
|
2017-06-29 06:54:10 +02:00
|
|
|
|
2023-10-16 12:55:24 +02:00
|
|
|
override(compose_notifications, "get_muted_narrow", (message) => {
|
|
|
|
assert.equal(message.type, "stream");
|
|
|
|
assert.equal(message.stream_id, 2);
|
|
|
|
assert.equal(message.topic, "test");
|
|
|
|
});
|
|
|
|
|
|
|
|
request = {
|
|
|
|
locally_echoed: false,
|
|
|
|
local_id: "1001",
|
2024-02-17 20:03:03 +01:00
|
|
|
draft_id: 100,
|
2023-10-16 12:55:24 +02:00
|
|
|
type: "stream",
|
|
|
|
stream_id: 2,
|
|
|
|
topic: "test",
|
|
|
|
};
|
|
|
|
data = {id: 12};
|
|
|
|
compose.send_message_success(request, data);
|
|
|
|
|
2023-11-02 19:29:54 +01:00
|
|
|
assert.equal($("textarea#compose-textarea").val(), "");
|
|
|
|
assert.ok($("textarea#compose-textarea").is_focused());
|
2023-10-16 12:55:24 +02:00
|
|
|
assert.ok(!$(".compose-submit-button .loader").visible());
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(reify_message_id_checked);
|
2024-02-17 20:03:03 +01:00
|
|
|
assert.ok(draft_deleted);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-29 14:31:26 +02:00
|
|
|
|
2022-08-19 22:24:06 +02:00
|
|
|
test_ui("send_message", ({override, override_rewire, mock_template}) => {
|
2022-08-19 21:36:33 +02:00
|
|
|
mock_banners();
|
2021-05-19 20:19:45 +02:00
|
|
|
MockDate.set(new Date(fake_now * 1000));
|
2024-02-02 20:56:49 +01:00
|
|
|
override_rewire(drafts, "sync_count", noop);
|
2021-05-19 20:19:45 +02:00
|
|
|
|
2017-07-06 21:57:25 +02:00
|
|
|
// This is the common setup stuff for all of the four tests.
|
2019-11-02 00:06:25 +01:00
|
|
|
let stub_state;
|
2017-07-06 21:57:25 +02:00
|
|
|
function initialize_state_stub_dict() {
|
|
|
|
stub_state = {};
|
2018-02-20 13:08:50 +01:00
|
|
|
stub_state.send_msg_called = 0;
|
2017-07-06 21:57:25 +02:00
|
|
|
stub_state.get_events_running_called = 0;
|
|
|
|
stub_state.reify_message_id_checked = 0;
|
|
|
|
return stub_state;
|
|
|
|
}
|
|
|
|
|
2022-10-07 18:58:30 +02:00
|
|
|
const $container = $(".top_left_drafts");
|
|
|
|
const $child = $(".unread_count");
|
|
|
|
$container.set_find_results(".unread_count", $child);
|
2024-02-07 08:14:58 +01:00
|
|
|
override_rewire(drafts, "update_compose_draft_count", noop);
|
2022-10-07 18:58:30 +02:00
|
|
|
|
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
|
|
|
override(server_events, "assert_get_events_running", () => {
|
|
|
|
stub_state.get_events_running_called += 1;
|
2020-12-01 00:53:02 +01:00
|
|
|
});
|
2017-07-06 21:57:25 +02:00
|
|
|
|
2024-03-16 00:57:19 +01:00
|
|
|
override_rewire(drafts, "update_draft", () => 100);
|
|
|
|
override(drafts.draft_model, "getDraft", (draft_id) => {
|
|
|
|
assert.equal(draft_id, 100);
|
|
|
|
return {};
|
|
|
|
});
|
|
|
|
|
2017-07-06 21:57:25 +02:00
|
|
|
// Tests start here.
|
|
|
|
(function test_message_send_success_codepath() {
|
|
|
|
stub_state = initialize_state_stub_dict();
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_state.topic("");
|
|
|
|
compose_state.set_message_type("private");
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", new_user.user_id);
|
2022-07-10 01:06:33 +02:00
|
|
|
override(compose_pm_pill, "get_emails", () => "alice@example.com");
|
2018-03-31 13:22:29 +02:00
|
|
|
|
2020-04-09 19:55:20 +02:00
|
|
|
const server_message_id = 127;
|
2024-01-22 07:55:55 +01:00
|
|
|
override(markdown, "render", noop);
|
2020-04-09 17:59:58 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(echo, "try_deliver_locally", (message_request) => {
|
2020-04-09 19:55:20 +02:00
|
|
|
const local_id_float = 123.04;
|
2024-06-03 20:39:19 +02:00
|
|
|
return echo.insert_local_message(message_request, local_id_float, (messages) => {
|
|
|
|
assert.equal(messages[0].timestamp, fake_now);
|
|
|
|
return messages;
|
|
|
|
});
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
override(transmit, "send_message", (payload, success) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const single_msg = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
|
|
|
content: "[foobar](/user_uploads/123456)",
|
2021-04-03 19:07:13 +02:00
|
|
|
sender_id: new_user.user_id,
|
2018-05-07 03:30:13 +02:00
|
|
|
queue_id: undefined,
|
2023-05-03 00:01:10 +02:00
|
|
|
resend: false,
|
2023-09-26 20:28:39 +02:00
|
|
|
stream_id: undefined,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "",
|
2019-05-23 22:18:58 +02:00
|
|
|
to: `[${alice.user_id}]`,
|
2020-07-15 01:29:15 +02:00
|
|
|
reply_to: "alice@example.com",
|
|
|
|
private_message_recipient: "alice@example.com",
|
|
|
|
to_user_ids: "31",
|
2024-02-17 20:03:03 +01:00
|
|
|
draft_id: 100,
|
2020-07-15 01:29:15 +02:00
|
|
|
local_id: "123.04",
|
2018-05-07 03:30:13 +02:00
|
|
|
locally_echoed: true,
|
2017-07-06 21:57:25 +02:00
|
|
|
};
|
2019-05-23 22:18:58 +02:00
|
|
|
|
2018-02-20 13:08:50 +01:00
|
|
|
assert.deepEqual(payload, single_msg);
|
2020-04-09 19:55:20 +02:00
|
|
|
payload.id = server_message_id;
|
2018-02-20 13:08:50 +01:00
|
|
|
success(payload);
|
|
|
|
stub_state.send_msg_called += 1;
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(echo, "reify_message_id", (local_id, message_id) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(typeof local_id, "string");
|
|
|
|
assert.equal(typeof message_id, "number");
|
2020-04-09 19:55:20 +02:00
|
|
|
assert.equal(message_id, server_message_id);
|
2017-07-06 21:57:25 +02:00
|
|
|
stub_state.reify_message_id_checked += 1;
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("[foobar](/user_uploads/123456)");
|
|
|
|
$("textarea#compose-textarea").trigger("blur");
|
2023-04-25 10:02:12 +02:00
|
|
|
$(".compose-submit-button .loader").show();
|
2017-07-06 21:57:25 +02:00
|
|
|
|
|
|
|
compose.send_message();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const state = {
|
2017-07-06 21:57:25 +02:00
|
|
|
get_events_running_called: 1,
|
|
|
|
reify_message_id_checked: 1,
|
2018-02-20 13:08:50 +01:00
|
|
|
send_msg_called: 1,
|
2017-07-06 21:57:25 +02:00
|
|
|
};
|
|
|
|
assert.deepEqual(stub_state, state);
|
2023-11-02 19:29:54 +01:00
|
|
|
assert.equal($("textarea#compose-textarea").val(), "");
|
|
|
|
assert.ok($("textarea#compose-textarea").is_focused());
|
2023-04-25 10:02:12 +02:00
|
|
|
assert.ok(!$(".compose-submit-button .loader").visible());
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2017-07-06 21:57:25 +02:00
|
|
|
|
|
|
|
// This is the additional setup which is common to both the tests below.
|
2023-06-29 21:59:08 +02:00
|
|
|
override(transmit, "send_message", (_payload, _success, error) => {
|
2018-02-20 13:08:50 +01:00
|
|
|
stub_state.send_msg_called += 1;
|
2020-07-15 01:29:15 +02:00
|
|
|
error("Error sending message: Server says 408");
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
2018-02-20 13:08:50 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let echo_error_msg_checked;
|
2018-02-20 13:08:50 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(echo, "message_send_error", (local_id, error_response) => {
|
2020-04-09 17:43:30 +02:00
|
|
|
assert.equal(local_id, 123.04);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(error_response, "Error sending message: Server says 408");
|
2017-07-06 21:57:25 +02:00
|
|
|
echo_error_msg_checked = true;
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
2017-07-06 21:57:25 +02:00
|
|
|
|
|
|
|
// Tests start here.
|
|
|
|
(function test_param_error_function_passed_from_send_message() {
|
|
|
|
stub_state = initialize_state_stub_dict();
|
|
|
|
|
|
|
|
compose.send_message();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const state = {
|
2017-07-06 21:57:25 +02:00
|
|
|
get_events_running_called: 1,
|
|
|
|
reify_message_id_checked: 0,
|
2018-02-20 13:08:50 +01:00
|
|
|
send_msg_called: 1,
|
2017-07-06 21:57:25 +02:00
|
|
|
};
|
|
|
|
assert.deepEqual(stub_state, state);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(echo_error_msg_checked);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2017-07-06 21:57:25 +02:00
|
|
|
|
|
|
|
(function test_error_codepath_local_id_undefined() {
|
2022-08-19 22:24:06 +02:00
|
|
|
let banner_rendered = false;
|
|
|
|
mock_template("compose_banner/compose_banner.hbs", false, (data) => {
|
|
|
|
assert.equal(data.classname, "generic_compose_error");
|
|
|
|
assert.equal(data.banner_text, "Error sending message: Server says 408");
|
|
|
|
banner_rendered = true;
|
2023-12-28 07:50:10 +01:00
|
|
|
return "<banner-stub>";
|
2022-08-19 22:24:06 +02:00
|
|
|
});
|
2017-07-06 21:57:25 +02:00
|
|
|
stub_state = initialize_state_stub_dict();
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("foobarfoobar");
|
|
|
|
$("textarea#compose-textarea").trigger("blur");
|
2023-04-25 10:02:12 +02:00
|
|
|
$(".compose-submit-button .loader").show();
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").off("select");
|
2017-07-06 21:57:25 +02:00
|
|
|
echo_error_msg_checked = false;
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(echo, "try_deliver_locally", noop);
|
2017-07-06 21:57:25 +02:00
|
|
|
|
2021-05-19 20:28:42 +02:00
|
|
|
override(sent_messages, "get_new_local_id", () => "loc-55");
|
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
2017-07-30 12:56:46 +02:00
|
|
|
|
2017-07-06 21:57:25 +02:00
|
|
|
compose.send_message();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const state = {
|
2017-07-06 21:57:25 +02:00
|
|
|
get_events_running_called: 1,
|
|
|
|
reify_message_id_checked: 0,
|
2018-02-20 13:08:50 +01:00
|
|
|
send_msg_called: 1,
|
2017-07-06 21:57:25 +02:00
|
|
|
};
|
|
|
|
assert.deepEqual(stub_state, state);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!echo_error_msg_checked);
|
2022-08-19 22:24:06 +02:00
|
|
|
assert.ok(banner_rendered);
|
2023-11-02 19:29:54 +01:00
|
|
|
assert.equal($("textarea#compose-textarea").val(), "foobarfoobar");
|
|
|
|
assert.ok($("textarea#compose-textarea").is_focused());
|
2023-04-25 10:02:12 +02:00
|
|
|
assert.ok(!$(".compose-submit-button .loader").visible());
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-06 21:57:25 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test_ui("enter_with_preview_open", ({override, override_rewire}) => {
|
2022-08-19 21:36:33 +02:00
|
|
|
mock_banners();
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").toggleClass = noop;
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(compose_banner, "clear_message_sent_banners", noop);
|
2021-05-19 21:15:26 +02:00
|
|
|
override(document, "to_$", () => $("document-stub"));
|
2021-11-30 06:26:05 +01:00
|
|
|
let show_button_spinner_called = false;
|
2022-03-16 21:37:41 +01:00
|
|
|
override(loading, "show_button_spinner", ($spinner) => {
|
2023-04-25 10:02:12 +02:00
|
|
|
assert.equal($spinner.selector, ".compose-submit-button .loader");
|
2021-11-30 06:26:05 +01:00
|
|
|
show_button_spinner_called = true;
|
|
|
|
});
|
2021-05-19 18:03:57 +02:00
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", new_user.user_id);
|
2021-04-03 19:07:13 +02:00
|
|
|
|
2017-07-07 19:31:32 +02:00
|
|
|
// Test sending a message with content.
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_state.set_message_type("stream");
|
2023-06-27 01:40:25 +02:00
|
|
|
compose_state.set_stream_id(social.stream_id);
|
2021-05-19 18:55:36 +02:00
|
|
|
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("message me");
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .undo_markdown_preview").show();
|
|
|
|
$("#compose .preview_message_area").show();
|
|
|
|
$("#compose .markdown_preview").hide();
|
2022-01-30 16:00:45 +01:00
|
|
|
$("#compose").addClass("preview_mode");
|
2024-10-09 21:10:22 +02:00
|
|
|
override(user_settings, "enter_sends", true);
|
2019-11-02 00:06:25 +01:00
|
|
|
let send_message_called = false;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(compose, "send_message", () => {
|
2017-07-07 00:33:46 +02:00
|
|
|
send_message_called = true;
|
2021-02-28 00:51:57 +01:00
|
|
|
});
|
2017-07-07 00:33:46 +02:00
|
|
|
compose.enter_with_preview_open();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$("#compose .undo_markdown_preview").visible());
|
|
|
|
assert.ok(!$("#compose .preview_message_area").visible());
|
|
|
|
assert.ok($("#compose .markdown_preview").visible());
|
2022-01-30 16:00:45 +01:00
|
|
|
assert.ok(!$("#compose").hasClass("preview_mode"));
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(send_message_called);
|
2021-11-30 06:26:05 +01:00
|
|
|
assert.ok(show_button_spinner_called);
|
2017-07-07 00:33:46 +02:00
|
|
|
|
2024-10-09 21:10:22 +02:00
|
|
|
override(user_settings, "enter_sends", false);
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").trigger("blur");
|
2017-07-07 00:33:46 +02:00
|
|
|
compose.enter_with_preview_open();
|
2023-11-02 19:29:54 +01:00
|
|
|
assert.ok($("textarea#compose-textarea").is_focused());
|
2017-07-07 19:31:32 +02:00
|
|
|
|
|
|
|
// Test sending a message without content.
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("");
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .preview_message_area").show();
|
2024-10-09 21:10:22 +02:00
|
|
|
override(user_settings, "enter_sends", true);
|
2017-07-07 19:31:32 +02:00
|
|
|
|
|
|
|
compose.enter_with_preview_open();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-07 00:33:46 +02:00
|
|
|
|
2023-01-03 09:35:18 +01:00
|
|
|
test_ui("finish", ({override, override_rewire}) => {
|
2022-08-19 21:36:33 +02:00
|
|
|
mock_banners();
|
2022-10-21 00:44:55 +02:00
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(compose_banner, "clear_message_sent_banners", noop);
|
2021-05-19 21:15:26 +02:00
|
|
|
override(document, "to_$", () => $("document-stub"));
|
2021-11-30 06:26:05 +01:00
|
|
|
let show_button_spinner_called = false;
|
2022-03-16 21:37:41 +01:00
|
|
|
override(loading, "show_button_spinner", ($spinner) => {
|
2023-04-25 10:02:12 +02:00
|
|
|
assert.equal($spinner.selector, ".compose-submit-button .loader");
|
2021-11-30 06:26:05 +01:00
|
|
|
show_button_spinner_called = true;
|
|
|
|
});
|
2021-05-19 18:03:57 +02:00
|
|
|
|
2017-07-07 00:48:51 +02:00
|
|
|
(function test_when_compose_validation_fails() {
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").toggleClass = (classname, value) => {
|
2023-01-03 09:35:18 +01:00
|
|
|
assert.equal(classname, "invalid");
|
|
|
|
assert.equal(value, true);
|
|
|
|
};
|
2017-07-07 00:48:51 +02:00
|
|
|
$("#compose_invite_users").show();
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#compose-send-button").prop("disabled", false);
|
2020-07-20 21:24:26 +02:00
|
|
|
$("#compose-send-button").trigger("focus");
|
2023-04-25 10:02:12 +02:00
|
|
|
$(".compose-submit-button .loader").hide();
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").off("select");
|
|
|
|
$("textarea#compose-textarea").val("");
|
2023-08-04 23:40:48 +02:00
|
|
|
override_rewire(compose_ui, "compose_spinner_visible", false);
|
2019-11-02 00:06:25 +01:00
|
|
|
const res = compose.finish();
|
2017-07-07 00:48:51 +02:00
|
|
|
assert.equal(res, false);
|
2022-08-20 02:51:13 +02:00
|
|
|
assert.ok(!$("#compose_banners .recipient_not_subscribed").visible());
|
2023-04-25 10:02:12 +02:00
|
|
|
assert.ok(!$(".compose-submit-button .loader").visible());
|
2021-11-30 06:26:05 +01:00
|
|
|
assert.ok(show_button_spinner_called);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2017-07-07 00:48:51 +02:00
|
|
|
|
|
|
|
(function test_when_compose_validation_succeed() {
|
2021-07-13 21:25:31 +02:00
|
|
|
// Testing successfully sending of a message.
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .undo_markdown_preview").show();
|
|
|
|
$("#compose .preview_message_area").show();
|
|
|
|
$("#compose .markdown_preview").hide();
|
2022-01-30 16:00:45 +01:00
|
|
|
$("#compsoe").addClass("preview_mode");
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("foobarfoobar");
|
2023-08-04 23:40:48 +02:00
|
|
|
override_rewire(compose_ui, "compose_spinner_visible", false);
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_state.set_message_type("private");
|
2022-07-10 01:06:33 +02:00
|
|
|
override(compose_pm_pill, "get_emails", () => "bob@example.com");
|
|
|
|
override(compose_pm_pill, "get_user_ids", () => []);
|
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);
|
2018-03-31 13:22:29 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let compose_finished_event_checked = false;
|
2020-07-21 05:53:07 +02:00
|
|
|
$(document).on("compose_finished.zulip", () => {
|
2018-04-12 18:06:39 +02:00
|
|
|
compose_finished_event_checked = true;
|
2020-07-21 05:53:07 +02:00
|
|
|
});
|
2019-11-02 00:06:25 +01:00
|
|
|
let send_message_called = false;
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(compose, "send_message", () => {
|
2017-07-07 00:48:51 +02:00
|
|
|
send_message_called = true;
|
2021-02-28 00:51:57 +01:00
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose.finish());
|
|
|
|
assert.ok(!$("#compose .undo_markdown_preview").visible());
|
|
|
|
assert.ok(!$("#compose .preview_message_area").visible());
|
|
|
|
assert.ok($("#compose .markdown_preview").visible());
|
2022-01-30 16:00:45 +01:00
|
|
|
assert.ok(!$("#compose").hasClass("preview_mode"));
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(send_message_called);
|
|
|
|
assert.ok(compose_finished_event_checked);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-07 00:48:51 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test_ui("initialize", ({override}) => {
|
2021-05-19 18:03:57 +02:00
|
|
|
let compose_actions_expected_opts;
|
|
|
|
let compose_actions_start_checked;
|
|
|
|
|
2024-04-04 02:38:16 +02:00
|
|
|
override(compose_actions, "start", (opts) => {
|
2021-05-19 18:03:57 +02:00
|
|
|
assert.deepEqual(opts, compose_actions_expected_opts);
|
|
|
|
compose_actions_start_checked = true;
|
|
|
|
});
|
|
|
|
|
2017-07-07 15:14:00 +02:00
|
|
|
// In this test we mostly do the setup stuff in addition to testing the
|
|
|
|
// normal workflow of the function. All the tests for the on functions are
|
|
|
|
// done in subsequent tests directly below this test.
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
override(realm, "realm_available_video_chat_providers", {disabled: {id: 0}});
|
|
|
|
override(realm, "realm_video_chat_provider", 0);
|
2021-03-05 22:45:18 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let resize_watch_manual_resize_checked = false;
|
2021-05-19 20:28:42 +02:00
|
|
|
override(resize, "watch_manual_resize", (elem) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal("#compose-textarea", elem);
|
2017-07-07 15:14:00 +02:00
|
|
|
resize_watch_manual_resize_checked = true;
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "max_file_upload_size_mib", 512);
|
2017-07-07 15:14:00 +02:00
|
|
|
|
2019-11-21 05:24:55 +01:00
|
|
|
let uppy_cancel_all_called = false;
|
2024-02-16 00:25:31 +01:00
|
|
|
override(upload, "compose_upload_cancel", () => {
|
|
|
|
uppy_cancel_all_called = true;
|
2021-02-28 00:52:20 +01:00
|
|
|
});
|
2017-07-07 15:14:00 +02:00
|
|
|
|
2023-10-05 21:02:57 +02:00
|
|
|
compose_setup.initialize();
|
2017-07-07 15:14:00 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(resize_watch_manual_resize_checked);
|
2017-07-07 15:14:00 +02:00
|
|
|
|
|
|
|
function set_up_compose_start_mock(expected_opts) {
|
|
|
|
compose_actions_start_checked = false;
|
2024-04-04 02:38:16 +02:00
|
|
|
compose_actions_expected_opts = {
|
|
|
|
...expected_opts,
|
|
|
|
message_type: "stream",
|
|
|
|
};
|
2017-07-07 15:14:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(function test_page_params_narrow_path() {
|
|
|
|
page_params.narrow = true;
|
|
|
|
|
|
|
|
reset_jquery();
|
|
|
|
set_up_compose_start_mock({});
|
|
|
|
|
2023-10-05 21:02:57 +02:00
|
|
|
compose_setup.initialize();
|
2017-07-07 15:14:00 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_actions_start_checked);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2017-07-07 15:14:00 +02:00
|
|
|
|
|
|
|
(function test_page_params_narrow_topic() {
|
2020-07-15 01:29:15 +02:00
|
|
|
page_params.narrow_topic = "testing";
|
2017-07-07 15:14:00 +02:00
|
|
|
|
|
|
|
reset_jquery();
|
2020-07-15 01:29:15 +02:00
|
|
|
set_up_compose_start_mock({topic: "testing"});
|
2017-07-07 15:14:00 +02:00
|
|
|
|
2023-10-05 21:02:57 +02:00
|
|
|
compose_setup.initialize();
|
2017-07-07 15:14:00 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_actions_start_checked);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2019-11-21 05:24:55 +01:00
|
|
|
|
|
|
|
(function test_abort_xhr() {
|
|
|
|
reset_jquery();
|
2023-10-05 21:02:57 +02:00
|
|
|
compose_setup.initialize();
|
2019-11-21 05:24:55 +01:00
|
|
|
|
2023-10-05 21:02:57 +02:00
|
|
|
compose_setup.abort_xhr();
|
2019-11-21 05:24:55 +01:00
|
|
|
|
|
|
|
assert.equal($("#compose-send-button").attr(), undefined);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(uppy_cancel_all_called);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-07 03:59:08 +02:00
|
|
|
|
2023-03-31 06:27:36 +02:00
|
|
|
test_ui("update_fade", ({override, override_rewire}) => {
|
2023-02-02 05:43:24 +01:00
|
|
|
mock_banners();
|
2022-07-10 01:06:33 +02:00
|
|
|
initialize_handlers({override});
|
2021-05-19 20:08:09 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let set_focused_recipient_checked = false;
|
|
|
|
let update_all_called = false;
|
2021-08-16 17:10:43 +02:00
|
|
|
let update_narrow_to_recipient_visibility_called = false;
|
2017-07-07 15:41:13 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
override(compose_fade, "set_focused_recipient", (msg_type) => {
|
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
|
|
|
assert.equal(msg_type, "private");
|
|
|
|
set_focused_recipient_checked = true;
|
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
override(compose_fade, "update_all", () => {
|
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
|
|
|
update_all_called = true;
|
2020-12-01 00:53:02 +01:00
|
|
|
});
|
2017-07-07 15:41:13 +02:00
|
|
|
|
2023-03-31 06:27:36 +02:00
|
|
|
override_rewire(compose_recipient, "update_narrow_to_recipient_visibility", () => {
|
2021-08-16 17:10:43 +02:00
|
|
|
update_narrow_to_recipient_visibility_called = true;
|
|
|
|
});
|
2024-02-07 08:14:58 +01:00
|
|
|
override_rewire(drafts, "update_compose_draft_count", noop);
|
2021-08-16 17:10:43 +02:00
|
|
|
|
2024-01-07 23:28:42 +01:00
|
|
|
compose_state.set_message_type(undefined);
|
2023-03-31 06:27:36 +02:00
|
|
|
compose_recipient.update_on_recipient_change();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!set_focused_recipient_checked);
|
|
|
|
assert.ok(!update_all_called);
|
2021-08-16 17:10:43 +02:00
|
|
|
assert.ok(update_narrow_to_recipient_visibility_called);
|
|
|
|
|
|
|
|
update_narrow_to_recipient_visibility_called = false;
|
2017-07-07 15:41:13 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
compose_state.set_message_type("private");
|
2023-03-31 06:27:36 +02:00
|
|
|
compose_recipient.update_on_recipient_change();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(set_focused_recipient_checked);
|
|
|
|
assert.ok(update_all_called);
|
2021-08-16 17:10:43 +02:00
|
|
|
assert.ok(update_narrow_to_recipient_visibility_called);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-07 15:41:13 +02:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test_ui("trigger_submit_compose_form", ({override, override_rewire}) => {
|
2022-07-10 01:06:33 +02:00
|
|
|
initialize_handlers({override});
|
2021-05-19 20:08:09 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let prevent_default_checked = false;
|
|
|
|
let compose_finish_checked = false;
|
|
|
|
const e = {
|
2020-07-20 22:18:43 +02:00
|
|
|
preventDefault() {
|
2017-07-07 15:42:51 +02:00
|
|
|
prevent_default_checked = true;
|
|
|
|
},
|
|
|
|
};
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(compose, "finish", () => {
|
2017-07-07 15:42:51 +02:00
|
|
|
compose_finish_checked = true;
|
2021-02-28 00:51:57 +01:00
|
|
|
});
|
2017-07-07 15:42:51 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const submit_handler = $("#compose form").get_on_handler("submit");
|
2017-07-07 15:42:51 +02:00
|
|
|
|
|
|
|
submit_handler(e);
|
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(prevent_default_checked);
|
|
|
|
assert.ok(compose_finish_checked);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-07 15:42:51 +02:00
|
|
|
|
2023-04-27 23:45:30 +02:00
|
|
|
test_ui("on_events", ({override, override_rewire}) => {
|
2022-07-10 01:06:33 +02:00
|
|
|
initialize_handlers({override});
|
2021-05-19 20:08:09 +02:00
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
override(rendered_markdown, "update_elements", noop);
|
2021-05-19 18:03:57 +02:00
|
|
|
|
2017-07-08 00:22:11 +02:00
|
|
|
(function test_attach_files_compose_clicked() {
|
2021-04-20 16:22:50 +02:00
|
|
|
const handler = $("#compose").get_on_handler("click", ".compose_upload_file");
|
2019-11-02 00:06:25 +01:00
|
|
|
let compose_file_input_clicked = false;
|
2021-04-20 16:14:55 +02:00
|
|
|
$("#compose .file_input").on("click", () => {
|
2017-07-08 00:22:11 +02:00
|
|
|
compose_file_input_clicked = true;
|
2020-07-21 05:53:07 +02:00
|
|
|
});
|
2019-02-02 15:48:30 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = {
|
2019-02-02 15:48:30 +01:00
|
|
|
preventDefault: noop,
|
2021-12-03 06:29:43 +01:00
|
|
|
stopPropagation: noop,
|
2019-02-02 15:48:30 +01:00
|
|
|
};
|
|
|
|
|
2017-07-08 00:22:11 +02:00
|
|
|
handler(event);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(compose_file_input_clicked);
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2017-07-08 01:21:20 +02:00
|
|
|
|
|
|
|
(function test_markdown_preview_compose_clicked() {
|
|
|
|
// Tests setup
|
2024-07-30 22:03:41 +02:00
|
|
|
$("textarea#compose-textarea").set_height(50);
|
|
|
|
$("#compose .preview_message_area").css = noop;
|
|
|
|
|
2017-07-08 01:21:20 +02:00
|
|
|
function setup_visibilities() {
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .markdown_preview").show();
|
|
|
|
$("#compose .undo_markdown_preview").hide();
|
|
|
|
$("#compose .preview_message_area").hide();
|
2022-01-30 16:00:45 +01:00
|
|
|
$("#compose").removeClass("preview_mode");
|
2017-07-08 01:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function assert_visibilities() {
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$("#compose .markdown_preview").visible());
|
|
|
|
assert.ok($("#compose .undo_markdown_preview").visible());
|
|
|
|
assert.ok($("#compose .preview_message_area").visible());
|
2022-01-30 16:00:45 +01:00
|
|
|
assert.ok($("#compose").hasClass("preview_mode"));
|
2017-07-08 01:21:20 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 02:51:33 +02:00
|
|
|
function setup_mock_markdown_contains_backend_only_syntax(msg_content, return_val) {
|
2021-05-19 20:28:42 +02:00
|
|
|
override(markdown, "contains_backend_only_syntax", (msg) => {
|
2017-07-08 01:21:20 +02:00
|
|
|
assert.equal(msg, msg_content);
|
|
|
|
return return_val;
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
2017-07-08 01:21:20 +02:00
|
|
|
}
|
|
|
|
|
2019-12-03 15:29:44 +01:00
|
|
|
function setup_mock_markdown_is_status_message(msg_content, return_val) {
|
2021-05-19 20:28:42 +02:00
|
|
|
override(markdown, "is_status_message", (content) => {
|
2018-01-21 19:27:36 +01:00
|
|
|
assert.equal(content, msg_content);
|
|
|
|
return return_val;
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
2018-01-21 19:27:36 +01:00
|
|
|
}
|
|
|
|
|
2017-07-08 01:21:20 +02:00
|
|
|
function test_post_success(success_callback) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const resp = {
|
2024-07-23 03:42:56 +02:00
|
|
|
msg: "",
|
|
|
|
result: "success",
|
2020-07-15 01:29:15 +02:00
|
|
|
rendered: "Server: foobarfoobar",
|
2017-07-08 01:21:20 +02:00
|
|
|
};
|
|
|
|
success_callback(resp);
|
2021-04-20 19:50:01 +02:00
|
|
|
assert.equal($("#compose .preview_content").html(), "Server: foobarfoobar");
|
2017-07-08 01:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_post_error(error_callback) {
|
|
|
|
error_callback();
|
2021-04-14 00:59:25 +02:00
|
|
|
assert.equal(
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .preview_content").html(),
|
2021-04-14 00:59:25 +02:00
|
|
|
"translated HTML: Failed to generate preview",
|
|
|
|
);
|
2017-07-08 01:21:20 +02:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:42:06 +02:00
|
|
|
let current_message;
|
|
|
|
|
|
|
|
override(channel, "post", (payload) => {
|
|
|
|
assert.equal(payload.url, "/json/messages/render");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(payload.data);
|
2021-05-19 20:42:06 +02:00
|
|
|
assert.deepEqual(payload.data.content, current_message);
|
|
|
|
|
|
|
|
function test(func, param) {
|
|
|
|
let destroy_indicator_called = false;
|
2022-03-16 21:37:41 +01:00
|
|
|
override(loading, "destroy_indicator", ($spinner) => {
|
|
|
|
assert.equal($spinner, $("#compose .markdown_preview_spinner"));
|
2021-05-19 20:42:06 +02:00
|
|
|
destroy_indicator_called = true;
|
|
|
|
});
|
|
|
|
setup_mock_markdown_contains_backend_only_syntax(current_message, true);
|
|
|
|
|
|
|
|
func(param);
|
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(destroy_indicator_called);
|
2021-05-19 20:42:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test(test_post_error, payload.error);
|
|
|
|
test(test_post_success, payload.success);
|
|
|
|
});
|
2017-07-08 01:21:20 +02:00
|
|
|
|
2021-04-20 19:50:01 +02:00
|
|
|
const handler = $("#compose").get_on_handler("click", ".markdown_preview");
|
2017-07-08 01:21:20 +02:00
|
|
|
|
|
|
|
// Tests start here
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("");
|
2017-07-08 01:21:20 +02:00
|
|
|
setup_visibilities();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = {
|
2019-02-02 15:48:30 +01:00
|
|
|
preventDefault: noop,
|
2021-12-03 06:29:43 +01:00
|
|
|
stopPropagation: noop,
|
2019-02-02 15:48:30 +01:00
|
|
|
};
|
|
|
|
|
2017-07-08 01:21:20 +02:00
|
|
|
handler(event);
|
|
|
|
|
2021-04-20 19:50:01 +02:00
|
|
|
assert.equal($("#compose .preview_content").html(), "translated HTML: Nothing to preview");
|
2017-07-08 01:21:20 +02:00
|
|
|
assert_visibilities();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let make_indicator_called = false;
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("```foobarfoobar```");
|
2017-07-08 01:21:20 +02:00
|
|
|
setup_visibilities();
|
2020-07-15 01:29:15 +02:00
|
|
|
setup_mock_markdown_contains_backend_only_syntax("```foobarfoobar```", true);
|
|
|
|
setup_mock_markdown_is_status_message("```foobarfoobar```", false);
|
2021-05-19 20:28:42 +02:00
|
|
|
|
2022-03-16 21:37:41 +01:00
|
|
|
override(loading, "make_indicator", ($spinner) => {
|
|
|
|
assert.equal($spinner.selector, "#compose .markdown_preview_spinner");
|
2017-07-08 01:21:20 +02:00
|
|
|
make_indicator_called = true;
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
|
|
|
|
2021-05-19 20:42:06 +02:00
|
|
|
current_message = "```foobarfoobar```";
|
2017-07-08 01:21:20 +02:00
|
|
|
|
|
|
|
handler(event);
|
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(make_indicator_called);
|
2017-07-08 01:21:20 +02:00
|
|
|
assert_visibilities();
|
|
|
|
|
2024-01-22 07:55:55 +01:00
|
|
|
let render_called = false;
|
2023-11-02 19:29:54 +01:00
|
|
|
$("textarea#compose-textarea").val("foobarfoobar");
|
2017-07-08 01:21:20 +02:00
|
|
|
setup_visibilities();
|
2020-07-15 01:29:15 +02:00
|
|
|
setup_mock_markdown_contains_backend_only_syntax("foobarfoobar", false);
|
|
|
|
setup_mock_markdown_is_status_message("foobarfoobar", false);
|
2021-05-19 20:42:06 +02:00
|
|
|
|
|
|
|
current_message = "foobarfoobar";
|
|
|
|
|
2024-01-22 07:55:55 +01:00
|
|
|
override(markdown, "render", (raw_content) => {
|
|
|
|
assert.equal(raw_content, "foobarfoobar");
|
|
|
|
render_called = true;
|
2021-05-19 20:28:42 +02:00
|
|
|
});
|
2017-07-08 01:21:20 +02:00
|
|
|
|
|
|
|
handler(event);
|
|
|
|
|
2024-01-22 07:55:55 +01:00
|
|
|
assert.ok(render_called);
|
2017-07-08 01:21:20 +02:00
|
|
|
assert_visibilities();
|
2021-04-20 19:50:01 +02:00
|
|
|
assert.equal($("#compose .preview_content").html(), "Server: foobarfoobar");
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2017-07-08 01:27:11 +02:00
|
|
|
|
|
|
|
(function test_undo_markdown_preview_clicked() {
|
2021-04-20 19:50:01 +02:00
|
|
|
const handler = $("#compose").get_on_handler("click", ".undo_markdown_preview");
|
2017-07-08 01:27:11 +02:00
|
|
|
|
2021-04-20 19:50:01 +02:00
|
|
|
$("#compose .undo_markdown_preview").show();
|
|
|
|
$("#compose .preview_message_area").show();
|
|
|
|
$("#compose .markdown_preview").hide();
|
2022-01-30 16:00:45 +01:00
|
|
|
$("#compose").removeClass("preview_mode");
|
2017-07-08 01:27:11 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const event = {
|
2019-02-02 15:48:30 +01:00
|
|
|
preventDefault: noop,
|
2021-12-03 06:29:43 +01:00
|
|
|
stopPropagation: noop,
|
2019-02-02 15:48:30 +01:00
|
|
|
};
|
|
|
|
|
2023-04-27 23:45:30 +02:00
|
|
|
override_rewire(compose_recipient, "update_placeholder_text", noop);
|
2024-04-23 09:04:05 +02:00
|
|
|
override(narrow_state, "narrowed_by_reply", () => true);
|
2024-04-05 13:32:42 +02:00
|
|
|
override(
|
|
|
|
compose_notifications,
|
|
|
|
"maybe_show_one_time_non_interleaved_view_messages_fading_banner",
|
|
|
|
noop,
|
|
|
|
);
|
2022-08-16 10:15:20 +02:00
|
|
|
|
2017-07-08 01:27:11 +02:00
|
|
|
handler(event);
|
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$("#compose .undo_markdown_preview").visible());
|
|
|
|
assert.ok(!$("#compose .preview_message_area").visible());
|
|
|
|
assert.ok($("#compose .markdown_preview").visible());
|
2022-01-30 16:00:45 +01:00
|
|
|
assert.ok(!$("#compose").hasClass("preview_mode"));
|
2020-07-16 22:35:58 +02:00
|
|
|
})();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-07-08 00:06:38 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test_ui("create_message_object", ({override, override_rewire}) => {
|
2023-04-23 14:18:48 +02:00
|
|
|
mock_banners();
|
2022-10-21 00:44:55 +02:00
|
|
|
|
2023-06-27 01:40:25 +02:00
|
|
|
compose_state.set_stream_id(social.stream_id);
|
2023-11-02 19:29:54 +01:00
|
|
|
$("input#stream_message_recipient_topic").val("lunch");
|
|
|
|
$("textarea#compose-textarea").val("burrito");
|
2017-02-24 16:18:56 +01:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
compose_state.set_message_type("stream");
|
2017-02-24 16:18:56 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let message = compose.create_message_object();
|
2021-05-19 20:12:32 +02:00
|
|
|
assert.equal(message.to, social.stream_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(message.topic, "lunch");
|
|
|
|
assert.equal(message.content, "burrito");
|
2020-02-07 21:18:20 +01:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
compose_state.set_message_type("private");
|
|
|
|
override(compose_pm_pill, "get_emails", () => "alice@example.com,bob@example.com");
|
2018-03-31 13:22:29 +02:00
|
|
|
|
2017-03-29 08:54:26 +02:00
|
|
|
message = compose.create_message_object();
|
2019-05-23 22:18:58 +02:00
|
|
|
assert.deepEqual(message.to, [alice.user_id, bob.user_id]);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(message.to_user_ids, "31,32");
|
|
|
|
assert.equal(message.content, "burrito");
|
2017-02-24 16:18:56 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(people, "email_list_to_user_ids_string", () => undefined);
|
2019-05-23 22:18:58 +02:00
|
|
|
message = compose.create_message_object();
|
|
|
|
assert.deepEqual(message.to, [alice.email, bob.email]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-07-23 02:41:55 +02:00
|
|
|
|
2023-01-03 08:29:15 +01:00
|
|
|
test_ui("DM policy disabled", ({override, override_rewire}) => {
|
|
|
|
// Disable dms in the organisation
|
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-01-03 08:29:15 +01:00
|
|
|
let reply_disabled = false;
|
|
|
|
override_rewire(compose_closed_ui, "update_reply_button_state", (disabled = false) => {
|
|
|
|
reply_disabled = disabled;
|
|
|
|
});
|
|
|
|
// For single bot recipient, Bot, the "Message X" button is not disabled
|
|
|
|
override(narrow_state, "pm_ids_string", () => "33");
|
|
|
|
compose_closed_ui.update_buttons_for_private();
|
|
|
|
assert.ok(!reply_disabled);
|
|
|
|
// For human user, Alice, the "Message X" button is disabled
|
|
|
|
override(narrow_state, "pm_ids_string", () => "31");
|
|
|
|
compose_closed_ui.update_buttons_for_private();
|
|
|
|
assert.ok(reply_disabled);
|
|
|
|
});
|
|
|
|
|
2022-05-07 02:53:53 +02:00
|
|
|
run_test("reset MockDate", () => {
|
|
|
|
MockDate.reset();
|
|
|
|
});
|