mirror of https://github.com/zulip/zulip.git
tests: Use override for realm.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
9cd2408e0d
commit
95153b3f0c
|
@ -717,8 +717,8 @@ test("insert_unfiltered_user_with_filter", () => {
|
|||
activity_ui.redraw_user(fred.user_id);
|
||||
});
|
||||
|
||||
test("realm_presence_disabled", () => {
|
||||
realm.realm_presence_disabled = true;
|
||||
test("realm_presence_disabled", ({override}) => {
|
||||
override(realm, "realm_presence_disabled", true);
|
||||
|
||||
activity_ui.redraw_user();
|
||||
activity_ui.build_user_sidebar();
|
||||
|
@ -734,9 +734,9 @@ test("update_presence_info", ({override, override_rewire}) => {
|
|||
override(pm_list, "update_private_messages", noop);
|
||||
override_rewire(activity_ui, "update_presence_indicators", noop);
|
||||
|
||||
realm.realm_presence_disabled = false;
|
||||
realm.server_presence_ping_interval_seconds = 60;
|
||||
realm.server_presence_offline_threshold_seconds = 200;
|
||||
override(realm, "realm_presence_disabled", false);
|
||||
override(realm, "server_presence_ping_interval_seconds", 60);
|
||||
override(realm, "server_presence_offline_threshold_seconds", 200);
|
||||
|
||||
const server_time = 500;
|
||||
const info = {
|
||||
|
@ -918,7 +918,7 @@ test("test_send_or_receive_no_presence_for_spectator", () => {
|
|||
activity.send_presence_to_server();
|
||||
});
|
||||
|
||||
test("check_should_redraw_new_user", () => {
|
||||
test("check_should_redraw_new_user", ({override}) => {
|
||||
presence.presence_info.set(9999, {status: "active"});
|
||||
|
||||
// A user that wasn't yet known, but has presence info should be redrawn
|
||||
|
@ -927,10 +927,10 @@ test("check_should_redraw_new_user", () => {
|
|||
|
||||
// We don't even build the user sidebar if realm_presence_disabled is true,
|
||||
// so nothing to redraw.
|
||||
realm.realm_presence_disabled = true;
|
||||
override(realm, "realm_presence_disabled", true);
|
||||
assert.equal(activity_ui.check_should_redraw_new_user(9999), false);
|
||||
|
||||
realm.realm_presence_disabled = false;
|
||||
override(realm, "realm_presence_disabled", false);
|
||||
// A new user that didn't have presence info should not be redrawn.
|
||||
assert.equal(activity_ui.check_should_redraw_new_user(99999), false);
|
||||
});
|
||||
|
|
|
@ -417,7 +417,7 @@ test("get_conversation_participants", ({override_rewire}) => {
|
|||
});
|
||||
|
||||
test("level", ({override}) => {
|
||||
realm.server_presence_offline_threshold_seconds = 200;
|
||||
override(realm, "server_presence_offline_threshold_seconds", 200);
|
||||
|
||||
add_canned_users();
|
||||
assert.equal(buddy_data.level(me.user_id), 0);
|
||||
|
@ -534,12 +534,12 @@ test("user_last_seen_time_status", ({override}) => {
|
|||
|
||||
assert.equal(buddy_data.user_last_seen_time_status(selma.user_id), "translated: Active now");
|
||||
|
||||
realm.realm_is_zephyr_mirror_realm = true;
|
||||
override(realm, "realm_is_zephyr_mirror_realm", true);
|
||||
assert.equal(
|
||||
buddy_data.user_last_seen_time_status(old_user.user_id),
|
||||
"translated: Activity unknown",
|
||||
);
|
||||
realm.realm_is_zephyr_mirror_realm = false;
|
||||
override(realm, "realm_is_zephyr_mirror_realm", false);
|
||||
assert.equal(
|
||||
buddy_data.user_last_seen_time_status(old_user.user_id),
|
||||
"translated: Not active in the last year",
|
||||
|
|
|
@ -522,7 +522,7 @@ test_ui("initialize", ({override}) => {
|
|||
resize_watch_manual_resize_checked = true;
|
||||
});
|
||||
|
||||
realm.max_file_upload_size_mib = 512;
|
||||
override(realm, "max_file_upload_size_mib", 512);
|
||||
|
||||
let uppy_cancel_all_called = false;
|
||||
override(upload, "compose_upload_cancel", () => {
|
||||
|
|
|
@ -569,8 +569,8 @@ test("on_narrow", ({override, override_rewire}) => {
|
|||
start_called = true;
|
||||
});
|
||||
narrowed_by_pm_reply = true;
|
||||
realm.realm_direct_message_permission_group = nobody.id;
|
||||
realm.realm_direct_message_initiator_group = everyone.id;
|
||||
override(realm, "realm_direct_message_permission_group", nobody.id);
|
||||
override(realm, "realm_direct_message_initiator_group", everyone.id);
|
||||
compose_actions.on_narrow({
|
||||
force_close: false,
|
||||
trigger: "not-search",
|
||||
|
@ -585,7 +585,7 @@ test("on_narrow", ({override, override_rewire}) => {
|
|||
});
|
||||
assert.ok(start_called);
|
||||
|
||||
realm.realm_direct_message_permission_group = everyone.id;
|
||||
override(realm, "realm_direct_message_permission_group", everyone.id);
|
||||
blueslip.expect("warn", "Unknown emails");
|
||||
compose_actions.on_narrow({
|
||||
force_close: false,
|
||||
|
|
|
@ -187,7 +187,7 @@ run_test("replace_syntax", ({override}) => {
|
|||
assert.equal(prev_caret + "$$\\pi$$".length - "Bca".length, $textbox.caret());
|
||||
});
|
||||
|
||||
run_test("compute_placeholder_text", () => {
|
||||
run_test("compute_placeholder_text", ({override}) => {
|
||||
let opts = {
|
||||
message_type: "stream",
|
||||
stream_id: undefined,
|
||||
|
@ -253,13 +253,13 @@ run_test("compute_placeholder_text", () => {
|
|||
);
|
||||
|
||||
alice.is_guest = true;
|
||||
realm.realm_enable_guest_user_indicator = true;
|
||||
override(realm, "realm_enable_guest_user_indicator", true);
|
||||
assert.equal(
|
||||
compose_ui.compute_placeholder_text(opts),
|
||||
$t({defaultMessage: "Message translated: Alice (guest) and Bob"}),
|
||||
);
|
||||
|
||||
realm.realm_enable_guest_user_indicator = false;
|
||||
override(realm, "realm_enable_guest_user_indicator", false);
|
||||
assert.equal(
|
||||
compose_ui.compute_placeholder_text(opts),
|
||||
$t({defaultMessage: "Message Alice and Bob"}),
|
||||
|
|
|
@ -136,7 +136,7 @@ test_ui("validate_stream_message_address_info", ({mock_template}) => {
|
|||
assert.ok(user_not_subscribed_rendered);
|
||||
});
|
||||
|
||||
test_ui("validate", ({mock_template}) => {
|
||||
test_ui("validate", ({mock_template, override}) => {
|
||||
function initialize_pm_pill() {
|
||||
$.clear_all_elements();
|
||||
|
||||
|
@ -172,8 +172,8 @@ test_ui("validate", ({mock_template}) => {
|
|||
add_content_to_compose_box();
|
||||
compose_state.private_message_recipient("");
|
||||
let pm_recipient_error_rendered = false;
|
||||
realm.realm_direct_message_permission_group = everyone.id;
|
||||
realm.realm_direct_message_initiator_group = everyone.id;
|
||||
override(realm, "realm_direct_message_permission_group", everyone.id);
|
||||
override(realm, "realm_direct_message_initiator_group", everyone.id);
|
||||
mock_template("compose_banner/compose_banner.hbs", false, (data) => {
|
||||
assert.equal(data.classname, compose_banner.CLASSNAMES.missing_private_message_recipient);
|
||||
assert.equal(
|
||||
|
@ -193,16 +193,16 @@ test_ui("validate", ({mock_template}) => {
|
|||
assert.ok(compose_validate.validate());
|
||||
assert.ok(!pm_recipient_error_rendered);
|
||||
|
||||
realm.realm_direct_message_initiator_group = admin.id;
|
||||
override(realm, "realm_direct_message_initiator_group", admin.id);
|
||||
assert.ok(compose_validate.validate());
|
||||
assert.ok(!pm_recipient_error_rendered);
|
||||
|
||||
realm.realm_direct_message_permission_group = admin.id;
|
||||
override(realm, "realm_direct_message_permission_group", admin.id);
|
||||
assert.ok(compose_validate.validate());
|
||||
assert.ok(!pm_recipient_error_rendered);
|
||||
|
||||
realm.realm_direct_message_initiator_group = everyone.id;
|
||||
realm.realm_direct_message_permission_group = everyone.id;
|
||||
override(realm, "realm_direct_message_initiator_group", everyone.id);
|
||||
override(realm, "realm_direct_message_permission_group", everyone.id);
|
||||
people.deactivate(bob);
|
||||
let deactivated_user_error_rendered = false;
|
||||
mock_template("compose_banner/compose_banner.hbs", false, (data) => {
|
||||
|
@ -217,9 +217,9 @@ test_ui("validate", ({mock_template}) => {
|
|||
assert.ok(!compose_validate.validate());
|
||||
assert.ok(deactivated_user_error_rendered);
|
||||
|
||||
realm.realm_is_zephyr_mirror_realm = true;
|
||||
override(realm, "realm_is_zephyr_mirror_realm", true);
|
||||
assert.ok(compose_validate.validate());
|
||||
realm.realm_is_zephyr_mirror_realm = false;
|
||||
override(realm, "realm_is_zephyr_mirror_realm", false);
|
||||
|
||||
initialize_pm_pill();
|
||||
add_content_to_compose_box();
|
||||
|
@ -284,7 +284,7 @@ test_ui("validate", ({mock_template}) => {
|
|||
};
|
||||
stream_data.add_sub(denmark);
|
||||
compose_state.set_stream_id(denmark.stream_id);
|
||||
realm.realm_mandatory_topics = true;
|
||||
override(realm, "realm_mandatory_topics", true);
|
||||
compose_state.topic("");
|
||||
let missing_topic_error_rendered = false;
|
||||
mock_template("compose_banner/compose_banner.hbs", false, (data) => {
|
||||
|
@ -374,7 +374,7 @@ test_ui("test_stream_wildcard_mention_allowed", ({override, override_rewire}) =>
|
|||
settings_config.wildcard_mention_policy_values.by_full_members.code;
|
||||
const person = people.get_by_user_id(current_user.user_id);
|
||||
person.date_joined = new Date(Date.now());
|
||||
realm.realm_waiting_period_threshold = 10;
|
||||
override(realm, "realm_waiting_period_threshold", 10);
|
||||
|
||||
assert.ok(compose_validate.stream_wildcard_mention_allowed());
|
||||
override(current_user, "is_admin", false);
|
||||
|
@ -397,7 +397,7 @@ test_ui("validate_stream_message", ({override, override_rewire, mock_template})
|
|||
// of execution should not be changed.
|
||||
mock_banners();
|
||||
override(current_user, "user_id", me.user_id);
|
||||
realm.realm_mandatory_topics = false;
|
||||
override(realm, "realm_mandatory_topics", false);
|
||||
|
||||
const special_sub = {
|
||||
stream_id: 101,
|
||||
|
@ -558,8 +558,8 @@ test_ui(
|
|||
},
|
||||
);
|
||||
|
||||
test_ui("test_check_overflow_text", ({mock_template}) => {
|
||||
realm.max_message_length = 10000;
|
||||
test_ui("test_check_overflow_text", ({mock_template, override}) => {
|
||||
override(realm, "max_message_length", 10000);
|
||||
|
||||
const $textarea = $("textarea#compose-textarea");
|
||||
const $indicator = $("#compose-limit-indicator");
|
||||
|
@ -724,7 +724,7 @@ test_ui("warn_if_mentioning_unsubscribed_user", ({override, mock_template}) => {
|
|||
new_banner_rendered = false;
|
||||
const msg_type = is_private ? "private" : "stream";
|
||||
compose_state.set_message_type(msg_type);
|
||||
realm.realm_is_zephyr_mirror_realm = is_zephyr_mirror;
|
||||
override(realm, "realm_is_zephyr_mirror_realm", is_zephyr_mirror);
|
||||
mentioned_details.type = type;
|
||||
compose_validate.warn_if_mentioning_unsubscribed_user(mentioned_details, $textarea);
|
||||
assert.ok(!new_banner_rendered);
|
||||
|
@ -736,7 +736,7 @@ test_ui("warn_if_mentioning_unsubscribed_user", ({override, mock_template}) => {
|
|||
|
||||
$("#compose_invite_users").hide();
|
||||
compose_state.set_message_type("stream");
|
||||
realm.realm_is_zephyr_mirror_realm = false;
|
||||
override(realm, "realm_is_zephyr_mirror_realm", false);
|
||||
|
||||
// Test with empty stream name in compose box. It should return noop.
|
||||
new_banner_rendered = false;
|
||||
|
|
|
@ -61,13 +61,17 @@ const realm_available_video_chat_providers = {
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
realm.realm_available_video_chat_providers = realm_available_video_chat_providers;
|
||||
helpers.override(
|
||||
realm,
|
||||
"realm_available_video_chat_providers",
|
||||
realm_available_video_chat_providers,
|
||||
);
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
||||
test("videos", ({override}) => {
|
||||
realm.realm_video_chat_provider = realm_available_video_chat_providers.disabled.id;
|
||||
override(realm, "realm_video_chat_provider", realm_available_video_chat_providers.disabled.id);
|
||||
|
||||
stub_out_video_calls();
|
||||
|
||||
|
@ -114,15 +118,19 @@ test("videos", ({override}) => {
|
|||
const handler = $("body").get_on_handler("click", ".video_link");
|
||||
$("textarea#compose-textarea").val("");
|
||||
|
||||
realm.realm_video_chat_provider = realm_available_video_chat_providers.jitsi_meet.id;
|
||||
override(
|
||||
realm,
|
||||
"realm_video_chat_provider",
|
||||
realm_available_video_chat_providers.jitsi_meet.id,
|
||||
);
|
||||
|
||||
realm.realm_jitsi_server_url = null;
|
||||
realm.server_jitsi_server_url = null;
|
||||
override(realm, "realm_jitsi_server_url", null);
|
||||
override(realm, "server_jitsi_server_url", null);
|
||||
handler(ev);
|
||||
assert.ok(!called);
|
||||
|
||||
realm.realm_jitsi_server_url = null;
|
||||
realm.server_jitsi_server_url = "https://server.example.com";
|
||||
override(realm, "realm_jitsi_server_url", null);
|
||||
override(realm, "server_jitsi_server_url", "https://server.example.com");
|
||||
handler(ev);
|
||||
// video link ids consist of 15 random digits
|
||||
let video_link_regex =
|
||||
|
@ -130,16 +138,16 @@ test("videos", ({override}) => {
|
|||
assert.ok(called);
|
||||
assert.match(syntax_to_insert, video_link_regex);
|
||||
|
||||
realm.realm_jitsi_server_url = "https://realm.example.com";
|
||||
realm.server_jitsi_server_url = null;
|
||||
override(realm, "realm_jitsi_server_url", "https://realm.example.com");
|
||||
override(realm, "server_jitsi_server_url", null);
|
||||
handler(ev);
|
||||
video_link_regex =
|
||||
/\[translated: Join video call\.]\(https:\/\/realm.example.com\/\d{15}#config.startWithVideoMuted=false\)/;
|
||||
assert.ok(called);
|
||||
assert.match(syntax_to_insert, video_link_regex);
|
||||
|
||||
realm.realm_jitsi_server_url = "https://realm.example.com";
|
||||
realm.server_jitsi_server_url = "https://server.example.com";
|
||||
override(realm, "realm_jitsi_server_url", "https://realm.example.com");
|
||||
override(realm, "server_jitsi_server_url", "https://server.example.com");
|
||||
handler(ev);
|
||||
video_link_regex =
|
||||
/\[translated: Join video call\.]\(https:\/\/realm.example.com\/\d{15}#config.startWithVideoMuted=false\)/;
|
||||
|
@ -167,7 +175,7 @@ test("videos", ({override}) => {
|
|||
called = true;
|
||||
});
|
||||
|
||||
realm.realm_video_chat_provider = realm_available_video_chat_providers.zoom.id;
|
||||
override(realm, "realm_video_chat_provider", realm_available_video_chat_providers.zoom.id);
|
||||
override(current_user, "has_zoom_token", false);
|
||||
|
||||
window.open = (url) => {
|
||||
|
@ -226,7 +234,11 @@ test("videos", ({override}) => {
|
|||
const handler = $("body").get_on_handler("click", ".video_link");
|
||||
$("textarea#compose-textarea").val("");
|
||||
|
||||
realm.realm_video_chat_provider = realm_available_video_chat_providers.big_blue_button.id;
|
||||
override(
|
||||
realm,
|
||||
"realm_video_chat_provider",
|
||||
realm_available_video_chat_providers.big_blue_button.id,
|
||||
);
|
||||
|
||||
override(compose_closed_ui, "get_recipient_label", () => "a");
|
||||
|
||||
|
@ -248,22 +260,30 @@ test("videos", ({override}) => {
|
|||
})();
|
||||
});
|
||||
|
||||
test("test_video_chat_button_toggle disabled", () => {
|
||||
realm.realm_video_chat_provider = realm_available_video_chat_providers.disabled.id;
|
||||
test("test_video_chat_button_toggle disabled", ({override}) => {
|
||||
override(realm, "realm_video_chat_provider", realm_available_video_chat_providers.disabled.id);
|
||||
compose_setup.initialize();
|
||||
assert.equal($(".compose-control-buttons-container .video_link").visible(), false);
|
||||
});
|
||||
|
||||
test("test_video_chat_button_toggle no url", () => {
|
||||
realm.realm_video_chat_provider = realm_available_video_chat_providers.jitsi_meet.id;
|
||||
test("test_video_chat_button_toggle no url", ({override}) => {
|
||||
override(
|
||||
realm,
|
||||
"realm_video_chat_provider",
|
||||
realm_available_video_chat_providers.jitsi_meet.id,
|
||||
);
|
||||
page_params.jitsi_server_url = null;
|
||||
compose_setup.initialize();
|
||||
assert.equal($(".compose-control-buttons-container .video_link").visible(), false);
|
||||
});
|
||||
|
||||
test("test_video_chat_button_toggle enabled", () => {
|
||||
realm.realm_video_chat_provider = realm_available_video_chat_providers.jitsi_meet.id;
|
||||
realm.realm_jitsi_server_url = "https://meet.jit.si";
|
||||
test("test_video_chat_button_toggle enabled", ({override}) => {
|
||||
override(
|
||||
realm,
|
||||
"realm_video_chat_provider",
|
||||
realm_available_video_chat_providers.jitsi_meet.id,
|
||||
);
|
||||
override(realm, "realm_jitsi_server_url", "https://meet.jit.si");
|
||||
compose_setup.initialize();
|
||||
assert.equal($(".compose-control-buttons-container .video_link").visible(), true);
|
||||
});
|
||||
|
|
|
@ -127,7 +127,6 @@ message_lists.all_rendered_message_lists = () => [cached_message_list, message_l
|
|||
|
||||
// page_params is highly coupled to dispatching now
|
||||
page_params.test_suite = false;
|
||||
realm.realm_description = "already set description";
|
||||
|
||||
// For data-oriented modules, just use them, don't stub them.
|
||||
const alert_words = zrequire("alert_words");
|
||||
|
@ -453,7 +452,7 @@ run_test("scheduled_messages", ({override}) => {
|
|||
|
||||
run_test("realm settings", ({override}) => {
|
||||
override(current_user, "is_admin", true);
|
||||
realm.realm_date_created = new Date("2023-01-01Z");
|
||||
override(realm, "realm_date_created", new Date("2023-01-01Z"));
|
||||
|
||||
override(settings_org, "check_disable_direct_message_initiator_group_dropdown", noop);
|
||||
override(settings_org, "sync_realm_settings", noop);
|
||||
|
@ -540,17 +539,17 @@ run_test("realm settings", ({override}) => {
|
|||
event = event_fixtures.realm__update__new_stream_announcements_stream_id;
|
||||
dispatch(event);
|
||||
assert_same(realm.realm_new_stream_announcements_stream_id, 42);
|
||||
realm.realm_new_stream_announcements_stream_id = -1; // make sure to reset for future tests
|
||||
override(realm, "realm_new_stream_announcements_stream_id", -1); // make sure to reset for future tests
|
||||
|
||||
event = event_fixtures.realm__update__signup_announcements_stream_id;
|
||||
dispatch(event);
|
||||
assert_same(realm.realm_signup_announcements_stream_id, 41);
|
||||
realm.realm_signup_announcements_stream_id = -1; // make sure to reset for future tests
|
||||
override(realm, "realm_signup_announcements_stream_id", -1); // make sure to reset for future tests
|
||||
|
||||
event = event_fixtures.realm__update__zulip_update_announcements_stream_id;
|
||||
dispatch(event);
|
||||
assert_same(realm.realm_zulip_update_announcements_stream_id, 42);
|
||||
realm.realm_zulip_update_announcements_stream_id = -1; // make sure to reset for future tests
|
||||
override(realm, "realm_zulip_update_announcements_stream_id", -1); // make sure to reset for future tests
|
||||
|
||||
event = event_fixtures.realm__update__default_code_block_language;
|
||||
dispatch(event);
|
||||
|
@ -573,13 +572,13 @@ run_test("realm settings", ({override}) => {
|
|||
};
|
||||
|
||||
event = event_fixtures.realm__update_dict__default;
|
||||
realm.realm_create_multiuse_invite_group = 1;
|
||||
realm.realm_allow_message_editing = false;
|
||||
realm.realm_message_content_edit_limit_seconds = 0;
|
||||
realm.realm_edit_topic_policy = 3;
|
||||
realm.realm_authentication_methods = {Google: {enabled: false, available: true}};
|
||||
realm.realm_can_create_public_channel_group = 1;
|
||||
realm.realm_direct_message_permission_group = 1;
|
||||
override(realm, "realm_create_multiuse_invite_group", 1);
|
||||
override(realm, "realm_allow_message_editing", false);
|
||||
override(realm, "realm_message_content_edit_limit_seconds", 0);
|
||||
override(realm, "realm_edit_topic_policy", 3);
|
||||
override(realm, "realm_authentication_methods", {Google: {enabled: false, available: true}});
|
||||
override(realm, "realm_can_create_public_channel_group", 1);
|
||||
override(realm, "realm_direct_message_permission_group", 1);
|
||||
override(settings_org, "populate_auth_methods", noop);
|
||||
dispatch(event);
|
||||
assert_same(realm.realm_create_multiuse_invite_group, 3);
|
||||
|
@ -694,7 +693,7 @@ run_test("realm_emoji", ({override}) => {
|
|||
|
||||
run_test("realm_linkifiers", ({override}) => {
|
||||
const event = event_fixtures.realm_linkifiers;
|
||||
realm.realm_linkifiers = [];
|
||||
override(realm, "realm_linkifiers", []);
|
||||
override(settings_linkifiers, "populate_linkifiers", noop);
|
||||
override(linkifiers, "update_linkifier_rules", noop);
|
||||
dispatch(event);
|
||||
|
@ -703,7 +702,7 @@ run_test("realm_linkifiers", ({override}) => {
|
|||
|
||||
run_test("realm_playgrounds", ({override}) => {
|
||||
const event = event_fixtures.realm_playgrounds;
|
||||
realm.realm_playgrounds = [];
|
||||
override(realm, "realm_playgrounds", []);
|
||||
override(settings_playgrounds, "populate_playgrounds", noop);
|
||||
override(realm_playground, "update_playgrounds", noop);
|
||||
dispatch(event);
|
||||
|
@ -712,7 +711,7 @@ run_test("realm_playgrounds", ({override}) => {
|
|||
|
||||
run_test("realm_domains", ({override}) => {
|
||||
let event = event_fixtures.realm_domains__add;
|
||||
realm.realm_domains = [];
|
||||
override(realm, "realm_domains", []);
|
||||
override(settings_org, "populate_realm_domains_label", noop);
|
||||
override(settings_realm_domains, "populate_realm_domains_table", noop);
|
||||
dispatch(event);
|
||||
|
|
|
@ -241,9 +241,9 @@ test("stream delete (special streams)", ({override}) => {
|
|||
|
||||
// sanity check data
|
||||
assert.equal(event.streams.length, 2);
|
||||
realm.realm_new_stream_announcements_stream_id = event.streams[0].stream_id;
|
||||
realm.realm_signup_announcements_stream_id = event.streams[1].stream_id;
|
||||
realm.realm_zulip_update_announcements_stream_id = event.streams[0].stream_id;
|
||||
override(realm, "realm_new_stream_announcements_stream_id", event.streams[0].stream_id);
|
||||
override(realm, "realm_signup_announcements_stream_id", event.streams[1].stream_id);
|
||||
override(realm, "realm_zulip_update_announcements_stream_id", event.streams[0].stream_id);
|
||||
|
||||
override(stream_settings_ui, "remove_stream", noop);
|
||||
override(settings_org, "sync_realm_settings", noop);
|
||||
|
|
|
@ -5,7 +5,6 @@ const assert = require("node:assert/strict");
|
|||
const {make_stream} = require("./lib/example_stream");
|
||||
const {zrequire} = require("./lib/namespace");
|
||||
const {run_test} = require("./lib/test");
|
||||
const {realm} = require("./lib/zpage_params");
|
||||
|
||||
// In the Zulip app you can narrow your message stream by topic, by
|
||||
// sender, by direct message recipient, by search keywords, etc.
|
||||
|
@ -15,13 +14,6 @@ const {realm} = require("./lib/zpage_params");
|
|||
const {Filter} = zrequire("../src/filter");
|
||||
const stream_data = zrequire("stream_data");
|
||||
|
||||
// This is the first time we have to deal with `realm`.
|
||||
// `realm` has a lot of important data shared by various
|
||||
// modules. Most of the data is irrelevant to our tests.
|
||||
// Use this to explicitly say we are not a special Zephyr
|
||||
// realm, since we want to test the "normal" codepath.
|
||||
realm.realm_is_zephyr_mirror_realm = false;
|
||||
|
||||
const denmark_stream = make_stream({
|
||||
color: "blue",
|
||||
name: "Denmark",
|
||||
|
|
|
@ -2020,7 +2020,7 @@ function make_web_public_sub(name, stream_id) {
|
|||
stream_data.add_sub(sub);
|
||||
}
|
||||
|
||||
test("navbar_helpers", () => {
|
||||
test("navbar_helpers", ({override}) => {
|
||||
stream_data.add_sub(foo_sub);
|
||||
|
||||
// make sure title has names separated with correct delimiters
|
||||
|
@ -2355,7 +2355,7 @@ test("navbar_helpers", () => {
|
|||
},
|
||||
];
|
||||
|
||||
realm.realm_enable_guest_user_indicator = true;
|
||||
override(realm, "realm_enable_guest_user_indicator", true);
|
||||
|
||||
for (const test_case of test_cases) {
|
||||
test_helpers(test_case);
|
||||
|
@ -2410,7 +2410,7 @@ test("navbar_helpers", () => {
|
|||
|
||||
test_get_title(channel_topic_search_term_test_case);
|
||||
|
||||
realm.realm_enable_guest_user_indicator = false;
|
||||
override(realm, "realm_enable_guest_user_indicator", false);
|
||||
const guest_user_test_cases_without_indicator = [
|
||||
{
|
||||
terms: guest_sender,
|
||||
|
|
|
@ -8,60 +8,60 @@ const {realm} = require("./lib/zpage_params");
|
|||
|
||||
const gear_menu_util = zrequire("gear_menu_util");
|
||||
|
||||
run_test("version_display_string", () => {
|
||||
run_test("version_display_string", ({override}) => {
|
||||
let expected_version_display_string;
|
||||
|
||||
// An official release
|
||||
realm.zulip_version = "5.6";
|
||||
realm.zulip_merge_base = "5.6";
|
||||
override(realm, "zulip_version", "5.6");
|
||||
override(realm, "zulip_merge_base", "5.6");
|
||||
expected_version_display_string = "translated: Zulip Server 5.6";
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// An official beta
|
||||
realm.zulip_version = "6.0-beta1";
|
||||
realm.zulip_merge_base = "6.0-beta1";
|
||||
override(realm, "zulip_version", "6.0-beta1");
|
||||
override(realm, "zulip_merge_base", "6.0-beta1");
|
||||
expected_version_display_string = "translated: Zulip Server 6.0-beta1";
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// An official release candidate
|
||||
realm.zulip_version = "6.0-rc1";
|
||||
realm.zulip_merge_base = "6.0-rc1";
|
||||
override(realm, "zulip_version", "6.0-rc1");
|
||||
override(realm, "zulip_merge_base", "6.0-rc1");
|
||||
expected_version_display_string = "translated: Zulip Server 6.0-rc1";
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// The Zulip development environment
|
||||
realm.zulip_version = "6.0-dev+git";
|
||||
realm.zulip_merge_base = "6.0-dev+git";
|
||||
override(realm, "zulip_version", "6.0-dev+git");
|
||||
override(realm, "zulip_merge_base", "6.0-dev+git");
|
||||
expected_version_display_string = "translated: Zulip Server dev environment";
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A commit on Zulip's main branch.
|
||||
realm.zulip_version = "6.0-dev-1976-g4bb381fc80";
|
||||
realm.zulip_merge_base = "6.0-dev-1976-g4bb381fc80";
|
||||
override(realm, "zulip_version", "6.0-dev-1976-g4bb381fc80");
|
||||
override(realm, "zulip_merge_base", "6.0-dev-1976-g4bb381fc80");
|
||||
expected_version_display_string = "translated: Zulip Server 6.0-dev";
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A fork with 18 commits beyond Zulip's main branch.
|
||||
realm.zulip_version = "6.0-dev-1994-g93730766b0";
|
||||
realm.zulip_merge_base = "6.0-dev-1976-g4bb381fc80";
|
||||
override(realm, "zulip_version", "6.0-dev-1994-g93730766b0");
|
||||
override(realm, "zulip_merge_base", "6.0-dev-1976-g4bb381fc80");
|
||||
expected_version_display_string = "translated: Zulip Server 6.0-dev (modified)";
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A commit from the Zulip 5.x branch
|
||||
realm.zulip_version = "5.6+git-4-g385a408be5";
|
||||
realm.zulip_merge_base = "5.6+git-4-g385a408be5";
|
||||
override(realm, "zulip_version", "5.6+git-4-g385a408be5");
|
||||
override(realm, "zulip_merge_base", "5.6+git-4-g385a408be5");
|
||||
expected_version_display_string = "translated: Zulip Server 5.6 (patched)";
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A fork with 3 commits beyond the Zulip 5.x branch.
|
||||
realm.zulip_version = "5.6+git-4-g385a408be5";
|
||||
realm.zulip_merge_base = "5.6+git-7-abcda4235c2";
|
||||
override(realm, "zulip_version", "5.6+git-4-g385a408be5");
|
||||
override(realm, "zulip_merge_base", "5.6+git-7-abcda4235c2");
|
||||
expected_version_display_string = "translated: Zulip Server 5.6 (modified)";
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A fork of a Zulip release commit, not on 5.x branch.
|
||||
realm.zulip_version = "5.3-1-g7ed896c0db";
|
||||
realm.zulip_merge_base = "5.3";
|
||||
override(realm, "zulip_version", "5.3-1-g7ed896c0db");
|
||||
override(realm, "zulip_merge_base", "5.3");
|
||||
expected_version_display_string = "translated: Zulip Server 5.3 (modified)";
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
});
|
||||
|
|
|
@ -6,8 +6,6 @@ const {mock_esm, zrequire} = require("./lib/namespace");
|
|||
const {run_test} = require("./lib/test");
|
||||
const {current_user, realm} = require("./lib/zpage_params");
|
||||
|
||||
realm.realm_move_messages_within_stream_limit_seconds = 259200;
|
||||
|
||||
const message_edit = zrequire("message_edit");
|
||||
const people = zrequire("people");
|
||||
|
||||
|
@ -15,7 +13,7 @@ const is_content_editable = message_edit.is_content_editable;
|
|||
|
||||
const settings_data = mock_esm("../src/settings_data");
|
||||
|
||||
run_test("is_content_editable", () => {
|
||||
run_test("is_content_editable", ({override}) => {
|
||||
// You can't edit a null message
|
||||
assert.equal(is_content_editable(null), false);
|
||||
// You can't edit a message you didn't send
|
||||
|
@ -52,15 +50,15 @@ run_test("is_content_editable", () => {
|
|||
sent_by_me: true,
|
||||
};
|
||||
|
||||
realm.realm_allow_message_editing = false;
|
||||
override(realm, "realm_allow_message_editing", false);
|
||||
assert.equal(is_content_editable(message), false);
|
||||
|
||||
realm.realm_allow_message_editing = true;
|
||||
override(realm, "realm_allow_message_editing", true);
|
||||
// Limit of 0 means no time limit on editing messages
|
||||
realm.realm_message_content_edit_limit_seconds = null;
|
||||
override(realm, "realm_message_content_edit_limit_seconds", null);
|
||||
assert.equal(is_content_editable(message), true);
|
||||
|
||||
realm.realm_message_content_edit_limit_seconds = 10;
|
||||
override(realm, "realm_message_content_edit_limit_seconds", 10);
|
||||
const now = new Date();
|
||||
const current_timestamp = now / 1000;
|
||||
message.timestamp = current_timestamp - 60;
|
||||
|
@ -90,7 +88,7 @@ run_test("is_topic_editable", ({override}) => {
|
|||
locally_echoed: true,
|
||||
type: "stream",
|
||||
};
|
||||
realm.realm_allow_message_editing = true;
|
||||
override(realm, "realm_allow_message_editing", true);
|
||||
override(settings_data, "user_can_move_messages_to_another_topic", () => true);
|
||||
override(current_user, "is_admin", true);
|
||||
|
||||
|
@ -119,7 +117,7 @@ run_test("is_topic_editable", ({override}) => {
|
|||
override(settings_data, "user_can_move_messages_to_another_topic", () => false);
|
||||
assert.equal(message_edit.is_topic_editable(message), false);
|
||||
|
||||
realm.realm_move_messages_within_stream_limit_seconds = 259200;
|
||||
override(realm, "realm_move_messages_within_stream_limit_seconds", 259200);
|
||||
message.timestamp = current_timestamp - 60;
|
||||
|
||||
override(settings_data, "user_can_move_messages_to_another_topic", () => true);
|
||||
|
@ -131,7 +129,7 @@ run_test("is_topic_editable", ({override}) => {
|
|||
override(current_user, "is_moderator", true);
|
||||
assert.equal(message_edit.is_topic_editable(message), true);
|
||||
|
||||
realm.realm_allow_message_editing = false;
|
||||
override(realm, "realm_allow_message_editing", false);
|
||||
assert.equal(message_edit.is_topic_editable(message), true);
|
||||
});
|
||||
|
||||
|
@ -144,7 +142,7 @@ run_test("is_stream_editable", ({override}) => {
|
|||
locally_echoed: true,
|
||||
type: "stream",
|
||||
};
|
||||
realm.realm_allow_message_editing = true;
|
||||
override(realm, "realm_allow_message_editing", true);
|
||||
override(settings_data, "user_can_move_messages_between_streams", () => true);
|
||||
override(current_user, "is_admin", true);
|
||||
|
||||
|
@ -166,7 +164,7 @@ run_test("is_stream_editable", ({override}) => {
|
|||
override(current_user, "is_admin", false);
|
||||
assert.equal(message_edit.is_stream_editable(message), false);
|
||||
|
||||
realm.realm_move_messages_between_streams_limit_seconds = 259200;
|
||||
override(realm, "realm_move_messages_between_streams_limit_seconds", 259200);
|
||||
message.timestamp = current_timestamp - 60;
|
||||
|
||||
override(settings_data, "user_can_move_messages_between_streams", () => true);
|
||||
|
@ -183,7 +181,7 @@ run_test("get_deletability", ({override}) => {
|
|||
override(current_user, "is_admin", true);
|
||||
override(settings_data, "user_can_delete_any_message", () => true);
|
||||
override(settings_data, "user_can_delete_own_message", () => false);
|
||||
realm.realm_message_content_delete_limit_seconds = null;
|
||||
override(realm, "realm_message_content_delete_limit_seconds", null);
|
||||
const test_user = {
|
||||
user_id: 1,
|
||||
full_name: "Test user",
|
||||
|
@ -231,7 +229,7 @@ run_test("get_deletability", ({override}) => {
|
|||
let current_timestamp = now / 1000;
|
||||
message.timestamp = current_timestamp - 5;
|
||||
|
||||
realm.realm_message_content_delete_limit_seconds = 10;
|
||||
override(realm, "realm_message_content_delete_limit_seconds", 10);
|
||||
assert.equal(message_edit.get_deletability(message), true);
|
||||
|
||||
message.timestamp = current_timestamp - 60;
|
||||
|
@ -240,7 +238,7 @@ run_test("get_deletability", ({override}) => {
|
|||
message.sender_id = 2;
|
||||
message.sent_by_me = false;
|
||||
people.initialize_current_user(test_user.user_id);
|
||||
realm.realm_message_content_delete_limit_seconds = null;
|
||||
override(realm, "realm_message_content_delete_limit_seconds", null);
|
||||
|
||||
override(settings_data, "user_can_delete_own_message", () => true);
|
||||
assert.equal(message_edit.get_deletability(message), true);
|
||||
|
@ -250,7 +248,7 @@ run_test("get_deletability", ({override}) => {
|
|||
|
||||
now = new Date();
|
||||
current_timestamp = now / 1000;
|
||||
realm.realm_message_content_delete_limit_seconds = 10;
|
||||
override(realm, "realm_message_content_delete_limit_seconds", 10);
|
||||
message.timestamp = current_timestamp - 60;
|
||||
override(settings_data, "user_can_delete_own_message", () => true);
|
||||
assert.equal(message_edit.get_deletability(message), false);
|
||||
|
|
|
@ -65,7 +65,7 @@ function test_helper(side_effects) {
|
|||
return self;
|
||||
}
|
||||
|
||||
run_test("update_messages", () => {
|
||||
run_test("update_messages", ({override}) => {
|
||||
const raw_message = {
|
||||
id: 111,
|
||||
display_recipient: denmark.name,
|
||||
|
@ -115,7 +115,7 @@ run_test("update_messages", () => {
|
|||
|
||||
const helper = test_helper(side_effects);
|
||||
|
||||
realm.realm_allow_edit_history = false;
|
||||
override(realm, "realm_allow_edit_history", false);
|
||||
|
||||
const $message_edit_history_modal = $.create("#message-edit-history");
|
||||
const $modal = $.create("micromodal").addClass("modal--open");
|
||||
|
|
|
@ -5,7 +5,6 @@ const assert = require("node:assert/strict");
|
|||
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
||||
const {run_test, noop} = require("./lib/test");
|
||||
const blueslip = require("./lib/zblueslip");
|
||||
const {realm} = require("./lib/zpage_params");
|
||||
|
||||
mock_esm("../src/settings_data", {
|
||||
user_can_access_all_other_users: () => true,
|
||||
|
@ -21,7 +20,6 @@ mock_esm("../src/recent_senders", {
|
|||
});
|
||||
|
||||
set_global("document", "document-stub");
|
||||
realm.realm_allow_message_editing = true;
|
||||
|
||||
const util = zrequire("util");
|
||||
const people = zrequire("people");
|
||||
|
|
|
@ -229,8 +229,8 @@ run_test("urls", () => {
|
|||
assert.equal(emails, "me@example.com");
|
||||
});
|
||||
|
||||
run_test("show_empty_narrow_message", ({mock_template}) => {
|
||||
realm.stop_words = [];
|
||||
run_test("show_empty_narrow_message", ({mock_template, override}) => {
|
||||
override(realm, "stop_words", []);
|
||||
|
||||
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
|
||||
|
||||
|
@ -324,8 +324,8 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
|||
),
|
||||
);
|
||||
|
||||
realm.realm_direct_message_permission_group = everyone.id;
|
||||
realm.realm_direct_message_initiator_group = everyone.id;
|
||||
override(realm, "realm_direct_message_permission_group", everyone.id);
|
||||
override(realm, "realm_direct_message_initiator_group", everyone.id);
|
||||
set_filter([["is", "dm"]]);
|
||||
narrow_banner.show_empty_narrow_message();
|
||||
assert.equal(
|
||||
|
@ -358,7 +358,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
|||
);
|
||||
|
||||
// organization has disabled sending direct messages
|
||||
realm.realm_direct_message_permission_group = nobody.id;
|
||||
override(realm, "realm_direct_message_permission_group", nobody.id);
|
||||
|
||||
// prioritize information about invalid user(s) in narrow/search
|
||||
set_filter([["dm", ["Yo"]]]);
|
||||
|
@ -412,7 +412,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
|||
);
|
||||
|
||||
// sending direct messages enabled
|
||||
realm.realm_direct_message_permission_group = everyone.id;
|
||||
override(realm, "realm_direct_message_permission_group", everyone.id);
|
||||
set_filter([["dm", "alice@example.com"]]);
|
||||
narrow_banner.show_empty_narrow_message();
|
||||
assert.equal(
|
||||
|
@ -424,7 +424,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
|||
);
|
||||
|
||||
// sending direct messages to deactivated user
|
||||
realm.realm_direct_message_permission_group = everyone.id;
|
||||
override(realm, "realm_direct_message_permission_group", everyone.id);
|
||||
people.deactivate(alice);
|
||||
set_filter([["dm", alice.email]]);
|
||||
narrow_banner.show_empty_narrow_message();
|
||||
|
@ -467,7 +467,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
|||
people.add_active_user(alice);
|
||||
|
||||
// organization has disabled sending direct messages
|
||||
realm.realm_direct_message_permission_group = nobody.id;
|
||||
override(realm, "realm_direct_message_permission_group", nobody.id);
|
||||
|
||||
// prioritize information about invalid user in narrow/search
|
||||
set_filter([["dm-including", ["Yo"]]]);
|
||||
|
@ -497,8 +497,8 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
|||
);
|
||||
|
||||
// sending direct messages enabled
|
||||
realm.realm_direct_message_permission_group = everyone.id;
|
||||
realm.realm_direct_message_permission_group = everyone.id;
|
||||
override(realm, "realm_direct_message_permission_group", everyone.id);
|
||||
override(realm, "realm_direct_message_permission_group", everyone.id);
|
||||
set_filter([["dm-including", "alice@example.com"]]);
|
||||
narrow_banner.show_empty_narrow_message();
|
||||
assert.equal(
|
||||
|
@ -586,8 +586,8 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
|||
);
|
||||
});
|
||||
|
||||
run_test("show_empty_narrow_message_with_search", ({mock_template}) => {
|
||||
realm.stop_words = [];
|
||||
run_test("show_empty_narrow_message_with_search", ({mock_template, override}) => {
|
||||
override(realm, "stop_words", []);
|
||||
|
||||
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
|
||||
|
||||
|
@ -602,8 +602,8 @@ run_test("hide_empty_narrow_message", () => {
|
|||
assert.equal($(".empty_feed_notice").text(), "never-been-set");
|
||||
});
|
||||
|
||||
run_test("show_search_stopwords", ({mock_template}) => {
|
||||
realm.stop_words = ["what", "about"];
|
||||
run_test("show_search_stopwords", ({mock_template, override}) => {
|
||||
override(realm, "stop_words", ["what", "about"]);
|
||||
|
||||
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ test("profile_incomplete_alert", ({override}) => {
|
|||
|
||||
// Show alert.
|
||||
override(current_user, "is_admin", true);
|
||||
realm.realm_description = "Organization imported from Slack!";
|
||||
override(realm, "realm_description", "Organization imported from Slack!");
|
||||
assert.equal(navbar_alerts.check_profile_incomplete(), true);
|
||||
|
||||
// Avoid showing if the user is not admin.
|
||||
|
@ -79,7 +79,7 @@ test("profile_incomplete_alert", ({override}) => {
|
|||
// Avoid showing if the realm description is already updated.
|
||||
override(current_user, "is_admin", true);
|
||||
assert.equal(navbar_alerts.check_profile_incomplete(), true);
|
||||
realm.realm_description = "Organization description already set!";
|
||||
override(realm, "realm_description", "Organization description already set!");
|
||||
assert.equal(navbar_alerts.check_profile_incomplete(), false);
|
||||
});
|
||||
|
||||
|
@ -103,12 +103,20 @@ test("demo_organization_days_remaining", ({override}) => {
|
|||
const start_time = new Date(1620327447050); // Thursday 06/5/2021 07:02:27 AM (UTC+0)
|
||||
|
||||
const high_priority_deadline = addDays(start_time, 5);
|
||||
realm.demo_organization_scheduled_deletion_date = Math.trunc(high_priority_deadline / 1000);
|
||||
override(
|
||||
realm,
|
||||
"demo_organization_scheduled_deletion_date",
|
||||
Math.trunc(high_priority_deadline / 1000),
|
||||
);
|
||||
override(Date, "now", () => start_time);
|
||||
assert.equal(navbar_alerts.get_demo_organization_deadline_days_remaining(), 5);
|
||||
|
||||
const low_priority_deadline = addDays(start_time, 10);
|
||||
realm.demo_organization_scheduled_deletion_date = Math.trunc(low_priority_deadline / 1000);
|
||||
override(
|
||||
realm,
|
||||
"demo_organization_scheduled_deletion_date",
|
||||
Math.trunc(low_priority_deadline / 1000),
|
||||
);
|
||||
override(Date, "now", () => start_time);
|
||||
assert.equal(navbar_alerts.get_demo_organization_deadline_days_remaining(), 10);
|
||||
});
|
||||
|
|
|
@ -511,7 +511,7 @@ test_people("get_display_full_names", ({override}) => {
|
|||
people.add_active_user(bob);
|
||||
people.add_active_user(charles);
|
||||
people.add_active_user(guest);
|
||||
realm.realm_enable_guest_user_indicator = true;
|
||||
override(realm, "realm_enable_guest_user_indicator", true);
|
||||
|
||||
let user_ids = [me.user_id, steven.user_id, bob.user_id, charles.user_id, guest.user_id];
|
||||
let names = people.get_display_full_names(user_ids);
|
||||
|
@ -527,7 +527,7 @@ test_people("get_display_full_names", ({override}) => {
|
|||
]);
|
||||
|
||||
muted_users.add_muted_user(charles.user_id);
|
||||
realm.realm_enable_guest_user_indicator = false;
|
||||
override(realm, "realm_enable_guest_user_indicator", false);
|
||||
names = people.get_display_full_names(user_ids);
|
||||
assert.deepEqual(names, [
|
||||
"Me Myself",
|
||||
|
@ -547,7 +547,7 @@ test_people("get_display_full_names", ({override}) => {
|
|||
"translated: Muted user",
|
||||
]);
|
||||
|
||||
realm.realm_enable_guest_user_indicator = true;
|
||||
override(realm, "realm_enable_guest_user_indicator", true);
|
||||
names = people.get_display_full_names(user_ids);
|
||||
assert.deepEqual(names, [
|
||||
"Me Myself",
|
||||
|
@ -1428,15 +1428,15 @@ test_people("get_realm_active_human_users", () => {
|
|||
assert.deepEqual(humans, [me]);
|
||||
});
|
||||
|
||||
test_people("should_show_guest_user_indicator", () => {
|
||||
test_people("should_show_guest_user_indicator", ({override}) => {
|
||||
people.add_active_user(charles);
|
||||
people.add_active_user(guest);
|
||||
|
||||
realm.realm_enable_guest_user_indicator = false;
|
||||
override(realm, "realm_enable_guest_user_indicator", false);
|
||||
assert.equal(people.should_add_guest_user_indicator(charles.user_id), false);
|
||||
assert.equal(people.should_add_guest_user_indicator(guest.user_id), false);
|
||||
|
||||
realm.realm_enable_guest_user_indicator = true;
|
||||
override(realm, "realm_enable_guest_user_indicator", true);
|
||||
assert.equal(people.should_add_guest_user_indicator(charles.user_id), false);
|
||||
assert.equal(people.should_add_guest_user_indicator(guest.user_id), true);
|
||||
});
|
||||
|
@ -1444,7 +1444,7 @@ test_people("should_show_guest_user_indicator", () => {
|
|||
test_people("get_user_by_id_assert_valid", ({override}) => {
|
||||
people.add_active_user(charles);
|
||||
const inaccessible_user_id = 99;
|
||||
realm.realm_bot_domain = "zulipdev.com";
|
||||
override(realm, "realm_bot_domain", "zulipdev.com");
|
||||
override(settings_data, "user_can_access_all_other_users", () => false);
|
||||
|
||||
let user = people.get_user_by_id_assert_valid(inaccessible_user_id);
|
||||
|
@ -1476,14 +1476,14 @@ test_people("get_user_by_id_assert_valid", ({override}) => {
|
|||
assert.equal(user.email, charles.email);
|
||||
});
|
||||
|
||||
test_people("user_can_initiate_direct_message_thread", () => {
|
||||
test_people("user_can_initiate_direct_message_thread", ({override}) => {
|
||||
people.add_active_user(welcome_bot);
|
||||
realm.realm_direct_message_initiator_group = nobody.id;
|
||||
override(realm, "realm_direct_message_initiator_group", nobody.id);
|
||||
assert.ok(!people.user_can_initiate_direct_message_thread("32"));
|
||||
// Can send if only bots and self are present.
|
||||
assert.ok(people.user_can_initiate_direct_message_thread("4,30"));
|
||||
|
||||
realm.realm_direct_message_initiator_group = everyone.id;
|
||||
override(realm, "realm_direct_message_initiator_group", everyone.id);
|
||||
assert.ok(people.user_can_initiate_direct_message_thread("32"));
|
||||
});
|
||||
|
||||
|
|
|
@ -614,7 +614,7 @@ run_test("set_up_group_setting_typeahead", ({mock_template, override, override_r
|
|||
const system_group_items = [moderators_item];
|
||||
|
||||
page_params.development_environment = true;
|
||||
realm.realm_waiting_period_threshold = 0;
|
||||
override(realm, "realm_waiting_period_threshold", 0);
|
||||
|
||||
override(bootstrap_typeahead, "Typeahead", (input_element, config) => {
|
||||
assert.equal(input_element.$element, $fake_input);
|
||||
|
|
|
@ -128,15 +128,15 @@ function add_message_with_view(list, messages) {
|
|||
|
||||
// Function sets page parameters with no time constraints on editing the message.
|
||||
// User is assumed to not be an admin.
|
||||
function set_page_params_no_edit_restrictions() {
|
||||
function set_page_params_no_edit_restrictions({override}) {
|
||||
page_params.is_spectator = false;
|
||||
realm.realm_allow_message_editing = true;
|
||||
realm.realm_message_content_edit_limit_seconds = null;
|
||||
realm.realm_allow_edit_history = true;
|
||||
realm.realm_message_content_delete_limit_seconds = null;
|
||||
realm.realm_enable_read_receipts = true;
|
||||
realm.realm_edit_topic_policy = 5;
|
||||
realm.realm_move_messages_within_stream_limit_seconds = null;
|
||||
override(realm, "realm_allow_message_editing", true);
|
||||
override(realm, "realm_message_content_edit_limit_seconds", null);
|
||||
override(realm, "realm_allow_edit_history", true);
|
||||
override(realm, "realm_message_content_delete_limit_seconds", null);
|
||||
override(realm, "realm_enable_read_receipts", true);
|
||||
override(realm, "realm_edit_topic_policy", 5);
|
||||
override(realm, "realm_move_messages_within_stream_limit_seconds", null);
|
||||
}
|
||||
|
||||
// Test init function
|
||||
|
@ -158,9 +158,9 @@ function test(label, f) {
|
|||
// Test functions
|
||||
test("my_message_all_actions", ({override}) => {
|
||||
// Set page parameters.
|
||||
set_page_params_no_edit_restrictions();
|
||||
realm.realm_can_delete_any_message_group = everyone.id;
|
||||
realm.realm_can_delete_own_message_group = everyone.id;
|
||||
set_page_params_no_edit_restrictions({override});
|
||||
override(realm, "realm_can_delete_any_message_group", everyone.id);
|
||||
override(realm, "realm_can_delete_own_message_group", everyone.id);
|
||||
override(current_user, "user_id", me.user_id);
|
||||
// Get message with maximum permissions available
|
||||
// Initialize message list
|
||||
|
@ -210,10 +210,10 @@ test("my_message_all_actions", ({override}) => {
|
|||
assert.equal(response.should_display_quote_and_reply, true);
|
||||
});
|
||||
|
||||
test("not_my_message_view_actions", () => {
|
||||
set_page_params_no_edit_restrictions();
|
||||
test("not_my_message_view_actions", ({override}) => {
|
||||
set_page_params_no_edit_restrictions({override});
|
||||
// Get message that is only viewable
|
||||
realm.realm_can_delete_any_message_group = everyone.id;
|
||||
override(realm, "realm_can_delete_any_message_group", everyone.id);
|
||||
const list = init_message_list();
|
||||
message_lists.set_current(list);
|
||||
|
||||
|
@ -249,9 +249,9 @@ test("not_my_message_view_actions", () => {
|
|||
assert.equal(response.move_message_menu_item, undefined);
|
||||
});
|
||||
|
||||
test("not_my_message_view_source_and_move", () => {
|
||||
set_page_params_no_edit_restrictions();
|
||||
realm.realm_can_delete_any_message_group = everyone.id;
|
||||
test("not_my_message_view_source_and_move", ({override}) => {
|
||||
set_page_params_no_edit_restrictions({override});
|
||||
override(realm, "realm_can_delete_any_message_group", everyone.id);
|
||||
// Get message that is movable with viewable source
|
||||
|
||||
const list = init_message_list();
|
||||
|
|
|
@ -85,7 +85,11 @@ people.initialize_current_user(me.user_id);
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
realm.server_presence_offline_threshold_seconds = OFFLINE_THRESHOLD_SECS;
|
||||
helpers.override(
|
||||
realm,
|
||||
"server_presence_offline_threshold_seconds",
|
||||
OFFLINE_THRESHOLD_SECS,
|
||||
);
|
||||
helpers.override(user_settings, "presence_enabled", true);
|
||||
presence.clear_internal_data();
|
||||
f(helpers);
|
||||
|
|
|
@ -162,7 +162,7 @@ const get_content_element = () => {
|
|||
return $content;
|
||||
};
|
||||
|
||||
run_test("misc_helpers", () => {
|
||||
run_test("misc_helpers", ({override}) => {
|
||||
const $elem = $.create("user-mention");
|
||||
rm.set_name_in_mention_element($elem, "Aaron");
|
||||
assert.equal($elem.text(), "@Aaron");
|
||||
|
@ -170,11 +170,11 @@ run_test("misc_helpers", () => {
|
|||
rm.set_name_in_mention_element($elem, "Aaron, but silent");
|
||||
assert.equal($elem.text(), "Aaron, but silent");
|
||||
|
||||
realm.realm_enable_guest_user_indicator = true;
|
||||
override(realm, "realm_enable_guest_user_indicator", true);
|
||||
rm.set_name_in_mention_element($elem, "Polonius", polonius.user_id);
|
||||
assert.equal($elem.text(), "translated: Polonius (guest)");
|
||||
|
||||
realm.realm_enable_guest_user_indicator = false;
|
||||
override(realm, "realm_enable_guest_user_indicator", false);
|
||||
rm.set_name_in_mention_element($elem, "Polonius", polonius.user_id);
|
||||
assert.equal($elem.text(), "Polonius");
|
||||
});
|
||||
|
@ -195,7 +195,7 @@ run_test("message_inline_video", () => {
|
|||
window.GestureEvent = false;
|
||||
});
|
||||
|
||||
run_test("user-mention", () => {
|
||||
run_test("user-mention", ({override}) => {
|
||||
// Setup
|
||||
const $content = get_content_element();
|
||||
const $iago = $.create("user-mention(iago)");
|
||||
|
@ -208,7 +208,7 @@ run_test("user-mention", () => {
|
|||
$polonius.set_find_results(".highlight", false);
|
||||
$polonius.attr("data-user-id", polonius.user_id);
|
||||
$content.set_find_results(".user-mention", $array([$iago, $cordelia, $polonius]));
|
||||
realm.realm_enable_guest_user_indicator = true;
|
||||
override(realm, "realm_enable_guest_user_indicator", true);
|
||||
// Initial asserts
|
||||
assert.ok(!$iago.hasClass("user-mention-me"));
|
||||
assert.equal($iago.text(), "never-been-set");
|
||||
|
@ -228,14 +228,14 @@ run_test("user-mention", () => {
|
|||
assert.ok($iago.hasClass("user-mention-me"));
|
||||
});
|
||||
|
||||
run_test("user-mention without guest indicator", () => {
|
||||
run_test("user-mention without guest indicator", ({override}) => {
|
||||
const $content = get_content_element();
|
||||
const $polonius = $.create("user-mention(polonius-again)");
|
||||
$polonius.set_find_results(".highlight", false);
|
||||
$polonius.attr("data-user-id", polonius.user_id);
|
||||
$content.set_find_results(".user-mention", $array([$polonius]));
|
||||
|
||||
realm.realm_enable_guest_user_indicator = false;
|
||||
override(realm, "realm_enable_guest_user_indicator", false);
|
||||
rm.update_elements($content);
|
||||
assert.equal($polonius.text(), `@${polonius.full_name}`);
|
||||
});
|
||||
|
|
|
@ -937,7 +937,7 @@ test("people_suggestions", ({override, mock_template}) => {
|
|||
}
|
||||
}
|
||||
|
||||
realm.realm_enable_guest_user_indicator = true;
|
||||
override(realm, "realm_enable_guest_user_indicator", true);
|
||||
suggestions = get_suggestions(query);
|
||||
|
||||
test_guest_user_indicator("dm:bob@zulip.com", false);
|
||||
|
@ -951,7 +951,7 @@ test("people_suggestions", ({override, mock_template}) => {
|
|||
test_guest_user_indicator("sender:bob@zulip.com", true);
|
||||
test_guest_user_indicator("dm-including:bob@zulip.com", true);
|
||||
|
||||
realm.realm_enable_guest_user_indicator = false;
|
||||
override(realm, "realm_enable_guest_user_indicator", false);
|
||||
suggestions = get_suggestions(query);
|
||||
|
||||
test_guest_user_indicator("dm:bob@zulip.com", false);
|
||||
|
|
|
@ -34,7 +34,7 @@ bot_data.initialize(bot_data_params);
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, ({override}) => {
|
||||
realm.realm_url = "https://chat.example.com";
|
||||
override(realm, "realm_url", "https://chat.example.com");
|
||||
realm.realm_embedded_bots = [
|
||||
{name: "converter", config: {}},
|
||||
{name: "giphy", config: {key: "12345678"}},
|
||||
|
@ -96,9 +96,9 @@ test("can_create_new_bots", ({override}) => {
|
|||
assert.ok(settings_bots.can_create_new_bots());
|
||||
|
||||
override(current_user, "is_admin", false);
|
||||
realm.realm_bot_creation_policy = 1;
|
||||
override(realm, "realm_bot_creation_policy", 1);
|
||||
assert.ok(settings_bots.can_create_new_bots());
|
||||
|
||||
realm.realm_bot_creation_policy = 3;
|
||||
override(realm, "realm_bot_creation_policy", 3);
|
||||
assert.ok(!settings_bots.can_create_new_bots());
|
||||
});
|
||||
|
|
|
@ -37,10 +37,10 @@ run_test("user_can_change_email", ({override}) => {
|
|||
assert.equal(can_change_email(), true);
|
||||
|
||||
override(current_user, "is_admin", false);
|
||||
realm.realm_email_changes_disabled = true;
|
||||
override(realm, "realm_email_changes_disabled", true);
|
||||
assert.equal(can_change_email(), false);
|
||||
|
||||
realm.realm_email_changes_disabled = false;
|
||||
override(realm, "realm_email_changes_disabled", false);
|
||||
assert.equal(can_change_email(), true);
|
||||
});
|
||||
|
||||
|
@ -51,16 +51,16 @@ run_test("user_can_change_name", ({override}) => {
|
|||
assert.equal(can_change_name(), true);
|
||||
|
||||
override(current_user, "is_admin", false);
|
||||
realm.realm_name_changes_disabled = true;
|
||||
realm.server_name_changes_disabled = false;
|
||||
override(realm, "realm_name_changes_disabled", true);
|
||||
override(realm, "server_name_changes_disabled", false);
|
||||
assert.equal(can_change_name(), false);
|
||||
|
||||
realm.realm_name_changes_disabled = false;
|
||||
realm.server_name_changes_disabled = false;
|
||||
override(realm, "realm_name_changes_disabled", false);
|
||||
override(realm, "server_name_changes_disabled", false);
|
||||
assert.equal(can_change_name(), true);
|
||||
|
||||
realm.realm_name_changes_disabled = false;
|
||||
realm.server_name_changes_disabled = true;
|
||||
override(realm, "realm_name_changes_disabled", false);
|
||||
override(realm, "server_name_changes_disabled", true);
|
||||
assert.equal(can_change_name(), false);
|
||||
});
|
||||
|
||||
|
@ -71,16 +71,16 @@ run_test("user_can_change_avatar", ({override}) => {
|
|||
assert.equal(can_change_avatar(), true);
|
||||
|
||||
override(current_user, "is_admin", false);
|
||||
realm.realm_avatar_changes_disabled = true;
|
||||
realm.server_avatar_changes_disabled = false;
|
||||
override(realm, "realm_avatar_changes_disabled", true);
|
||||
override(realm, "server_avatar_changes_disabled", false);
|
||||
assert.equal(can_change_avatar(), false);
|
||||
|
||||
realm.realm_avatar_changes_disabled = false;
|
||||
realm.server_avatar_changes_disabled = false;
|
||||
override(realm, "realm_avatar_changes_disabled", false);
|
||||
override(realm, "server_avatar_changes_disabled", false);
|
||||
assert.equal(can_change_avatar(), true);
|
||||
|
||||
realm.realm_avatar_changes_disabled = false;
|
||||
realm.server_avatar_changes_disabled = true;
|
||||
override(realm, "realm_avatar_changes_disabled", false);
|
||||
override(realm, "server_avatar_changes_disabled", true);
|
||||
assert.equal(can_change_avatar(), false);
|
||||
});
|
||||
|
||||
|
@ -88,19 +88,19 @@ run_test("user_can_change_logo", ({override}) => {
|
|||
const can_change_logo = settings_data.user_can_change_logo;
|
||||
|
||||
override(current_user, "is_admin", true);
|
||||
realm.zulip_plan_is_not_limited = true;
|
||||
override(realm, "zulip_plan_is_not_limited", true);
|
||||
assert.equal(can_change_logo(), true);
|
||||
|
||||
override(current_user, "is_admin", false);
|
||||
realm.zulip_plan_is_not_limited = false;
|
||||
override(realm, "zulip_plan_is_not_limited", false);
|
||||
assert.equal(can_change_logo(), false);
|
||||
|
||||
override(current_user, "is_admin", true);
|
||||
realm.zulip_plan_is_not_limited = false;
|
||||
override(realm, "zulip_plan_is_not_limited", false);
|
||||
assert.equal(can_change_logo(), false);
|
||||
|
||||
override(current_user, "is_admin", false);
|
||||
realm.zulip_plan_is_not_limited = true;
|
||||
override(realm, "zulip_plan_is_not_limited", true);
|
||||
assert.equal(can_change_logo(), false);
|
||||
});
|
||||
|
||||
|
@ -138,7 +138,7 @@ function test_policy(label, policy, validation_func) {
|
|||
override(current_user, "user_id", 30);
|
||||
isaac.date_joined = new Date(Date.now());
|
||||
settings_data.initialize(isaac.date_joined);
|
||||
realm.realm_waiting_period_threshold = 10;
|
||||
override(realm, "realm_waiting_period_threshold", 10);
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
isaac.date_joined = new Date(Date.now() - 20 * 86400000);
|
||||
|
@ -197,7 +197,7 @@ function test_message_policy(label, policy, validation_func) {
|
|||
realm[policy] = settings_config.common_message_policy_values.by_full_members.code;
|
||||
override(current_user, "user_id", 30);
|
||||
isaac.date_joined = new Date(Date.now());
|
||||
realm.realm_waiting_period_threshold = 10;
|
||||
override(realm, "realm_waiting_period_threshold", 10);
|
||||
settings_data.initialize(isaac.date_joined);
|
||||
assert.equal(validation_func(), false);
|
||||
|
||||
|
@ -216,7 +216,11 @@ test_message_policy(
|
|||
run_test("user_can_move_messages_to_another_topic_nobody_case", ({override}) => {
|
||||
override(current_user, "is_admin", true);
|
||||
override(current_user, "is_guest", false);
|
||||
realm.realm_edit_topic_policy = settings_config.edit_topic_policy_values.nobody.code;
|
||||
override(
|
||||
realm,
|
||||
"realm_edit_topic_policy",
|
||||
settings_config.edit_topic_policy_values.nobody.code,
|
||||
);
|
||||
assert.equal(settings_data.user_can_move_messages_to_another_topic(), false);
|
||||
});
|
||||
|
||||
|
@ -408,7 +412,7 @@ run_test("can_manage_user_group", ({override}) => {
|
|||
assert.ok(!settings_data.can_manage_user_group(students.id));
|
||||
|
||||
page_params.is_spectator = false;
|
||||
realm.realm_can_manage_all_groups = admins.id;
|
||||
override(realm, "realm_can_manage_all_groups", admins.id);
|
||||
override(current_user, "user_id", 3);
|
||||
assert.ok(!settings_data.can_manage_user_group(students.id));
|
||||
|
||||
|
@ -424,14 +428,14 @@ run_test("can_manage_user_group", ({override}) => {
|
|||
override(current_user, "user_id", 2);
|
||||
assert.ok(!settings_data.can_manage_user_group(students.id));
|
||||
|
||||
realm.realm_can_manage_all_groups = members.id;
|
||||
override(realm, "realm_can_manage_all_groups", members.id);
|
||||
override(current_user, "user_id", 3);
|
||||
assert.ok(!settings_data.can_manage_user_group(students.id));
|
||||
|
||||
override(current_user, "user_id", 2);
|
||||
assert.ok(settings_data.can_manage_user_group(students.id));
|
||||
|
||||
realm.realm_can_manage_all_groups = admins.id;
|
||||
override(realm, "realm_can_manage_all_groups", admins.id);
|
||||
override(current_user, "user_id", 2);
|
||||
assert.ok(!settings_data.can_manage_user_group(students.id));
|
||||
|
||||
|
@ -511,7 +515,7 @@ run_test("can_join_user_group", ({override}) => {
|
|||
user_groups.initialize({
|
||||
realm_user_groups: [admins, moderators, members, nobody, students],
|
||||
});
|
||||
realm.realm_can_manage_all_groups = nobody.id;
|
||||
override(realm, "realm_can_manage_all_groups", nobody.id);
|
||||
|
||||
page_params.is_spectator = true;
|
||||
assert.ok(!settings_data.can_join_user_group(students.id));
|
||||
|
@ -561,7 +565,7 @@ run_test("can_join_user_group", ({override}) => {
|
|||
override(current_user, "user_id", 4);
|
||||
assert.ok(settings_data.can_join_user_group(students.id));
|
||||
|
||||
realm.realm_can_manage_all_groups = moderators.id;
|
||||
override(realm, "realm_can_manage_all_groups", moderators.id);
|
||||
override(current_user, "user_id", 2);
|
||||
assert.ok(settings_data.can_join_user_group(students.id));
|
||||
});
|
||||
|
@ -605,7 +609,7 @@ run_test("user_can_access_all_other_users", ({override}) => {
|
|||
};
|
||||
|
||||
user_groups.initialize({realm_user_groups: [members, everyone]});
|
||||
realm.realm_can_access_all_users_group = members.id;
|
||||
override(realm, "realm_can_access_all_users_group", members.id);
|
||||
|
||||
// Test spectators case.
|
||||
page_params.is_spectator = true;
|
||||
|
@ -618,7 +622,7 @@ run_test("user_can_access_all_other_users", ({override}) => {
|
|||
override(current_user, "user_id", guest_user_id);
|
||||
assert.ok(!settings_data.user_can_access_all_other_users());
|
||||
|
||||
realm.realm_can_access_all_users_group = everyone.id;
|
||||
override(realm, "realm_can_access_all_users_group", everyone.id);
|
||||
assert.ok(settings_data.user_can_access_all_other_users());
|
||||
});
|
||||
|
||||
|
@ -648,8 +652,8 @@ run_test("user_can_create_private_streams", () => {
|
|||
});
|
||||
|
||||
run_test("user_can_create_web_public_streams", ({override}) => {
|
||||
realm.server_web_public_streams_enabled = true;
|
||||
realm.realm_enable_spectator_access = true;
|
||||
override(realm, "server_web_public_streams_enabled", true);
|
||||
override(realm, "realm_enable_spectator_access", true);
|
||||
|
||||
test_realm_group_settings(
|
||||
"realm_can_create_web_public_channel_group",
|
||||
|
@ -666,20 +670,20 @@ run_test("user_can_create_web_public_streams", ({override}) => {
|
|||
override(current_user, "user_id", owner_user_id);
|
||||
user_groups.initialize({realm_user_groups: [owners]});
|
||||
|
||||
realm.server_web_public_streams_enabled = true;
|
||||
realm.realm_enable_spectator_access = true;
|
||||
realm.realm_can_create_web_public_channel_group = owners.id;
|
||||
override(realm, "server_web_public_streams_enabled", true);
|
||||
override(realm, "realm_enable_spectator_access", true);
|
||||
override(realm, "realm_can_create_web_public_channel_group", owners.id);
|
||||
assert.equal(settings_data.user_can_create_web_public_streams(), true);
|
||||
|
||||
realm.realm_enable_spectator_access = false;
|
||||
realm.server_web_public_streams_enabled = true;
|
||||
override(realm, "realm_enable_spectator_access", false);
|
||||
override(realm, "server_web_public_streams_enabled", true);
|
||||
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
||||
|
||||
realm.realm_enable_spectator_access = true;
|
||||
realm.server_web_public_streams_enabled = false;
|
||||
override(realm, "realm_enable_spectator_access", true);
|
||||
override(realm, "server_web_public_streams_enabled", false);
|
||||
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
||||
|
||||
realm.realm_enable_spectator_access = false;
|
||||
realm.server_web_public_streams_enabled = false;
|
||||
override(realm, "realm_enable_spectator_access", false);
|
||||
override(realm, "server_web_public_streams_enabled", false);
|
||||
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
||||
});
|
||||
|
|
|
@ -38,7 +38,7 @@ function test(label, f) {
|
|||
{domain: "example.com", allow_subdomains: true},
|
||||
{domain: "example.org", allow_subdomains: false},
|
||||
];
|
||||
realm.realm_authentication_methods = {};
|
||||
helpers.override(realm, "realm_authentication_methods", {});
|
||||
settings_org.reset();
|
||||
f(helpers);
|
||||
});
|
||||
|
@ -288,7 +288,7 @@ function test_extract_property_name() {
|
|||
);
|
||||
}
|
||||
|
||||
function test_sync_realm_settings() {
|
||||
function test_sync_realm_settings({override}) {
|
||||
const $subsection_stub = $.create("org-subsection-stub");
|
||||
$subsection_stub.set_find_results(
|
||||
".save-button-controls",
|
||||
|
@ -339,7 +339,7 @@ function test_sync_realm_settings() {
|
|||
$property_dropdown_elem.attr("id", "id_realm_message_content_edit_limit_seconds");
|
||||
$property_dropdown_elem.closest = () => $subsection_stub;
|
||||
|
||||
realm.realm_message_content_edit_limit_seconds = 120;
|
||||
override(realm, "realm_message_content_edit_limit_seconds", 120);
|
||||
|
||||
settings_org.sync_realm_settings("message_content_edit_limit_seconds");
|
||||
assert.equal($("#id_realm_message_content_edit_limit_minutes").val(), "2");
|
||||
|
@ -347,11 +347,11 @@ function test_sync_realm_settings() {
|
|||
|
||||
{
|
||||
/* Test message content edit limit dropdown value sync */
|
||||
realm.realm_message_content_edit_limit_seconds = 120;
|
||||
override(realm, "realm_message_content_edit_limit_seconds", 120);
|
||||
settings_org.sync_realm_settings("message_content_edit_limit_seconds");
|
||||
assert.equal($("#id_realm_message_content_edit_limit_seconds").val(), "120");
|
||||
|
||||
realm.realm_message_content_edit_limit_seconds = 130;
|
||||
override(realm, "realm_message_content_edit_limit_seconds", 130);
|
||||
settings_org.sync_realm_settings("message_content_edit_limit_seconds");
|
||||
assert.equal($("#id_realm_message_content_edit_limit_seconds").val(), "custom_period");
|
||||
}
|
||||
|
@ -363,18 +363,18 @@ function test_sync_realm_settings() {
|
|||
$property_elem.attr("id", "id_realm_org_join_restrictions");
|
||||
$property_elem.closest = () => $subsection_stub;
|
||||
|
||||
realm.realm_emails_restricted_to_domains = true;
|
||||
realm.realm_disallow_disposable_email_addresses = false;
|
||||
override(realm, "realm_emails_restricted_to_domains", true);
|
||||
override(realm, "realm_disallow_disposable_email_addresses", false);
|
||||
settings_org.sync_realm_settings("emails_restricted_to_domains");
|
||||
assert.equal($("#id_realm_org_join_restrictions").val(), "only_selected_domain");
|
||||
|
||||
realm.realm_emails_restricted_to_domains = false;
|
||||
override(realm, "realm_emails_restricted_to_domains", false);
|
||||
|
||||
realm.realm_disallow_disposable_email_addresses = true;
|
||||
override(realm, "realm_disallow_disposable_email_addresses", true);
|
||||
settings_org.sync_realm_settings("emails_restricted_to_domains");
|
||||
assert.equal($("#id_realm_org_join_restrictions").val(), "no_disposable_email");
|
||||
|
||||
realm.realm_disallow_disposable_email_addresses = false;
|
||||
override(realm, "realm_disallow_disposable_email_addresses", false);
|
||||
settings_org.sync_realm_settings("emails_restricted_to_domains");
|
||||
assert.equal($("#id_realm_org_join_restrictions").val(), "no_restriction");
|
||||
}
|
||||
|
@ -392,7 +392,11 @@ function test_sync_realm_settings() {
|
|||
save_button_stubs.$save_button_controls,
|
||||
);
|
||||
$property_elem.val(settings_config.common_policy_values.by_admins_only.code);
|
||||
realm.realm_invite_to_realm_policy = settings_config.common_policy_values.by_members.code;
|
||||
override(
|
||||
realm,
|
||||
"realm_invite_to_realm_policy",
|
||||
settings_config.common_policy_values.by_members.code,
|
||||
);
|
||||
save_button_stubs.$save_button_controls.removeClass("hide");
|
||||
$subsection_stub.set_find_results(".prop-element", [$property_elem]);
|
||||
|
||||
|
@ -433,17 +437,21 @@ function test_parse_time_limit() {
|
|||
test_function("501.34", "501.3");
|
||||
}
|
||||
|
||||
function test_discard_changes_button(discard_changes) {
|
||||
function test_discard_changes_button({override}, discard_changes) {
|
||||
const ev = {
|
||||
preventDefault: noop,
|
||||
stopPropagation: noop,
|
||||
};
|
||||
|
||||
realm.realm_allow_edit_history = true;
|
||||
realm.realm_edit_topic_policy = settings_config.common_message_policy_values.by_everyone.code;
|
||||
realm.realm_allow_message_editing = true;
|
||||
realm.realm_message_content_edit_limit_seconds = 3600;
|
||||
realm.realm_message_content_delete_limit_seconds = 120;
|
||||
override(realm, "realm_allow_edit_history", true);
|
||||
override(
|
||||
realm,
|
||||
"realm_edit_topic_policy",
|
||||
settings_config.common_message_policy_values.by_everyone.code,
|
||||
);
|
||||
override(realm, "realm_allow_message_editing", true);
|
||||
override(realm, "realm_message_content_edit_limit_seconds", 3600);
|
||||
override(realm, "realm_message_content_delete_limit_seconds", 120);
|
||||
|
||||
const $allow_edit_history = $("#id_realm_allow_edit_history").prop("checked", false);
|
||||
const $edit_topic_policy = $("#id_realm_edit_topic_policy").val(
|
||||
|
@ -666,9 +674,10 @@ test("set_up", ({override, override_rewire}) => {
|
|||
test_upload_realm_icon(override, upload_realm_logo_or_icon);
|
||||
test_extract_property_name();
|
||||
test_change_save_button_state();
|
||||
test_sync_realm_settings();
|
||||
test_sync_realm_settings({override});
|
||||
test_parse_time_limit();
|
||||
test_discard_changes_button(
|
||||
{override},
|
||||
$(".admin-realm-form").get_on_handler(
|
||||
"click",
|
||||
".subsection-header .subsection-changes-discard button",
|
||||
|
@ -793,52 +802,52 @@ test("misc", ({override}) => {
|
|||
$("#user-avatar-upload-widget").length = 1;
|
||||
$("#user_details_section").length = 1;
|
||||
|
||||
realm.realm_name_changes_disabled = false;
|
||||
realm.server_name_changes_disabled = false;
|
||||
override(realm, "realm_name_changes_disabled", false);
|
||||
override(realm, "server_name_changes_disabled", false);
|
||||
settings_account.update_name_change_display();
|
||||
assert.ok(!$("#full_name").prop("disabled"));
|
||||
assert.ok(!$("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
||||
|
||||
realm.realm_name_changes_disabled = true;
|
||||
realm.server_name_changes_disabled = false;
|
||||
override(realm, "realm_name_changes_disabled", true);
|
||||
override(realm, "server_name_changes_disabled", false);
|
||||
settings_account.update_name_change_display();
|
||||
assert.ok($("#full_name").prop("disabled"));
|
||||
assert.ok($("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
||||
|
||||
realm.realm_name_changes_disabled = true;
|
||||
realm.server_name_changes_disabled = true;
|
||||
override(realm, "realm_name_changes_disabled", true);
|
||||
override(realm, "server_name_changes_disabled", true);
|
||||
settings_account.update_name_change_display();
|
||||
assert.ok($("#full_name").prop("disabled"));
|
||||
assert.ok($("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
||||
|
||||
realm.realm_name_changes_disabled = false;
|
||||
realm.server_name_changes_disabled = true;
|
||||
override(realm, "realm_name_changes_disabled", false);
|
||||
override(realm, "server_name_changes_disabled", true);
|
||||
settings_account.update_name_change_display();
|
||||
assert.ok($("#full_name").prop("disabled"));
|
||||
assert.ok($("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
||||
|
||||
realm.realm_email_changes_disabled = false;
|
||||
override(realm, "realm_email_changes_disabled", false);
|
||||
settings_account.update_email_change_display();
|
||||
assert.ok(!$("#change_email_button").prop("disabled"));
|
||||
|
||||
realm.realm_email_changes_disabled = true;
|
||||
override(realm, "realm_email_changes_disabled", true);
|
||||
settings_account.update_email_change_display();
|
||||
assert.ok($("#change_email_button").prop("disabled"));
|
||||
|
||||
realm.realm_avatar_changes_disabled = false;
|
||||
realm.server_avatar_changes_disabled = false;
|
||||
override(realm, "realm_avatar_changes_disabled", false);
|
||||
override(realm, "server_avatar_changes_disabled", false);
|
||||
settings_account.update_avatar_change_display();
|
||||
assert.ok(!$("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
||||
realm.realm_avatar_changes_disabled = true;
|
||||
realm.server_avatar_changes_disabled = false;
|
||||
override(realm, "realm_avatar_changes_disabled", true);
|
||||
override(realm, "server_avatar_changes_disabled", false);
|
||||
settings_account.update_avatar_change_display();
|
||||
assert.ok($("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
||||
realm.realm_avatar_changes_disabled = false;
|
||||
realm.server_avatar_changes_disabled = true;
|
||||
override(realm, "realm_avatar_changes_disabled", false);
|
||||
override(realm, "server_avatar_changes_disabled", true);
|
||||
settings_account.update_avatar_change_display();
|
||||
assert.ok($("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
||||
realm.realm_avatar_changes_disabled = true;
|
||||
realm.server_avatar_changes_disabled = true;
|
||||
override(realm, "realm_avatar_changes_disabled", true);
|
||||
override(realm, "server_avatar_changes_disabled", true);
|
||||
settings_account.update_avatar_change_display();
|
||||
assert.ok($("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ function test_populate(opts, template_data) {
|
|||
with_overrides(({override}) => {
|
||||
const fields_data = opts.fields_data;
|
||||
|
||||
realm.custom_profile_field_types = custom_profile_field_types;
|
||||
override(realm, "custom_profile_field_types", custom_profile_field_types);
|
||||
override(current_user, "is_admin", opts.is_admin);
|
||||
const $table = $("#admin_profile_fields_table");
|
||||
const $rows = $.create("rows");
|
||||
|
@ -82,9 +82,9 @@ function test_populate(opts, template_data) {
|
|||
});
|
||||
}
|
||||
|
||||
run_test("populate_profile_fields", ({mock_template}) => {
|
||||
realm.custom_profile_fields = {};
|
||||
realm.realm_default_external_accounts = JSON.stringify({});
|
||||
run_test("populate_profile_fields", ({mock_template, override}) => {
|
||||
override(realm, "custom_profile_fields", {});
|
||||
override(realm, "realm_default_external_accounts", JSON.stringify({}));
|
||||
|
||||
$("#admin_profile_fields_table .display_in_profile_summary_false").toggleClass = noop;
|
||||
|
||||
|
|
|
@ -324,7 +324,11 @@ test("get_streams_for_user", ({override}) => {
|
|||
peer_data.set_subscribers(test.stream_id, [test_user.user_id]);
|
||||
peer_data.set_subscribers(world.stream_id, [me.user_id]);
|
||||
|
||||
realm.realm_invite_to_stream_policy = settings_config.common_policy_values.by_admins_only.code;
|
||||
override(
|
||||
realm,
|
||||
"realm_invite_to_stream_policy",
|
||||
settings_config.common_policy_values.by_admins_only.code,
|
||||
);
|
||||
assert.deepEqual(stream_data.get_streams_for_user(me.user_id).can_subscribe, [social, errors]);
|
||||
|
||||
// test_user is subscribed to all three streams, but current user (me)
|
||||
|
@ -347,7 +351,11 @@ test("get_streams_for_user", ({override}) => {
|
|||
]);
|
||||
override(current_user, "is_admin", false);
|
||||
|
||||
realm.realm_invite_to_stream_policy = settings_config.common_policy_values.by_members.code;
|
||||
override(
|
||||
realm,
|
||||
"realm_invite_to_stream_policy",
|
||||
settings_config.common_policy_values.by_members.code,
|
||||
);
|
||||
assert.deepEqual(stream_data.get_streams_for_user(test_user.user_id).can_subscribe, [
|
||||
world,
|
||||
errors,
|
||||
|
@ -757,14 +765,14 @@ const jazy = {
|
|||
is_muted: true,
|
||||
};
|
||||
|
||||
test("is_new_stream_announcements_stream_muted", () => {
|
||||
test("is_new_stream_announcements_stream_muted", ({override}) => {
|
||||
stream_data.add_sub(tony);
|
||||
stream_data.add_sub(jazy);
|
||||
|
||||
realm.realm_new_stream_announcements_stream_id = tony.stream_id;
|
||||
override(realm, "realm_new_stream_announcements_stream_id", tony.stream_id);
|
||||
assert.ok(!stream_data.is_new_stream_announcements_stream_muted());
|
||||
|
||||
realm.realm_new_stream_announcements_stream_id = jazy.stream_id;
|
||||
override(realm, "realm_new_stream_announcements_stream_id", jazy.stream_id);
|
||||
assert.ok(stream_data.is_new_stream_announcements_stream_muted());
|
||||
});
|
||||
|
||||
|
@ -814,10 +822,10 @@ test("muted_stream_ids", () => {
|
|||
assert.deepEqual(stream_data.muted_stream_ids(), [1, 3]);
|
||||
});
|
||||
|
||||
test("realm_has_new_stream_announcements_stream", () => {
|
||||
realm.realm_new_stream_announcements_stream_id = 10;
|
||||
test("realm_has_new_stream_announcements_stream", ({override}) => {
|
||||
override(realm, "realm_new_stream_announcements_stream_id", 10);
|
||||
assert.ok(stream_data.realm_has_new_stream_announcements_stream());
|
||||
realm.realm_new_stream_announcements_stream_id = -1;
|
||||
override(realm, "realm_new_stream_announcements_stream_id", -1);
|
||||
assert.ok(!stream_data.realm_has_new_stream_announcements_stream());
|
||||
});
|
||||
|
||||
|
@ -879,7 +887,7 @@ test("create_sub", () => {
|
|||
|
||||
test("creator_id", ({override}) => {
|
||||
people.add_active_user(test_user);
|
||||
realm.realm_can_access_all_users_group = everyone_group.id;
|
||||
override(realm, "realm_can_access_all_users_group", everyone_group.id);
|
||||
override(current_user, "user_id", me.user_id);
|
||||
// When creator id is not a valid user id
|
||||
assert.throws(() => stream_data.maybe_get_creator_details(-1), {
|
||||
|
@ -905,7 +913,7 @@ test("creator_id", ({override}) => {
|
|||
);
|
||||
});
|
||||
|
||||
test("initialize", () => {
|
||||
test("initialize", ({override}) => {
|
||||
function get_params() {
|
||||
const params = {};
|
||||
|
||||
|
@ -939,7 +947,7 @@ test("initialize", () => {
|
|||
stream_data.initialize(get_params());
|
||||
}
|
||||
|
||||
realm.realm_new_stream_announcements_stream_id = -1;
|
||||
override(realm, "realm_new_stream_announcements_stream_id", -1);
|
||||
|
||||
initialize();
|
||||
|
||||
|
@ -950,7 +958,7 @@ test("initialize", () => {
|
|||
assert.equal(stream_data.get_new_stream_announcements_stream(), "");
|
||||
|
||||
// Simulate a private stream the user isn't subscribed to
|
||||
realm.realm_new_stream_announcements_stream_id = 89;
|
||||
override(realm, "realm_new_stream_announcements_stream_id", 89);
|
||||
initialize();
|
||||
assert.equal(stream_data.get_new_stream_announcements_stream(), "");
|
||||
|
||||
|
@ -1081,7 +1089,7 @@ test("can_post_messages_in_stream", ({override}) => {
|
|||
social.stream_post_policy = settings_config.stream_post_policy_values.non_new_members.code;
|
||||
override(current_user, "is_moderator", false);
|
||||
me.date_joined = new Date(Date.now());
|
||||
realm.realm_waiting_period_threshold = 10;
|
||||
override(realm, "realm_waiting_period_threshold", 10);
|
||||
assert.equal(stream_data.can_post_messages_in_stream(social), false);
|
||||
|
||||
me.date_joined = new Date(Date.now() - 20 * 86400000);
|
||||
|
|
|
@ -179,7 +179,7 @@ function test(label, f) {
|
|||
peer_data.clear_for_testing();
|
||||
people.clear_recipient_counts_for_testing();
|
||||
helpers.override(current_user, "is_admin", false);
|
||||
realm.realm_is_zephyr_mirror_realm = false;
|
||||
helpers.override(realm, "realm_is_zephyr_mirror_realm", false);
|
||||
|
||||
f(helpers);
|
||||
});
|
||||
|
|
|
@ -6,9 +6,6 @@ const _ = require("lodash");
|
|||
|
||||
const {set_global, with_overrides, zrequire} = require("./lib/namespace");
|
||||
const {run_test} = require("./lib/test");
|
||||
const {realm} = require("./lib/zpage_params");
|
||||
|
||||
realm.realm_push_notifications_enabled = false;
|
||||
|
||||
set_global("document", "document-stub");
|
||||
const {FoldDict} = zrequire("fold_dict");
|
||||
|
|
|
@ -39,7 +39,7 @@ message_lists.current = {
|
|||
};
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
realm.max_file_upload_size_mib = 25;
|
||||
helpers.override(realm, "max_file_upload_size_mib", 25);
|
||||
return f(helpers);
|
||||
});
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ test("show_error_message", ({mock_template}) => {
|
|||
upload.show_error_message(upload.compose_config);
|
||||
});
|
||||
|
||||
test("upload_files", async ({mock_template, override_rewire}) => {
|
||||
test("upload_files", async ({mock_template, override, override_rewire}) => {
|
||||
$("#compose_banners .upload_banner").remove = noop;
|
||||
$("#compose_banners .upload_banner .moving_bar").css = noop;
|
||||
$("#compose_banners .upload_banner").length = 0;
|
||||
|
@ -208,12 +208,12 @@ test("upload_files", async ({mock_template, override_rewire}) => {
|
|||
banner_shown = true;
|
||||
return "<banner-stub>";
|
||||
});
|
||||
realm.max_file_upload_size_mib = 0;
|
||||
override(realm, "max_file_upload_size_mib", 0);
|
||||
$("#compose_banners .upload_banner .upload_msg").text("");
|
||||
await upload.upload_files(uppy, config, files);
|
||||
assert.ok(banner_shown);
|
||||
|
||||
realm.max_file_upload_size_mib = 25;
|
||||
override(realm, "max_file_upload_size_mib", 25);
|
||||
let on_click_close_button_callback;
|
||||
|
||||
$("#compose_banners .upload_banner.file_id_123 .upload_banner_cancel_button").one = (
|
||||
|
|
|
@ -67,13 +67,13 @@ function test(label, f) {
|
|||
});
|
||||
}
|
||||
|
||||
test("create_item", () => {
|
||||
test("create_item", ({override}) => {
|
||||
function test_create_item(email, current_items, expected_item, pill_config) {
|
||||
const item = user_pill.create_item_from_email(email, current_items, pill_config);
|
||||
assert.deepEqual(item, expected_item);
|
||||
}
|
||||
|
||||
realm.realm_is_zephyr_mirror_realm = true;
|
||||
override(realm, "realm_is_zephyr_mirror_realm", true);
|
||||
|
||||
test_create_item("bogus@example.com", [], bogus_item);
|
||||
test_create_item("bogus@example.com", [bogus_item], undefined);
|
||||
|
@ -81,14 +81,14 @@ test("create_item", () => {
|
|||
test_create_item("isaac@example.com", [], isaac_item);
|
||||
test_create_item("isaac@example.com", [isaac_item], undefined);
|
||||
|
||||
realm.realm_is_zephyr_mirror_realm = false;
|
||||
override(realm, "realm_is_zephyr_mirror_realm", false);
|
||||
|
||||
test_create_item("bogus@example.com", [], undefined);
|
||||
test_create_item("isaac@example.com", [], isaac_item);
|
||||
test_create_item("isaac@example.com", [isaac_item], undefined);
|
||||
|
||||
settings_data.user_can_access_all_other_users = () => false;
|
||||
realm.realm_bot_domain = "example.com";
|
||||
override(realm, "realm_bot_domain", "example.com");
|
||||
people.add_inaccessible_user(inaccessible_user_id);
|
||||
|
||||
test_create_item("user103@example.com", [], undefined, {exclude_inaccessible_users: true});
|
||||
|
|
|
@ -122,7 +122,7 @@ test("clear_search", ({override}) => {
|
|||
});
|
||||
|
||||
test("escape_search", ({override}) => {
|
||||
realm.realm_presence_disabled = true;
|
||||
override(realm, "realm_presence_disabled", true);
|
||||
|
||||
override(resize, "resize_sidebars", noop);
|
||||
override(popovers, "hide_all", noop);
|
||||
|
@ -233,7 +233,7 @@ test("click on user header to toggle display", ({override}) => {
|
|||
override(sidebar_ui, "show_userlist_sidebar", noop);
|
||||
override(resize, "resize_sidebars", noop);
|
||||
|
||||
realm.realm_presence_disabled = true;
|
||||
override(realm, "realm_presence_disabled", true);
|
||||
|
||||
assert.ok(!$("#user_search_section").hasClass("notdisplayed"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue