mirror of https://github.com/zulip/zulip.git
tests: Use override for user_settings.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
8271ac97e6
commit
4d74ecccf3
|
@ -116,7 +116,7 @@ function add_sub_and_set_as_current_narrow(sub) {
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
user_settings.presence_enabled = true;
|
||||
helpers.override(user_settings, "presence_enabled", true);
|
||||
// Simulate a small window by having the
|
||||
// fill_screen_with_content render the entire
|
||||
// list in one pass. We will do more refined
|
||||
|
@ -158,7 +158,7 @@ run_test("reload_defaults", () => {
|
|||
assert.equal(activity_ui.get_filter_text(), "");
|
||||
});
|
||||
|
||||
test("get_status", () => {
|
||||
test("get_status", ({override}) => {
|
||||
page_params.realm_users = [];
|
||||
current_user.user_id = 999;
|
||||
|
||||
|
@ -167,9 +167,9 @@ test("get_status", () => {
|
|||
assert.equal(presence.get_status(mark.user_id), "idle");
|
||||
assert.equal(presence.get_status(fred.user_id), "active");
|
||||
|
||||
user_settings.presence_enabled = false;
|
||||
override(user_settings, "presence_enabled", false);
|
||||
assert.equal(presence.get_status(current_user.user_id), "offline");
|
||||
user_settings.presence_enabled = true;
|
||||
override(user_settings, "presence_enabled", true);
|
||||
assert.equal(presence.get_status(current_user.user_id), "active");
|
||||
|
||||
presence.presence_info.delete(zoe.user_id);
|
||||
|
@ -505,7 +505,7 @@ test("render_empty_user_list_message", ({override, mock_template}) => {
|
|||
});
|
||||
|
||||
test("insert_one_user_into_empty_list", ({override, mock_template}) => {
|
||||
user_settings.user_list_style = 2;
|
||||
override(user_settings, "user_list_style", 2);
|
||||
|
||||
override(padded_widget, "update_padding", noop);
|
||||
mock_template("presence_row.hbs", true, (data, html) => {
|
||||
|
|
|
@ -13,11 +13,11 @@ window.location.hash = "#bogus";
|
|||
const browser_history = zrequire("browser_history");
|
||||
|
||||
function test(label, f) {
|
||||
run_test(label, (...args) => {
|
||||
user_settings.web_home_view = "recent";
|
||||
run_test(label, (helpers) => {
|
||||
helpers.override(user_settings, "web_home_view", "recent");
|
||||
window.location.hash = "#bogus";
|
||||
browser_history.clear_for_testing();
|
||||
f(...args);
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ function add_canned_users() {
|
|||
|
||||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
user_settings.presence_enabled = true;
|
||||
helpers.override(user_settings, "presence_enabled", true);
|
||||
compose_fade_helper.clear_focused_recipient();
|
||||
stream_data.clear_subscriptions();
|
||||
peer_data.clear_for_testing();
|
||||
|
@ -126,7 +126,7 @@ function set_presence(user_id, status) {
|
|||
});
|
||||
}
|
||||
|
||||
test("user_circle, level", () => {
|
||||
test("user_circle, level", ({override}) => {
|
||||
add_canned_users();
|
||||
|
||||
set_presence(selma.user_id, "active");
|
||||
|
@ -145,11 +145,11 @@ test("user_circle, level", () => {
|
|||
assert.equal(buddy_data.get_user_circle_class(me.user_id), "user_circle_green");
|
||||
assert.equal(buddy_data.level(me.user_id), 0);
|
||||
|
||||
user_settings.presence_enabled = false;
|
||||
override(user_settings, "presence_enabled", false);
|
||||
assert.equal(buddy_data.get_user_circle_class(me.user_id), "user_circle_empty");
|
||||
assert.equal(buddy_data.level(me.user_id), 0);
|
||||
|
||||
user_settings.presence_enabled = true;
|
||||
override(user_settings, "presence_enabled", true);
|
||||
assert.equal(buddy_data.get_user_circle_class(me.user_id), "user_circle_green");
|
||||
assert.equal(buddy_data.level(me.user_id), 0);
|
||||
|
||||
|
@ -412,7 +412,7 @@ test("get_conversation_participants", ({override_rewire}) => {
|
|||
assert.deepEqual(buddy_data.get_conversation_participants(), new Set([selma.user_id]));
|
||||
});
|
||||
|
||||
test("level", () => {
|
||||
test("level", ({override}) => {
|
||||
realm.server_presence_offline_threshold_seconds = 200;
|
||||
|
||||
add_canned_users();
|
||||
|
@ -432,7 +432,7 @@ test("level", () => {
|
|||
assert.equal(buddy_data.level(me.user_id), 0);
|
||||
assert.equal(buddy_data.level(selma.user_id), 1);
|
||||
|
||||
user_settings.presence_enabled = false;
|
||||
override(user_settings, "presence_enabled", false);
|
||||
set_presence(selma.user_id, "offline");
|
||||
|
||||
// Selma gets demoted to level 3, but "me"
|
||||
|
@ -557,12 +557,12 @@ test("user_last_seen_time_status", ({override}) => {
|
|||
assert.equal(buddy_data.user_last_seen_time_status(selma.user_id), "translated: Idle");
|
||||
});
|
||||
|
||||
test("get_items_for_users", () => {
|
||||
test("get_items_for_users", ({override}) => {
|
||||
people.add_active_user(alice);
|
||||
people.add_active_user(fred);
|
||||
set_presence(alice.user_id, "offline");
|
||||
user_settings.emojiset = "google";
|
||||
user_settings.user_list_style = 2;
|
||||
override(user_settings, "emojiset", "google");
|
||||
override(user_settings, "user_list_style", 2);
|
||||
|
||||
const status_emoji_info = {
|
||||
emoji_alt_code: false,
|
||||
|
|
|
@ -408,7 +408,7 @@ test_ui("enter_with_preview_open", ({override, override_rewire}) => {
|
|||
$("#compose .preview_message_area").show();
|
||||
$("#compose .markdown_preview").hide();
|
||||
$("#compose").addClass("preview_mode");
|
||||
user_settings.enter_sends = true;
|
||||
override(user_settings, "enter_sends", true);
|
||||
let send_message_called = false;
|
||||
override_rewire(compose, "send_message", () => {
|
||||
send_message_called = true;
|
||||
|
@ -421,7 +421,7 @@ test_ui("enter_with_preview_open", ({override, override_rewire}) => {
|
|||
assert.ok(send_message_called);
|
||||
assert.ok(show_button_spinner_called);
|
||||
|
||||
user_settings.enter_sends = false;
|
||||
override(user_settings, "enter_sends", false);
|
||||
$("textarea#compose-textarea").trigger("blur");
|
||||
compose.enter_with_preview_open();
|
||||
assert.ok($("textarea#compose-textarea").is_focused());
|
||||
|
@ -429,7 +429,7 @@ test_ui("enter_with_preview_open", ({override, override_rewire}) => {
|
|||
// Test sending a message without content.
|
||||
$("textarea#compose-textarea").val("");
|
||||
$("#compose .preview_message_area").show();
|
||||
user_settings.enter_sends = true;
|
||||
override(user_settings, "enter_sends", true);
|
||||
|
||||
compose.enter_with_preview_open();
|
||||
});
|
||||
|
|
|
@ -1286,7 +1286,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
|
|||
}
|
||||
});
|
||||
|
||||
user_settings.enter_sends = false;
|
||||
override(user_settings, "enter_sends", false);
|
||||
let compose_finish_called = false;
|
||||
function finish() {
|
||||
compose_finish_called = true;
|
||||
|
@ -1328,7 +1328,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
|
|||
$stub_target.attr("id", "stream_message_recipient_topic");
|
||||
$("form#send_message_form").trigger(event);
|
||||
$stub_target.attr("id", "compose-textarea");
|
||||
user_settings.enter_sends = false;
|
||||
override(user_settings, "enter_sends", false);
|
||||
event.metaKey = true;
|
||||
|
||||
$("form#send_message_form").trigger(event);
|
||||
|
@ -1336,7 +1336,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
|
|||
event.metaKey = false;
|
||||
event.ctrlKey = true;
|
||||
$("form#send_message_form").trigger(event);
|
||||
user_settings.enter_sends = true;
|
||||
override(user_settings, "enter_sends", true);
|
||||
event.ctrlKey = false;
|
||||
event.altKey = true;
|
||||
$("form#send_message_form").trigger(event);
|
||||
|
|
|
@ -893,7 +893,7 @@ run_test("stream_typing", ({override}) => {
|
|||
run_test("user_settings", ({override}) => {
|
||||
settings_preferences.set_default_language_name = () => {};
|
||||
let event = event_fixtures.user_settings__default_language;
|
||||
user_settings.default_language = "en";
|
||||
override(user_settings, "default_language", "en");
|
||||
override(settings_preferences, "update_page", noop);
|
||||
override(information_density, "calculate_timestamp_widths", noop);
|
||||
override(overlays, "settings_open", () => true);
|
||||
|
@ -901,7 +901,7 @@ run_test("user_settings", ({override}) => {
|
|||
assert_same(user_settings.default_language, "fr");
|
||||
|
||||
event = event_fixtures.user_settings__web_escape_navigates_to_home_view;
|
||||
user_settings.web_escape_navigates_to_home_view = false;
|
||||
override(user_settings, "web_escape_navigates_to_home_view", false);
|
||||
let toggled = [];
|
||||
$("#go-to-home-view-hotkey-help").toggleClass = (cls) => {
|
||||
toggled.push(cls);
|
||||
|
@ -919,24 +919,24 @@ run_test("user_settings", ({override}) => {
|
|||
called_for_cached_msg_list = true;
|
||||
};
|
||||
event = event_fixtures.user_settings__twenty_four_hour_time;
|
||||
user_settings.twenty_four_hour_time = false;
|
||||
override(user_settings, "twenty_four_hour_time", false);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.twenty_four_hour_time, true);
|
||||
assert_same(called, true);
|
||||
assert_same(called_for_cached_msg_list, true);
|
||||
|
||||
event = event_fixtures.user_settings__translate_emoticons;
|
||||
user_settings.translate_emoticons = false;
|
||||
override(user_settings, "translate_emoticons", false);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.translate_emoticons, true);
|
||||
|
||||
event = event_fixtures.user_settings__display_emoji_reaction_users;
|
||||
user_settings.display_emoji_reaction_users = false;
|
||||
override(user_settings, "display_emoji_reaction_users", false);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.display_emoji_reaction_users, true);
|
||||
|
||||
event = event_fixtures.user_settings__high_contrast_mode;
|
||||
user_settings.high_contrast_mode = false;
|
||||
override(user_settings, "high_contrast_mode", false);
|
||||
toggled = [];
|
||||
$("body").toggleClass = (cls) => {
|
||||
toggled.push(cls);
|
||||
|
@ -946,18 +946,18 @@ run_test("user_settings", ({override}) => {
|
|||
assert_same(toggled, ["high-contrast"]);
|
||||
|
||||
event = event_fixtures.user_settings__web_mark_read_on_scroll_policy;
|
||||
user_settings.web_mark_read_on_scroll_policy = 3;
|
||||
override(user_settings, "web_mark_read_on_scroll_policy", 3);
|
||||
override(unread_ui, "update_unread_banner", noop);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.web_mark_read_on_scroll_policy, 1);
|
||||
|
||||
event = event_fixtures.user_settings__web_channel_default_view;
|
||||
user_settings.web_channel_default_view = 2;
|
||||
override(user_settings, "web_channel_default_view", 2);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.web_channel_default_view, 1);
|
||||
|
||||
event = event_fixtures.user_settings__dense_mode;
|
||||
user_settings.dense_mode = false;
|
||||
override(user_settings, "dense_mode", false);
|
||||
settings_preferences.user_settings_panel = {
|
||||
container: "#user-preferences",
|
||||
};
|
||||
|
@ -968,13 +968,13 @@ run_test("user_settings", ({override}) => {
|
|||
assert_same(toggled, ["less-dense-mode", "more-dense-mode"]);
|
||||
|
||||
event = event_fixtures.user_settings__web_font_size_px;
|
||||
user_settings.web_font_size_px = 14;
|
||||
override(user_settings, "web_font_size_px", 14);
|
||||
override(information_density, "set_base_typography_css_variables", noop);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.web_font_size_px, 16);
|
||||
|
||||
event = event_fixtures.user_settings__web_line_height_percent;
|
||||
user_settings.web_font_size_px = 122;
|
||||
override(user_settings, "web_font_size_px", 122);
|
||||
override(information_density, "set_base_typography_css_variables", noop);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.web_line_height_percent, 130);
|
||||
|
@ -982,7 +982,7 @@ run_test("user_settings", ({override}) => {
|
|||
{
|
||||
const stub = make_stub();
|
||||
event = event_fixtures.user_settings__color_scheme_automatic;
|
||||
user_settings.color_scheme = 2;
|
||||
override(user_settings, "color_scheme", 2);
|
||||
override(theme, "set_theme_and_update", stub.f); // automatically checks if called
|
||||
dispatch(event);
|
||||
const args = stub.get_args("color_scheme_code");
|
||||
|
@ -993,7 +993,7 @@ run_test("user_settings", ({override}) => {
|
|||
{
|
||||
const stub = make_stub();
|
||||
event = event_fixtures.user_settings__color_scheme_dark;
|
||||
user_settings.color_scheme = 1;
|
||||
override(user_settings, "color_scheme", 1);
|
||||
override(theme, "set_theme_and_update", stub.f); // automatically checks if called
|
||||
dispatch(event);
|
||||
const args = stub.get_args("color_scheme_code");
|
||||
|
@ -1004,7 +1004,7 @@ run_test("user_settings", ({override}) => {
|
|||
{
|
||||
const stub = make_stub();
|
||||
event = event_fixtures.user_settings__color_scheme_light;
|
||||
user_settings.color_scheme = 1;
|
||||
override(user_settings, "color_scheme", 1);
|
||||
override(theme, "set_theme_and_update", stub.f); // automatically checks if called
|
||||
dispatch(event);
|
||||
const args = stub.get_args("color_scheme_code");
|
||||
|
@ -1014,41 +1014,41 @@ run_test("user_settings", ({override}) => {
|
|||
|
||||
{
|
||||
event = event_fixtures.user_settings__web_home_view_recent_topics;
|
||||
user_settings.web_home_view = "all_messages";
|
||||
override(user_settings, "web_home_view", "all_messages");
|
||||
dispatch(event);
|
||||
assert.equal(user_settings.web_home_view, "recent_topics");
|
||||
}
|
||||
|
||||
{
|
||||
event = event_fixtures.user_settings__web_home_view_all_messages;
|
||||
user_settings.web_home_view = "recent_topics";
|
||||
override(user_settings, "web_home_view", "recent_topics");
|
||||
dispatch(event);
|
||||
assert.equal(user_settings.web_home_view, "all_messages");
|
||||
}
|
||||
|
||||
{
|
||||
event = event_fixtures.user_settings__web_home_view_inbox;
|
||||
user_settings.web_home_view = "all_messages";
|
||||
override(user_settings, "web_home_view", "all_messages");
|
||||
dispatch(event);
|
||||
assert.equal(user_settings.web_home_view, "inbox");
|
||||
}
|
||||
{
|
||||
event = event_fixtures.user_settings__web_animate_image_previews_always;
|
||||
user_settings.web_animate_image_previews = "on_hover";
|
||||
override(user_settings, "web_animate_image_previews", "on_hover");
|
||||
dispatch(event);
|
||||
assert.equal(user_settings.web_animate_image_previews, "always");
|
||||
}
|
||||
|
||||
{
|
||||
event = event_fixtures.user_settings__web_animate_image_previews_on_hover;
|
||||
user_settings.web_animate_image_previews = "never";
|
||||
override(user_settings, "web_animate_image_previews", "never");
|
||||
dispatch(event);
|
||||
assert.equal(user_settings.web_animate_image_previews, "on_hover");
|
||||
}
|
||||
|
||||
{
|
||||
event = event_fixtures.user_settings__web_animate_image_previews_never;
|
||||
user_settings.web_animate_image_previews = "always";
|
||||
override(user_settings, "web_animate_image_previews", "always");
|
||||
dispatch(event);
|
||||
assert.equal(user_settings.web_animate_image_previews, "never");
|
||||
}
|
||||
|
@ -1059,7 +1059,7 @@ run_test("user_settings", ({override}) => {
|
|||
called = false;
|
||||
override(settings_preferences, "report_emojiset_change", stub.f);
|
||||
override(activity_ui, "build_user_sidebar", noop);
|
||||
user_settings.emojiset = "text";
|
||||
override(user_settings, "emojiset", "text");
|
||||
dispatch(event);
|
||||
assert.equal(stub.num_calls, 1);
|
||||
assert_same(called, true);
|
||||
|
@ -1067,24 +1067,24 @@ run_test("user_settings", ({override}) => {
|
|||
}
|
||||
|
||||
event = event_fixtures.user_settings__starred_message_counts;
|
||||
user_settings.starred_message_counts = false;
|
||||
override(user_settings, "starred_message_counts", false);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.starred_message_counts, true);
|
||||
|
||||
event = event_fixtures.user_settings__receives_typing_notifications;
|
||||
user_settings.receives_typing_notifications = false;
|
||||
override(user_settings, "receives_typing_notifications", false);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.receives_typing_notifications, true);
|
||||
|
||||
event = event_fixtures.user_settings__receives_typing_notifications_disabled;
|
||||
override(typing_events, "disable_typing_notification", noop);
|
||||
user_settings.receives_typing_notifications = true;
|
||||
override(user_settings, "receives_typing_notifications", true);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.receives_typing_notifications, false);
|
||||
|
||||
override(scroll_bar, "set_layout_width", noop);
|
||||
event = event_fixtures.user_settings__fluid_layout_width;
|
||||
user_settings.fluid_layout_width = false;
|
||||
override(user_settings, "fluid_layout_width", false);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.fluid_layout_width, true);
|
||||
|
||||
|
@ -1093,7 +1093,7 @@ run_test("user_settings", ({override}) => {
|
|||
event = event_fixtures.user_settings__demote_inactive_streams;
|
||||
override(stream_list_sort, "set_filter_out_inactives", noop);
|
||||
override(stream_list, "update_streams_sidebar", stub.f);
|
||||
user_settings.demote_inactive_streams = 1;
|
||||
override(user_settings, "demote_inactive_streams", 1);
|
||||
dispatch(event);
|
||||
assert.equal(stub.num_calls, 1);
|
||||
assert_same(user_settings.demote_inactive_streams, 2);
|
||||
|
@ -1103,7 +1103,7 @@ run_test("user_settings", ({override}) => {
|
|||
const stub = make_stub();
|
||||
event = event_fixtures.user_settings__web_stream_unreads_count_display_policy;
|
||||
override(stream_list, "update_dom_unread_counts_visibility", stub.f);
|
||||
user_settings.web_stream_unreads_count_display_policy = 1;
|
||||
override(user_settings, "web_stream_unreads_count_display_policy", 1);
|
||||
dispatch(event);
|
||||
assert.equal(stub.num_calls, 1);
|
||||
assert_same(user_settings.web_stream_unreads_count_display_policy, 2);
|
||||
|
@ -1113,7 +1113,7 @@ run_test("user_settings", ({override}) => {
|
|||
const stub = make_stub();
|
||||
event = event_fixtures.user_settings__user_list_style;
|
||||
override(settings_preferences, "report_user_list_style_change", stub.f);
|
||||
user_settings.user_list_style = 1;
|
||||
override(user_settings, "user_list_style", 1);
|
||||
override(activity_ui, "build_user_sidebar", stub.f);
|
||||
dispatch(event);
|
||||
assert.equal(stub.num_calls, 2);
|
||||
|
@ -1121,12 +1121,12 @@ run_test("user_settings", ({override}) => {
|
|||
}
|
||||
|
||||
event = event_fixtures.user_settings__enter_sends;
|
||||
user_settings.enter_sends = false;
|
||||
override(user_settings, "enter_sends", false);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.enter_sends, true);
|
||||
|
||||
event = event_fixtures.user_settings__presence_disabled;
|
||||
user_settings.presence_enabled = true;
|
||||
override(user_settings, "presence_enabled", true);
|
||||
override(activity_ui, "redraw_user", noop);
|
||||
override(settings_account, "update_privacy_settings_box", noop);
|
||||
dispatch(event);
|
||||
|
@ -1153,12 +1153,12 @@ run_test("user_settings", ({override}) => {
|
|||
dispatch(event);
|
||||
|
||||
event = event_fixtures.user_settings__email_address_visibility;
|
||||
user_settings.email_address_visibility = 3;
|
||||
override(user_settings, "email_address_visibility", 3);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.email_address_visibility, 5);
|
||||
|
||||
event = event_fixtures.user_settings__web_navigate_to_sent_message;
|
||||
user_settings.web_navigate_to_sent_message = true;
|
||||
override(user_settings, "web_navigate_to_sent_message", true);
|
||||
dispatch(event);
|
||||
assert_same(user_settings.web_navigate_to_sent_message, false);
|
||||
});
|
||||
|
|
|
@ -6,7 +6,6 @@ const {mock_banners} = require("./lib/compose_banner");
|
|||
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
||||
const {run_test, noop} = require("./lib/test");
|
||||
const $ = require("./lib/zjquery");
|
||||
const {user_settings} = require("./lib/zpage_params");
|
||||
|
||||
const user_pill = mock_esm("../src/user_pill");
|
||||
const messages_overlay_ui = mock_esm("../src/messages_overlay_ui");
|
||||
|
@ -58,7 +57,6 @@ mock_esm("tippy.js", {
|
|||
},
|
||||
delegate: noop,
|
||||
});
|
||||
user_settings.twenty_four_hour_time = false;
|
||||
|
||||
const {localstorage} = zrequire("localstorage");
|
||||
const drafts = zrequire("drafts");
|
||||
|
|
|
@ -232,7 +232,7 @@ function test_helper({override, override_rewire, change_tab}) {
|
|||
|
||||
run_test("hash_interactions", ({override, override_rewire}) => {
|
||||
$window_stub = $.create("window-stub");
|
||||
user_settings.web_home_view = "recent_topics";
|
||||
override(user_settings, "web_home_view", "recent_topics");
|
||||
|
||||
const helper = test_helper({override, override_rewire, change_tab: true});
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ const example_realm_linkifiers = [
|
|||
id: 4,
|
||||
},
|
||||
];
|
||||
user_settings.translate_emoticons = false;
|
||||
|
||||
set_global("document", {compatMode: "CSS1Compat"});
|
||||
|
||||
|
@ -259,7 +258,7 @@ test("markdown_detection", () => {
|
|||
}
|
||||
});
|
||||
|
||||
test("marked_shared", () => {
|
||||
test("marked_shared", ({override}) => {
|
||||
const tests = markdown_test_cases.regular_tests;
|
||||
|
||||
for (const test of tests) {
|
||||
|
@ -270,7 +269,7 @@ test("marked_shared", () => {
|
|||
}
|
||||
|
||||
let message = {raw_content: test.input};
|
||||
user_settings.translate_emoticons = test.translate_emoticons || false;
|
||||
override(user_settings, "translate_emoticons", test.translate_emoticons || false);
|
||||
message = {
|
||||
...message,
|
||||
...markdown.render(message.raw_content),
|
||||
|
@ -320,7 +319,7 @@ test("message_flags", () => {
|
|||
assert.ok(message.flags.includes("topic_wildcard_mentioned"));
|
||||
});
|
||||
|
||||
test("marked", () => {
|
||||
test("marked", ({override}) => {
|
||||
const test_cases = [
|
||||
{input: "hello", expected: "<p>hello</p>"},
|
||||
{input: "hello there", expected: "<p>hello there</p>"},
|
||||
|
@ -633,7 +632,7 @@ test("marked", () => {
|
|||
|
||||
for (const test_case of test_cases) {
|
||||
// Disable emoji conversion by default.
|
||||
user_settings.translate_emoticons = test_case.translate_emoticons || false;
|
||||
override(user_settings, "translate_emoticons", test_case.translate_emoticons || false);
|
||||
|
||||
const input = test_case.input;
|
||||
const expected = test_case.expected;
|
||||
|
|
|
@ -55,18 +55,18 @@ function test(label, f) {
|
|||
run_test(label, (helpers) => {
|
||||
current_user.is_admin = false;
|
||||
page_params.realm_users = [];
|
||||
user_settings.enable_followed_topic_desktop_notifications = true;
|
||||
user_settings.enable_followed_topic_audible_notifications = true;
|
||||
user_settings.enable_desktop_notifications = true;
|
||||
user_settings.enable_sounds = true;
|
||||
user_settings.enable_followed_topic_wildcard_mentions_notify = true;
|
||||
user_settings.wildcard_mentions_notify = true;
|
||||
user_settings.notification_sound = "ding";
|
||||
helpers.override(user_settings, "enable_followed_topic_desktop_notifications", true);
|
||||
helpers.override(user_settings, "enable_followed_topic_audible_notifications", true);
|
||||
helpers.override(user_settings, "enable_desktop_notifications", true);
|
||||
helpers.override(user_settings, "enable_sounds", true);
|
||||
helpers.override(user_settings, "enable_followed_topic_wildcard_mentions_notify", true);
|
||||
helpers.override(user_settings, "wildcard_mentions_notify", true);
|
||||
helpers.override(user_settings, "notification_sound", "ding");
|
||||
f(helpers);
|
||||
});
|
||||
}
|
||||
|
||||
test("message_is_notifiable", () => {
|
||||
test("message_is_notifiable", ({override}) => {
|
||||
// A notification is sent if both message_is_notifiable(message)
|
||||
// and the appropriate should_send_*_notification function return
|
||||
// true.
|
||||
|
@ -150,14 +150,14 @@ test("message_is_notifiable", () => {
|
|||
|
||||
// But not if 'enable_followed_topic_desktop_notifications'
|
||||
// and 'enable_followed_topic_audible_notifications' are disabled.
|
||||
user_settings.enable_followed_topic_desktop_notifications = false;
|
||||
user_settings.enable_followed_topic_audible_notifications = false;
|
||||
override(user_settings, "enable_followed_topic_desktop_notifications", false);
|
||||
override(user_settings, "enable_followed_topic_audible_notifications", false);
|
||||
assert.equal(message_notifications.should_send_desktop_notification(message), false);
|
||||
assert.equal(message_notifications.should_send_audible_notification(message), false);
|
||||
assert.equal(message_notifications.message_is_notifiable(message), true);
|
||||
|
||||
// Reset state
|
||||
user_settings.enable_followed_topic_desktop_notifications = true;
|
||||
override(user_settings, "enable_followed_topic_desktop_notifications", true);
|
||||
|
||||
// Case 5:
|
||||
// Mentioning should trigger notification in unmuted topic
|
||||
|
@ -195,7 +195,7 @@ test("message_is_notifiable", () => {
|
|||
assert.equal(message_notifications.message_is_notifiable(message), true);
|
||||
|
||||
// But not if it's disabled
|
||||
user_settings.wildcard_mentions_notify = false;
|
||||
override(user_settings, "wildcard_mentions_notify", false);
|
||||
assert.equal(message_notifications.should_send_desktop_notification(message), false);
|
||||
assert.equal(message_notifications.should_send_audible_notification(message), false);
|
||||
assert.equal(message_notifications.message_is_notifiable(message), true);
|
||||
|
@ -207,7 +207,7 @@ test("message_is_notifiable", () => {
|
|||
assert.equal(message_notifications.message_is_notifiable(message), true);
|
||||
|
||||
// Reset state
|
||||
user_settings.wildcard_mentions_notify = true;
|
||||
override(user_settings, "wildcard_mentions_notify", true);
|
||||
general.wildcard_mentions_notify = null;
|
||||
|
||||
// Case 7: If a message is in a muted stream
|
||||
|
@ -270,9 +270,9 @@ test("message_is_notifiable", () => {
|
|||
// 'enable_followed_topic_audible_notifications' disabled and
|
||||
// 'enable_followed_topic_wildcard_mentions_notify' enabled;
|
||||
// DO visually and audibly notify the user
|
||||
user_settings.wildcard_mentions_notify = false;
|
||||
user_settings.enable_followed_topic_desktop_notifications = false;
|
||||
user_settings.enable_followed_topic_audible_notifications = false;
|
||||
override(user_settings, "wildcard_mentions_notify", false);
|
||||
override(user_settings, "enable_followed_topic_desktop_notifications", false);
|
||||
override(user_settings, "enable_followed_topic_audible_notifications", false);
|
||||
message = {
|
||||
id: 50,
|
||||
content: "message number 5",
|
||||
|
@ -289,16 +289,16 @@ test("message_is_notifiable", () => {
|
|||
assert.equal(message_notifications.message_is_notifiable(message), true);
|
||||
|
||||
// But not if 'enable_followed_topic_wildcard_mentions_notify' is disabled
|
||||
user_settings.enable_followed_topic_wildcard_mentions_notify = false;
|
||||
override(user_settings, "enable_followed_topic_wildcard_mentions_notify", false);
|
||||
assert.equal(message_notifications.should_send_desktop_notification(message), false);
|
||||
assert.equal(message_notifications.should_send_audible_notification(message), false);
|
||||
assert.equal(message_notifications.message_is_notifiable(message), true);
|
||||
|
||||
// Reset state
|
||||
user_settings.wildcard_mentions_notify = true;
|
||||
user_settings.enable_followed_topic_desktop_notifications = true;
|
||||
user_settings.enable_followed_topic_audible_notifications = true;
|
||||
user_settings.enable_followed_topic_wildcard_mentions_notify = true;
|
||||
override(user_settings, "wildcard_mentions_notify", true);
|
||||
override(user_settings, "enable_followed_topic_desktop_notifications", true);
|
||||
override(user_settings, "enable_followed_topic_audible_notifications", true);
|
||||
override(user_settings, "enable_followed_topic_wildcard_mentions_notify", true);
|
||||
|
||||
// Case 11: If `None` is selected as the notification sound, send no
|
||||
// audible notification, no matter what other user configurations are.
|
||||
|
@ -313,13 +313,13 @@ test("message_is_notifiable", () => {
|
|||
stream_id: general.stream_id,
|
||||
topic: "whatever",
|
||||
};
|
||||
user_settings.notification_sound = "none";
|
||||
override(user_settings, "notification_sound", "none");
|
||||
assert.equal(message_notifications.should_send_desktop_notification(message), true);
|
||||
assert.equal(message_notifications.should_send_audible_notification(message), false);
|
||||
assert.equal(message_notifications.message_is_notifiable(message), true);
|
||||
|
||||
// Reset state
|
||||
user_settings.notification_sound = "ding";
|
||||
override(user_settings, "notification_sound", "ding");
|
||||
|
||||
// If none of the above cases apply
|
||||
// (ie: topic is not muted, message does not mention user,
|
||||
|
|
|
@ -614,19 +614,19 @@ test_people("bot_custom_profile_data", () => {
|
|||
assert.equal(people.get_custom_profile_data(bot_botson.user_id, 3), null);
|
||||
});
|
||||
|
||||
test_people("user_timezone", () => {
|
||||
test_people("user_timezone", ({override}) => {
|
||||
MockDate.set(parseISO("20130208T080910").getTime());
|
||||
|
||||
user_settings.twenty_four_hour_time = true;
|
||||
override(user_settings, "twenty_four_hour_time", true);
|
||||
assert.equal(people.get_user_time(me.user_id), "00:09");
|
||||
|
||||
user_settings.twenty_four_hour_time = false;
|
||||
override(user_settings, "twenty_four_hour_time", false);
|
||||
assert.equal(people.get_user_time(me.user_id), "12:09 AM");
|
||||
});
|
||||
|
||||
test_people("utcToZonedTime", ({override}) => {
|
||||
MockDate.set(parseISO("20130208T080910").getTime());
|
||||
user_settings.twenty_four_hour_time = true;
|
||||
override(user_settings, "twenty_four_hour_time", true);
|
||||
|
||||
assert.deepEqual(people.get_user_time(unknown_user.user_id), undefined);
|
||||
assert.equal(people.get_user_time(me.user_id), "00:09");
|
||||
|
|
|
@ -82,7 +82,7 @@ people.initialize_current_user(me.user_id);
|
|||
function test(label, f) {
|
||||
run_test(label, (helpers) => {
|
||||
realm.server_presence_offline_threshold_seconds = OFFLINE_THRESHOLD_SECS;
|
||||
user_settings.presence_enabled = true;
|
||||
helpers.override(user_settings, "presence_enabled", true);
|
||||
presence.clear_internal_data();
|
||||
f(helpers);
|
||||
});
|
||||
|
|
|
@ -442,32 +442,32 @@ function stub_reaction(message_id, local_id) {
|
|||
return $reaction;
|
||||
}
|
||||
|
||||
test("get_vote_text (more than 3 reactions)", () => {
|
||||
test("get_vote_text (more than 3 reactions)", ({override}) => {
|
||||
const user_ids = [5, 6, 7];
|
||||
const message = {...sample_message};
|
||||
|
||||
user_settings.display_emoji_reaction_users = true;
|
||||
override(user_settings, "display_emoji_reaction_users", true);
|
||||
assert.equal(
|
||||
"translated: You, Bob van Roberts, Cali",
|
||||
reactions.get_vote_text(user_ids, message),
|
||||
);
|
||||
});
|
||||
|
||||
test("get_vote_text (3 reactions)", () => {
|
||||
test("get_vote_text (3 reactions)", ({override}) => {
|
||||
const user_ids = [5, 6, 7];
|
||||
const message = {...sample_message};
|
||||
|
||||
// slicing the reactions array to only include first 3 reactions
|
||||
message.reactions = message.reactions.slice(0, 3);
|
||||
|
||||
user_settings.display_emoji_reaction_users = true;
|
||||
override(user_settings, "display_emoji_reaction_users", true);
|
||||
assert.equal(
|
||||
"translated: You, Bob van Roberts, Cali",
|
||||
reactions.get_vote_text(user_ids, message),
|
||||
);
|
||||
});
|
||||
|
||||
test("update_vote_text_on_message", ({override_rewire}) => {
|
||||
test("update_vote_text_on_message", ({override, override_rewire}) => {
|
||||
// the vote_text in this message is intentionally wrong.
|
||||
// After calling update_vote_text_on_message(), we
|
||||
// will check if the vote_text has been correctly updated.
|
||||
|
@ -500,7 +500,7 @@ test("update_vote_text_on_message", ({override_rewire}) => {
|
|||
};
|
||||
convert_reactions_to_clean_reactions(message);
|
||||
|
||||
user_settings.display_emoji_reaction_users = true;
|
||||
override(user_settings, "display_emoji_reaction_users", true);
|
||||
|
||||
override_rewire(reactions, "find_reaction", noop);
|
||||
override_rewire(reactions, "set_reaction_vote_text", noop);
|
||||
|
@ -580,7 +580,7 @@ test("add_reaction/remove_reaction", ({override, override_rewire}) => {
|
|||
};
|
||||
convert_reactions_to_clean_reactions(message);
|
||||
|
||||
user_settings.display_emoji_reaction_users = true;
|
||||
override(user_settings, "display_emoji_reaction_users", true);
|
||||
|
||||
override(message_store, "get", () => message);
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ mock_cjs("clipboard", Clipboard);
|
|||
|
||||
const realm_playground = mock_esm("../src/realm_playground");
|
||||
const copied_tooltip = mock_esm("../src/copied_tooltip");
|
||||
user_settings.emojiset = "apple";
|
||||
|
||||
const rm = zrequire("rendered_markdown");
|
||||
const people = zrequire("people");
|
||||
|
@ -475,7 +474,7 @@ run_test("timestamp-error", () => {
|
|||
assert.equal($timestamp_error.text(), "translated: Invalid time format: the-time-format");
|
||||
});
|
||||
|
||||
run_test("emoji", () => {
|
||||
run_test("emoji", ({override}) => {
|
||||
// Setup
|
||||
const $content = get_content_element();
|
||||
const $emoji = $.create("emoji-stub");
|
||||
|
@ -488,14 +487,14 @@ run_test("emoji", () => {
|
|||
return {contents: () => ({unwrap() {}})};
|
||||
};
|
||||
$content.set_find_results(".emoji", $emoji);
|
||||
user_settings.emojiset = "text";
|
||||
override(user_settings, "emojiset", "text");
|
||||
|
||||
rm.update_elements($content);
|
||||
|
||||
assert.ok(called);
|
||||
|
||||
// Set page parameters back so that test run order is independent
|
||||
user_settings.emojiset = "apple";
|
||||
override(user_settings, "emojiset", "apple");
|
||||
});
|
||||
|
||||
run_test("spoiler-header", () => {
|
||||
|
|
|
@ -8,20 +8,20 @@ const {user_settings} = require("./lib/zpage_params");
|
|||
|
||||
const settings_config = zrequire("settings_config");
|
||||
|
||||
run_test("all_notifications", () => {
|
||||
user_settings.enable_stream_desktop_notifications = false;
|
||||
user_settings.enable_stream_audible_notifications = true;
|
||||
user_settings.enable_stream_push_notifications = true;
|
||||
user_settings.enable_stream_email_notifications = false;
|
||||
user_settings.enable_desktop_notifications = false;
|
||||
user_settings.enable_sounds = true;
|
||||
user_settings.enable_offline_push_notifications = false;
|
||||
user_settings.enable_offline_email_notifications = true;
|
||||
user_settings.enable_followed_topic_desktop_notifications = false;
|
||||
user_settings.enable_followed_topic_audible_notifications = true;
|
||||
user_settings.enable_followed_topic_push_notifications = false;
|
||||
user_settings.enable_followed_topic_email_notifications = true;
|
||||
user_settings.enable_followed_topic_wildcard_mentions_notify = false;
|
||||
run_test("all_notifications", ({override}) => {
|
||||
override(user_settings, "enable_stream_desktop_notifications", false);
|
||||
override(user_settings, "enable_stream_audible_notifications", true);
|
||||
override(user_settings, "enable_stream_push_notifications", true);
|
||||
override(user_settings, "enable_stream_email_notifications", false);
|
||||
override(user_settings, "enable_desktop_notifications", false);
|
||||
override(user_settings, "enable_sounds", true);
|
||||
override(user_settings, "enable_offline_push_notifications", false);
|
||||
override(user_settings, "enable_offline_email_notifications", true);
|
||||
override(user_settings, "enable_followed_topic_desktop_notifications", false);
|
||||
override(user_settings, "enable_followed_topic_audible_notifications", true);
|
||||
override(user_settings, "enable_followed_topic_push_notifications", false);
|
||||
override(user_settings, "enable_followed_topic_email_notifications", true);
|
||||
override(user_settings, "enable_followed_topic_wildcard_mentions_notify", false);
|
||||
|
||||
// Check that it throws error if incorrect settings name
|
||||
// is passed. In this case, we articulate that with
|
||||
|
@ -38,7 +38,7 @@ run_test("all_notifications", () => {
|
|||
assert.equal(error_name, "TypeError");
|
||||
assert.equal(error_message, "Incorrect setting_name passed: wildcard_mentions_notify");
|
||||
|
||||
user_settings.wildcard_mentions_notify = false;
|
||||
override(user_settings, "wildcard_mentions_notify", false);
|
||||
const notifications = settings_config.all_notifications(user_settings);
|
||||
|
||||
assert.deepEqual(notifications.general_settings, [
|
||||
|
|
|
@ -234,11 +234,11 @@ test_realm_group_settings(
|
|||
settings_data.user_can_delete_own_message,
|
||||
);
|
||||
|
||||
run_test("using_dark_theme", () => {
|
||||
user_settings.color_scheme = settings_config.color_scheme_values.dark.code;
|
||||
run_test("using_dark_theme", ({override}) => {
|
||||
override(user_settings, "color_scheme", settings_config.color_scheme_values.dark.code);
|
||||
assert.equal(settings_data.using_dark_theme(), true);
|
||||
|
||||
user_settings.color_scheme = settings_config.color_scheme_values.automatic.code;
|
||||
override(user_settings, "color_scheme", settings_config.color_scheme_values.automatic.code);
|
||||
|
||||
window.matchMedia = (query) => {
|
||||
assert.equal(query, "(prefers-color-scheme: dark)");
|
||||
|
@ -252,7 +252,7 @@ run_test("using_dark_theme", () => {
|
|||
};
|
||||
assert.equal(settings_data.using_dark_theme(), false);
|
||||
|
||||
user_settings.color_scheme = settings_config.color_scheme_values.light.code;
|
||||
override(user_settings, "color_scheme", settings_config.color_scheme_values.light.code);
|
||||
assert.equal(settings_data.using_dark_theme(), false);
|
||||
});
|
||||
|
||||
|
|
|
@ -90,13 +90,13 @@ run_test("initialize", () => {
|
|||
assert.deepEqual(starred_messages.get_starred_msg_ids(), [4, 5, 6]);
|
||||
});
|
||||
|
||||
run_test("rerender_ui", () => {
|
||||
run_test("rerender_ui", ({override}) => {
|
||||
starred_messages.starred_ids.clear();
|
||||
for (const id of [1, 2, 3]) {
|
||||
starred_messages.starred_ids.add(id);
|
||||
}
|
||||
|
||||
user_settings.starred_message_counts = true;
|
||||
override(user_settings, "starred_message_counts", true);
|
||||
with_overrides(({override}) => {
|
||||
const stub = make_stub();
|
||||
override(left_sidebar_navigation_area, "update_starred_count", stub.f);
|
||||
|
@ -107,7 +107,7 @@ run_test("rerender_ui", () => {
|
|||
assert.equal(args.hidden, false);
|
||||
});
|
||||
|
||||
user_settings.starred_message_counts = false;
|
||||
override(user_settings, "starred_message_counts", false);
|
||||
with_overrides(({override}) => {
|
||||
const stub = make_stub();
|
||||
override(left_sidebar_navigation_area, "update_starred_count", stub.f);
|
||||
|
|
|
@ -582,7 +582,7 @@ test("delete_sub", () => {
|
|||
stream_data.delete_sub(99999);
|
||||
});
|
||||
|
||||
test("notifications", () => {
|
||||
test("notifications", ({override}) => {
|
||||
const india = {
|
||||
stream_id: 102,
|
||||
name: "India",
|
||||
|
@ -601,13 +601,13 @@ test("notifications", () => {
|
|||
assert.ok(!stream_data.receives_notifications(india.stream_id, "desktop_notifications"));
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "audible_notifications"));
|
||||
|
||||
user_settings.enable_stream_desktop_notifications = true;
|
||||
user_settings.enable_stream_audible_notifications = true;
|
||||
override(user_settings, "enable_stream_desktop_notifications", true);
|
||||
override(user_settings, "enable_stream_audible_notifications", true);
|
||||
assert.ok(stream_data.receives_notifications(india.stream_id, "desktop_notifications"));
|
||||
assert.ok(stream_data.receives_notifications(india.stream_id, "audible_notifications"));
|
||||
|
||||
user_settings.enable_stream_desktop_notifications = false;
|
||||
user_settings.enable_stream_audible_notifications = false;
|
||||
override(user_settings, "enable_stream_desktop_notifications", false);
|
||||
override(user_settings, "enable_stream_audible_notifications", false);
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "desktop_notifications"));
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "audible_notifications"));
|
||||
|
||||
|
@ -618,38 +618,38 @@ test("notifications", () => {
|
|||
|
||||
india.desktop_notifications = false;
|
||||
india.audible_notifications = false;
|
||||
user_settings.enable_stream_desktop_notifications = true;
|
||||
user_settings.enable_stream_audible_notifications = true;
|
||||
override(user_settings, "enable_stream_desktop_notifications", true);
|
||||
override(user_settings, "enable_stream_audible_notifications", true);
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "desktop_notifications"));
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "audible_notifications"));
|
||||
|
||||
user_settings.wildcard_mentions_notify = true;
|
||||
override(user_settings, "wildcard_mentions_notify", true);
|
||||
assert.ok(stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify"));
|
||||
user_settings.wildcard_mentions_notify = false;
|
||||
override(user_settings, "wildcard_mentions_notify", false);
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify"));
|
||||
india.wildcard_mentions_notify = true;
|
||||
assert.ok(stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify"));
|
||||
user_settings.wildcard_mentions_notify = true;
|
||||
override(user_settings, "wildcard_mentions_notify", true);
|
||||
india.wildcard_mentions_notify = false;
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify"));
|
||||
|
||||
user_settings.enable_stream_push_notifications = true;
|
||||
override(user_settings, "enable_stream_push_notifications", true);
|
||||
assert.ok(stream_data.receives_notifications(india.stream_id, "push_notifications"));
|
||||
user_settings.enable_stream_push_notifications = false;
|
||||
override(user_settings, "enable_stream_push_notifications", false);
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "push_notifications"));
|
||||
india.push_notifications = true;
|
||||
assert.ok(stream_data.receives_notifications(india.stream_id, "push_notifications"));
|
||||
user_settings.enable_stream_push_notifications = true;
|
||||
override(user_settings, "enable_stream_push_notifications", true);
|
||||
india.push_notifications = false;
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "push_notifications"));
|
||||
|
||||
user_settings.enable_stream_email_notifications = true;
|
||||
override(user_settings, "enable_stream_email_notifications", true);
|
||||
assert.ok(stream_data.receives_notifications(india.stream_id, "email_notifications"));
|
||||
user_settings.enable_stream_email_notifications = false;
|
||||
override(user_settings, "enable_stream_email_notifications", false);
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "email_notifications"));
|
||||
india.email_notifications = true;
|
||||
assert.ok(stream_data.receives_notifications(india.stream_id, "email_notifications"));
|
||||
user_settings.enable_stream_email_notifications = true;
|
||||
override(user_settings, "enable_stream_email_notifications", true);
|
||||
india.email_notifications = false;
|
||||
assert.ok(!stream_data.receives_notifications(india.stream_id, "email_notifications"));
|
||||
|
||||
|
@ -680,11 +680,11 @@ test("notifications", () => {
|
|||
};
|
||||
stream_data.add_sub(antarctica);
|
||||
|
||||
user_settings.enable_stream_desktop_notifications = true;
|
||||
user_settings.enable_stream_audible_notifications = true;
|
||||
user_settings.enable_stream_email_notifications = false;
|
||||
user_settings.enable_stream_push_notifications = false;
|
||||
user_settings.wildcard_mentions_notify = true;
|
||||
override(user_settings, "enable_stream_desktop_notifications", true);
|
||||
override(user_settings, "enable_stream_audible_notifications", true);
|
||||
override(user_settings, "enable_stream_email_notifications", false);
|
||||
override(user_settings, "enable_stream_push_notifications", false);
|
||||
override(user_settings, "wildcard_mentions_notify", true);
|
||||
|
||||
india.desktop_notifications = null;
|
||||
india.audible_notifications = true;
|
||||
|
|
|
@ -126,10 +126,10 @@ function test_ui(label, f) {
|
|||
});
|
||||
}
|
||||
|
||||
test_ui("create_sidebar_row", ({override_rewire, mock_template}) => {
|
||||
test_ui("create_sidebar_row", ({override, override_rewire, mock_template}) => {
|
||||
// Make a couple calls to create_sidebar_row() and make sure they
|
||||
// generate the right markup as well as play nice with get_stream_li().
|
||||
user_settings.demote_inactive_streams = 1;
|
||||
override(user_settings, "demote_inactive_streams", 1);
|
||||
|
||||
stream_data.add_sub(devel);
|
||||
stream_data.add_sub(social);
|
||||
|
@ -645,8 +645,8 @@ test_ui("separators_only_pinned", () => {
|
|||
assert.deepEqual(appended_elems, expected_elems);
|
||||
});
|
||||
|
||||
test_ui("rename_stream", ({mock_template}) => {
|
||||
user_settings.web_stream_unreads_count_display_policy = 3;
|
||||
test_ui("rename_stream", ({mock_template, override}) => {
|
||||
override(user_settings, "web_stream_unreads_count_display_policy", 3);
|
||||
|
||||
create_stream_subheader({mock_template});
|
||||
initialize_stream_data();
|
||||
|
@ -726,7 +726,7 @@ test_ui("refresh_pin", ({override, override_rewire, mock_template}) => {
|
|||
});
|
||||
|
||||
test_ui("create_initial_sidebar_rows", ({override, override_rewire, mock_template}) => {
|
||||
user_settings.web_stream_unreads_count_display_policy = 2; // Test coverage for this setting.
|
||||
override(user_settings, "web_stream_unreads_count_display_policy", 2); // Test coverage for this setting.
|
||||
initialize_stream_data();
|
||||
|
||||
const html_dict = new Map();
|
||||
|
|
|
@ -196,15 +196,18 @@ test("basics", ({override_rewire}) => {
|
|||
assert.deepEqual(sorted.dormant_streams, []);
|
||||
});
|
||||
|
||||
test("has_recent_activity", () => {
|
||||
test("has_recent_activity", ({override}) => {
|
||||
people.init();
|
||||
people.add_active_user(me);
|
||||
people.initialize_current_user(me.user_id);
|
||||
|
||||
let sub;
|
||||
|
||||
user_settings.demote_inactive_streams =
|
||||
settings_config.demote_inactive_streams_values.automatic.code;
|
||||
override(
|
||||
user_settings,
|
||||
"demote_inactive_streams",
|
||||
settings_config.demote_inactive_streams_values.automatic.code,
|
||||
);
|
||||
|
||||
stream_list_sort.set_filter_out_inactives();
|
||||
|
||||
|
@ -235,8 +238,11 @@ test("has_recent_activity", () => {
|
|||
|
||||
assert.ok(stream_list_sort.has_recent_activity(sub));
|
||||
|
||||
user_settings.demote_inactive_streams =
|
||||
settings_config.demote_inactive_streams_values.always.code;
|
||||
override(
|
||||
user_settings,
|
||||
"demote_inactive_streams",
|
||||
settings_config.demote_inactive_streams_values.always.code,
|
||||
);
|
||||
|
||||
stream_list_sort.set_filter_out_inactives();
|
||||
|
||||
|
@ -264,8 +270,11 @@ test("has_recent_activity", () => {
|
|||
|
||||
assert.ok(stream_list_sort.has_recent_activity(sub));
|
||||
|
||||
user_settings.demote_inactive_streams =
|
||||
settings_config.demote_inactive_streams_values.never.code;
|
||||
override(
|
||||
user_settings,
|
||||
"demote_inactive_streams",
|
||||
settings_config.demote_inactive_streams_values.never.code,
|
||||
);
|
||||
|
||||
stream_list_sort.set_filter_out_inactives();
|
||||
|
||||
|
@ -294,9 +303,12 @@ test("has_recent_activity_but_muted", () => {
|
|||
assert.ok(stream_list_sort.has_recent_activity_but_muted(sub));
|
||||
});
|
||||
|
||||
test("filter inactives", () => {
|
||||
user_settings.demote_inactive_streams =
|
||||
settings_config.demote_inactive_streams_values.automatic.code;
|
||||
test("filter inactives", ({override}) => {
|
||||
override(
|
||||
user_settings,
|
||||
"demote_inactive_streams",
|
||||
settings_config.demote_inactive_streams_values.automatic.code,
|
||||
);
|
||||
|
||||
assert.ok(!stream_list_sort.is_filtering_inactives());
|
||||
|
||||
|
@ -317,8 +329,8 @@ test("filter inactives", () => {
|
|||
assert.ok(stream_list_sort.is_filtering_inactives());
|
||||
});
|
||||
|
||||
test("initialize", () => {
|
||||
user_settings.demote_inactive_streams = 1;
|
||||
test("initialize", ({override}) => {
|
||||
override(user_settings, "demote_inactive_streams", 1);
|
||||
stream_list_sort.initialize();
|
||||
|
||||
assert.ok(!stream_list_sort.is_filtering_inactives());
|
||||
|
|
|
@ -11,8 +11,6 @@ const {run_test} = require("./lib/test");
|
|||
const $ = require("./lib/zjquery");
|
||||
const {user_settings} = require("./lib/zpage_params");
|
||||
|
||||
user_settings.twenty_four_hour_time = true;
|
||||
|
||||
const timerender = zrequire("timerender");
|
||||
|
||||
function get_date(time_ISO, DOW) {
|
||||
|
@ -35,18 +33,21 @@ const date_2021 = get_date("2021-01-27T01:53:08.000Z", "Wednesday");
|
|||
|
||||
const date_2025 = get_date("2025-03-03T12:10:00.000Z", "Monday");
|
||||
|
||||
run_test("get_localized_date_or_time_for_format returns default date with incorrect locale", () => {
|
||||
const date = date_2019;
|
||||
const expectedDate = "Friday, April 12, 2019";
|
||||
run_test(
|
||||
"get_localized_date_or_time_for_format returns default date with incorrect locale",
|
||||
({override}) => {
|
||||
const date = date_2019;
|
||||
const expectedDate = "Friday, April 12, 2019";
|
||||
|
||||
user_settings.default_language = "invalid";
|
||||
const actualDate = timerender.get_localized_date_or_time_for_format(
|
||||
date,
|
||||
"weekday_dayofyear_year",
|
||||
);
|
||||
override(user_settings, "default_language", "invalid");
|
||||
const actualDate = timerender.get_localized_date_or_time_for_format(
|
||||
date,
|
||||
"weekday_dayofyear_year",
|
||||
);
|
||||
|
||||
assert.equal(actualDate, expectedDate);
|
||||
});
|
||||
assert.equal(actualDate, expectedDate);
|
||||
},
|
||||
);
|
||||
|
||||
run_test("get_localized_date_or_time_for_format returns correct format", () => {
|
||||
const date = date_2021;
|
||||
|
@ -119,7 +120,7 @@ run_test("get_localized_date_or_time_for_format returns correct format", () => {
|
|||
}
|
||||
});
|
||||
|
||||
run_test("get_localized_date_or_time_for_format returns correct localized date", () => {
|
||||
run_test("get_localized_date_or_time_for_format returns correct localized date", ({override}) => {
|
||||
const date = add(date_2019, {years: -1});
|
||||
const languages = [
|
||||
{
|
||||
|
@ -161,7 +162,7 @@ run_test("get_localized_date_or_time_for_format returns correct localized date",
|
|||
];
|
||||
|
||||
for (const language of languages) {
|
||||
user_settings.default_language = language.language;
|
||||
override(user_settings, "default_language", language.language);
|
||||
const actualDate = timerender.get_localized_date_or_time_for_format(
|
||||
date,
|
||||
"weekday_dayofyear_year",
|
||||
|
@ -398,8 +399,8 @@ run_test("get_timestamp_for_flatpickr", () => {
|
|||
MockDate.reset();
|
||||
});
|
||||
|
||||
run_test("absolute_time_12_hour", () => {
|
||||
user_settings.twenty_four_hour_time = false;
|
||||
run_test("absolute_time_12_hour", ({override}) => {
|
||||
override(user_settings, "twenty_four_hour_time", false);
|
||||
|
||||
// timestamp with hour > 12, same year
|
||||
let timestamp = date_2019.getTime();
|
||||
|
@ -436,8 +437,8 @@ run_test("absolute_time_12_hour", () => {
|
|||
MockDate.reset();
|
||||
});
|
||||
|
||||
run_test("absolute_time_24_hour", () => {
|
||||
user_settings.twenty_four_hour_time = true;
|
||||
run_test("absolute_time_24_hour", ({override}) => {
|
||||
override(user_settings, "twenty_four_hour_time", true);
|
||||
|
||||
// date with hour > 12, same year
|
||||
let today = date_2019;
|
||||
|
@ -470,7 +471,7 @@ run_test("absolute_time_24_hour", () => {
|
|||
MockDate.reset();
|
||||
});
|
||||
|
||||
run_test("get_full_datetime", () => {
|
||||
run_test("get_full_datetime", ({override}) => {
|
||||
const time = date_2017_PM;
|
||||
|
||||
let expected = "translated: 5/18/2017 at 9:12:53 PM UTC";
|
||||
|
@ -484,13 +485,13 @@ run_test("get_full_datetime", () => {
|
|||
assert.equal(timerender.get_full_datetime(time, "time"), expected);
|
||||
|
||||
// test 24 hour time setting.
|
||||
user_settings.twenty_four_hour_time = true;
|
||||
override(user_settings, "twenty_four_hour_time", true);
|
||||
expected = "translated: 5/18/2017 at 21:12:53 UTC";
|
||||
assert.equal(timerender.get_full_datetime_clarification(time), expected);
|
||||
expected = "translated: May 18, 2017 at 21:12:53";
|
||||
assert.equal(timerender.get_full_datetime(time), expected);
|
||||
|
||||
user_settings.twenty_four_hour_time = false;
|
||||
override(user_settings, "twenty_four_hour_time", false);
|
||||
|
||||
// Test the GMT[+-]x:y logic.
|
||||
timerender.set_display_time_zone("Asia/Kolkata");
|
||||
|
@ -615,21 +616,21 @@ run_test("relative_time_string_from_date", () => {
|
|||
MockDate.reset();
|
||||
});
|
||||
|
||||
run_test("set_full_datetime", () => {
|
||||
run_test("set_full_datetime", ({override}) => {
|
||||
let time = date_2019;
|
||||
|
||||
user_settings.twenty_four_hour_time = true;
|
||||
override(user_settings, "twenty_four_hour_time", true);
|
||||
let time_str = timerender.stringify_time(time);
|
||||
let expected = "17:52";
|
||||
assert.equal(time_str, expected);
|
||||
|
||||
user_settings.twenty_four_hour_time = false;
|
||||
override(user_settings, "twenty_four_hour_time", false);
|
||||
time_str = timerender.stringify_time(time);
|
||||
expected = "5:52 PM";
|
||||
assert.equal(time_str, expected);
|
||||
|
||||
time = add(time, {hours: -7}); // time between 1 to 12 o'clock time.
|
||||
user_settings.twenty_four_hour_time = false;
|
||||
override(user_settings, "twenty_four_hour_time", false);
|
||||
time_str = timerender.stringify_time(time);
|
||||
expected = "10:52 AM";
|
||||
assert.equal(time_str, expected);
|
||||
|
|
|
@ -4,7 +4,7 @@ const assert = require("node:assert/strict");
|
|||
|
||||
const _ = require("lodash");
|
||||
|
||||
const {zrequire, set_global} = require("./lib/namespace");
|
||||
const {set_global, with_overrides, zrequire} = require("./lib/namespace");
|
||||
const {run_test} = require("./lib/test");
|
||||
const {realm, user_settings} = require("./lib/zpage_params");
|
||||
|
||||
|
@ -51,18 +51,20 @@ function assert_zero_counts(counts) {
|
|||
}
|
||||
|
||||
function test_notifiable_count(home_unread_messages, expected_notifiable_count) {
|
||||
user_settings.desktop_icon_count_display = 1;
|
||||
let notifiable_counts = unread.get_notifiable_count();
|
||||
assert.deepEqual(notifiable_counts, home_unread_messages);
|
||||
user_settings.desktop_icon_count_display = 2;
|
||||
notifiable_counts = unread.get_notifiable_count();
|
||||
assert.deepEqual(notifiable_counts, expected_notifiable_count);
|
||||
user_settings.desktop_icon_count_display = 3;
|
||||
notifiable_counts = unread.get_notifiable_count();
|
||||
assert.deepEqual(notifiable_counts, expected_notifiable_count);
|
||||
user_settings.desktop_icon_count_display = 4;
|
||||
notifiable_counts = unread.get_notifiable_count();
|
||||
assert.deepEqual(notifiable_counts, 0);
|
||||
with_overrides(({override}) => {
|
||||
override(user_settings, "desktop_icon_count_display", 1);
|
||||
let notifiable_counts = unread.get_notifiable_count();
|
||||
assert.deepEqual(notifiable_counts, home_unread_messages);
|
||||
override(user_settings, "desktop_icon_count_display", 2);
|
||||
notifiable_counts = unread.get_notifiable_count();
|
||||
assert.deepEqual(notifiable_counts, expected_notifiable_count);
|
||||
override(user_settings, "desktop_icon_count_display", 3);
|
||||
notifiable_counts = unread.get_notifiable_count();
|
||||
assert.deepEqual(notifiable_counts, expected_notifiable_count);
|
||||
override(user_settings, "desktop_icon_count_display", 4);
|
||||
notifiable_counts = unread.get_notifiable_count();
|
||||
assert.deepEqual(notifiable_counts, 0);
|
||||
});
|
||||
}
|
||||
|
||||
function test(label, f) {
|
||||
|
|
Loading…
Reference in New Issue