node tests: Use array syntax more aggressively.

This commit is contained in:
Steve Howell 2021-02-23 13:37:26 +00:00 committed by Steve Howell
parent 2262f79cc8
commit 1a241cef88
48 changed files with 447 additions and 753 deletions

View File

@ -258,14 +258,14 @@ test_ui("presence_list_full_update", () => {
});
function simulate_right_column_buddy_list() {
$(".user-list-filter").closest = function (selector) {
$(".user-list-filter").closest = (selector) => {
assert.equal(selector, ".app-main [class^='column-']");
return $.create("right-sidebar").addClass("column-right");
};
}
function simulate_left_column_buddy_list() {
$(".user-list-filter").closest = function (selector) {
$(".user-list-filter").closest = (selector) => {
assert.equal(selector, ".app-main [class^='column-']");
return $.create("left-sidebar").addClass("column-left");
};
@ -605,7 +605,7 @@ test_ui("toggle_filter_display", () => {
activity.user_filter.toggle_filter_displayed();
assert($("#user_search_section").hasClass("notdisplayed"));
$(".user-list-filter").closest = function (selector) {
$(".user-list-filter").closest = (selector) => {
assert.equal(selector, ".app-main [class^='column-']");
return $.create("sidebar").addClass("column-right");
};
@ -667,7 +667,7 @@ test_ui("initialize", () => {
clear();
channel.post = function (payload) {
channel.post = (payload) => {
payload.success({});
};
set_global("server_events", {
@ -690,10 +690,10 @@ test_ui("initialize", () => {
assert(!activity.new_user_input);
assert(!$("#zephyr-mirror-error").hasClass("show"));
assert(activity.client_is_active);
$(window).idle = function (params) {
$(window).idle = (params) => {
params.onIdle();
};
channel.post = function (payload) {
channel.post = (payload) => {
payload.success({
zephyr_mirror_active: false,
presences: {},

View File

@ -54,26 +54,26 @@ run_test("create_ajax_request", (override) => {
make_indicator: 0,
};
loading.make_indicator = function (loading_indicator, config) {
loading.make_indicator = (loading_indicator, config) => {
assert.equal(loading_indicator.selector, form_loading_indicator);
assert.equal(config.text, "Processing ...");
assert.equal(config.abs_positioned, true);
state.make_indicator += 1;
};
$(form_input_section).hide = function () {
$(form_input_section).hide = () => {
state.form_input_section_hide += 1;
};
$(form_input_section).show = function () {
$(form_input_section).show = () => {
state.form_input_section_show += 1;
};
$(form_error).hide = function () {
$(form_error).hide = () => {
state.form_error_hide += 1;
};
$(form_error).show = function () {
$(form_error).show = () => {
state.form_error_show += 1;
return {
text: (msg) => {
@ -82,15 +82,15 @@ run_test("create_ajax_request", (override) => {
};
};
$(form_success).show = function () {
$(form_success).show = () => {
state.form_success_show += 1;
};
$(form_loading).show = function () {
$(form_loading).show = () => {
state.form_loading_show += 1;
};
$(form_loading).hide = function () {
$(form_loading).hide = () => {
state.form_loading_hide += 1;
};

View File

@ -20,16 +20,16 @@ function test_with_mock_ajax(test_params) {
let ajax_called;
let ajax_options;
$.ajax = function (options) {
$.ajax = (options) => {
$.ajax = undefined;
ajax_called = true;
ajax_options = options;
options.simulate_success = function (data, text_status) {
options.simulate_success = (data, text_status) => {
options.success(data, text_status, xhr);
};
options.simulate_error = function () {
options.simulate_error = () => {
options.error(xhr);
};
@ -216,7 +216,7 @@ run_test("reload_on_403_error", () => {
check_ajax_options(options) {
let reload_initiated;
reload.initiate = function (options) {
reload.initiate = (options) => {
reload_initiated = true;
assert.deepEqual(options, {
immediate: true,
@ -280,7 +280,7 @@ run_test("retry", () => {
});
run_test("too_many_pending", () => {
$.ajax = function () {
$.ajax = () => {
const xhr = "stub";
return xhr;
};

View File

@ -65,9 +65,7 @@ run_test("copy_data_attribute_value", (override) => {
});
run_test("adjust_mac_shortcuts non-mac", () => {
common.has_mac_keyboard = function () {
return false;
};
common.has_mac_keyboard = () => false;
// The adjust_mac_shortcuts has a really simple guard
// at the top, and we just test the early-return behavior
@ -91,9 +89,7 @@ run_test("adjust_mac_shortcuts mac", () => {
["Ctrl + Backspace + End", "⌘ + Delete + Fn + →"],
]);
common.has_mac_keyboard = function () {
return true;
};
common.has_mac_keyboard = () => true;
const test_items = [];
let key_no = 1;

View File

@ -10,7 +10,7 @@ const {run_test} = require("../zjsunit/test");
zrequire("keydown_util");
const components = zrequire("components");
const noop = function () {};
const noop = () => {};
const LEFT_KEY = {which: 37, preventDefault: noop, stopPropagation: noop};
const RIGHT_KEY = {which: 39, preventDefault: noop, stopPropagation: noop};
@ -30,28 +30,28 @@ run_test("basics", () => {
self.stub = true;
self.class = [];
self.addClass = function (c) {
self.addClass = (c) => {
self.class += " " + c;
const tokens = self.class.trim().split(/ +/);
self.class = _.uniq(tokens).join(" ");
};
self.removeClass = function (c) {
self.removeClass = (c) => {
const tokens = self.class.trim().split(/ +/);
self.class = _.without(tokens, c).join(" ");
};
self.hasClass = function (c) {
self.hasClass = (c) => {
const tokens = self.class.trim().split(/ +/);
return tokens.includes(c);
};
self.data = function (name) {
self.data = (name) => {
assert.equal(name, "tab-id");
return i;
};
self.text = function (text) {
self.text = (text) => {
assert.equal(
text,
[
@ -62,7 +62,7 @@ run_test("basics", () => {
);
};
self.trigger = function (type) {
self.trigger = (type) => {
if (type === "focus") {
focused_tab = i;
}
@ -78,7 +78,7 @@ run_test("basics", () => {
self.stub = true;
self.on = function (name, f) {
self.on = (name, f) => {
if (name === "click") {
click_f = f;
} else if (name === "keydown") {
@ -86,15 +86,13 @@ run_test("basics", () => {
}
};
self.removeClass = function (c) {
self.removeClass = (c) => {
for (const tab of tabs) {
tab.removeClass(c);
}
};
self.eq = function (idx) {
return tabs[idx];
};
self.eq = (idx) => tabs[idx];
return self;
})();
@ -108,16 +106,16 @@ run_test("basics", () => {
self.classList = new Set();
self.append = function (child) {
self.append = (child) => {
self.children.push(child);
};
self.addClass = function (c) {
self.addClass = (c) => {
self.classList.add(c);
self.addedClass = c;
};
self.find = function (sel) {
self.find = (sel) => {
switch (sel) {
case ".ind-tab":
return ind_tab;

View File

@ -15,7 +15,7 @@ const events = require("./lib/events");
set_global("bridge", false);
const noop = function () {};
const noop = () => {};
set_global("DOMParser", new JSDOM().window.DOMParser);
set_global("compose_actions", {
@ -95,9 +95,7 @@ const upload = zrequire("upload");
const server_events_dispatch = zrequire("server_events_dispatch");
const settings_config = zrequire("settings_config");
people.small_avatar_url_for_person = function () {
return "http://example.com/example.png";
};
people.small_avatar_url_for_person = () => "http://example.com/example.png";
function stub_out_video_calls() {
const elem = $("#below-compose-content .video_link");
@ -172,7 +170,7 @@ test_ui("validate_stream_message_address_info", () => {
assert.equal($("#compose-error-msg").html(), "compose_not_subscribed_stub");
page_params.narrow_stream = false;
channel.post = function (payload) {
channel.post = (payload) => {
assert.equal(payload.data.stream, "social");
payload.data.subscribed = true;
payload.success(payload.data);
@ -182,7 +180,7 @@ test_ui("validate_stream_message_address_info", () => {
sub.name = "Frontend";
sub.stream_id = 102;
stream_data.add_sub(sub);
channel.post = function (payload) {
channel.post = (payload) => {
assert.equal(payload.data.stream, "Frontend");
payload.data.subscribed = false;
payload.success(payload.data);
@ -190,7 +188,7 @@ test_ui("validate_stream_message_address_info", () => {
assert(!compose.validate_stream_message_address_info("Frontend"));
assert.equal($("#compose-error-msg").html(), "compose_not_subscribed_stub");
channel.post = function (payload) {
channel.post = (payload) => {
assert.equal(payload.data.stream, "Frontend");
payload.error({status: 404});
};
@ -200,7 +198,7 @@ test_ui("validate_stream_message_address_info", () => {
"translated: <p>The stream <b>Frontend</b> does not exist.</p><p>Manage your subscriptions <a href='#streams/all'>on your Streams page</a>.</p>",
);
channel.post = function (payload) {
channel.post = (payload) => {
assert.equal(payload.data.stream, "social");
payload.error({status: 500});
};
@ -252,7 +250,7 @@ test_ui("validate", () => {
add_content_to_compose_box();
let zephyr_checked = false;
$("#zephyr-mirror-error").is = function () {
$("#zephyr-mirror-error").is = () => {
if (!zephyr_checked) {
zephyr_checked = true;
return true;
@ -397,7 +395,7 @@ test_ui("validate_stream_message", () => {
assert(!$("#compose-all-everyone").visible());
assert(!$("#compose-send-status").visible());
peer_data.get_subscriber_count = function (stream_id) {
peer_data.get_subscriber_count = (stream_id) => {
assert.equal(stream_id, 101);
return 16;
};
@ -407,13 +405,11 @@ test_ui("validate_stream_message", () => {
return "compose_all_everyone_stub";
});
let compose_content;
$("#compose-all-everyone").append = function (data) {
$("#compose-all-everyone").append = (data) => {
compose_content = data;
};
compose.wildcard_mention_allowed = function () {
return true;
};
compose.wildcard_mention_allowed = () => true;
compose_state.message_content("Hey @**all**");
assert(!compose.validate());
assert.equal($("#compose-send-button").prop("disabled"), false);
@ -421,9 +417,7 @@ test_ui("validate_stream_message", () => {
assert.equal(compose_content, "compose_all_everyone_stub");
assert($("#compose-all-everyone").visible());
compose.wildcard_mention_allowed = function () {
return false;
};
compose.wildcard_mention_allowed = () => false;
assert(!compose.validate());
assert.equal(
$("#compose-error-msg").html(),
@ -548,10 +542,8 @@ test_ui("markdown_shortcuts", () => {
let compose_value = $("#compose_textarea").val();
let selected_word = "";
document.queryCommandEnabled = function () {
return queryCommandEnabled;
};
document.execCommand = function (cmd, bool, markdown) {
document.queryCommandEnabled = () => queryCommandEnabled;
document.execCommand = (cmd, bool, markdown) => {
const compose_textarea = $("#compose-textarea");
const value = compose_textarea.val();
$("#compose-textarea").val(
@ -562,17 +554,15 @@ test_ui("markdown_shortcuts", () => {
};
$("#compose-textarea")[0] = {};
$("#compose-textarea").range = function () {
return {
start: range_start,
end: range_start + range_length,
length: range_length,
range: noop,
text: $("#compose-textarea")
.val()
.slice(range_start, range_length + range_start),
};
};
$("#compose-textarea").range = () => ({
start: range_start,
end: range_start + range_length,
length: range_length,
range: noop,
text: $("#compose-textarea")
.val()
.slice(range_start, range_length + range_start),
});
$("#compose-textarea").caret = noop;
function test_i_typed(isCtrl, isCmd) {
@ -704,7 +694,7 @@ test_ui("send_message_success", () => {
$("#sending-indicator").show();
let reify_message_id_checked;
echo.reify_message_id = function (local_id, message_id) {
echo.reify_message_id = (local_id, message_id) => {
assert.equal(local_id, "1001");
assert.equal(message_id, 12);
reify_message_id_checked = true;
@ -747,9 +737,7 @@ test_ui("send_message", () => {
compose_state.topic("");
compose_state.set_message_type("private");
page_params.user_id = 101;
compose_state.private_message_recipient = function () {
return "alice@example.com";
};
compose_state.private_message_recipient = () => "alice@example.com";
const server_message_id = 127;
local_message.insert_message = (message) => {
@ -759,11 +747,11 @@ test_ui("send_message", () => {
markdown.apply_markdown = () => {};
markdown.add_topic_links = () => {};
echo.try_deliver_locally = function (message_request) {
echo.try_deliver_locally = (message_request) => {
const local_id_float = 123.04;
return echo.insert_local_message(message_request, local_id_float);
};
transmit.send_message = function (payload, success) {
transmit.send_message = (payload, success) => {
const single_msg = {
type: "private",
content: "[foobar](/user_uploads/123456)",
@ -784,7 +772,7 @@ test_ui("send_message", () => {
success(payload);
stub_state.send_msg_called += 1;
};
echo.reify_message_id = function (local_id, message_id) {
echo.reify_message_id = (local_id, message_id) => {
assert.equal(typeof local_id, "string");
assert.equal(typeof message_id, "number");
assert.equal(message_id, server_message_id);
@ -815,14 +803,14 @@ test_ui("send_message", () => {
})();
// This is the additional setup which is common to both the tests below.
transmit.send_message = function (payload, success, error) {
transmit.send_message = (payload, success, error) => {
stub_state.send_msg_called += 1;
error("Error sending message: Server says 408");
};
let echo_error_msg_checked;
echo.message_send_error = function (local_id, error_response) {
echo.message_send_error = (local_id, error_response) => {
assert.equal(local_id, 123.04);
assert.equal(error_response, "Error sending message: Server says 408");
echo_error_msg_checked = true;
@ -852,13 +840,9 @@ test_ui("send_message", () => {
$("#sending-indicator").show();
$("#compose-textarea").off("select");
echo_error_msg_checked = false;
echo.try_deliver_locally = function () {
return;
};
echo.try_deliver_locally = () => {};
sent_messages.get_new_local_id = function () {
return "loc-55";
};
sent_messages.get_new_local_id = () => "loc-55";
compose.send_message();
@ -891,7 +875,7 @@ test_ui("enter_with_preview_open", () => {
$("#markdown_preview").hide();
page_params.enter_sends = true;
let send_message_called = false;
compose.send_message = function () {
compose.send_message = () => {
send_message_called = true;
};
compose.enter_with_preview_open();
@ -942,16 +926,14 @@ test_ui("finish", () => {
$("#markdown_preview").hide();
$("#compose-textarea").val("foobarfoobar");
compose_state.set_message_type("private");
compose_state.private_message_recipient = function () {
return "bob@example.com";
};
compose_state.private_message_recipient = () => "bob@example.com";
let compose_finished_event_checked = false;
$(document).on("compose_finished.zulip", () => {
compose_finished_event_checked = true;
});
let send_message_called = false;
compose.send_message = function () {
compose.send_message = () => {
send_message_called = true;
};
assert(compose.finish());
@ -1012,7 +994,7 @@ test_ui("warn_if_private_stream_is_linked", () => {
(function () {
let called;
$("#compose_private_stream_alert").append = function (html) {
$("#compose_private_stream_alert").append = (html) => {
called = true;
assert.equal(html, "fake-compose_private_stream_alert-template");
};
@ -1043,7 +1025,7 @@ test_ui("initialize", () => {
// done in subsequent tests directly below this test.
let resize_watch_manual_resize_checked = false;
resize.watch_manual_resize = function (elem) {
resize.watch_manual_resize = (elem) => {
assert.equal("#compose-textarea", elem);
resize_watch_manual_resize_checked = true;
};
@ -1062,7 +1044,7 @@ test_ui("initialize", () => {
let setup_upload_called = false;
let uppy_cancel_all_called = false;
upload.setup_upload = function (config) {
upload.setup_upload = (config) => {
assert.equal(config.mode, "compose");
setup_upload_called = true;
return {
@ -1191,7 +1173,7 @@ test_ui("trigger_submit_compose_form", () => {
prevent_default_checked = true;
},
};
compose.finish = function () {
compose.finish = () => {
compose_finish_checked = true;
};
@ -1282,7 +1264,7 @@ test_ui("warn_if_mentioning_unsubscribed_user", () => {
const checks = [
(function () {
let called;
compose.needs_subscribe_warning = function (user_id, stream_id) {
compose.needs_subscribe_warning = (user_id, stream_id) => {
called = true;
assert.equal(user_id, 34);
assert.equal(stream_id, 111);
@ -1310,7 +1292,7 @@ test_ui("warn_if_mentioning_unsubscribed_user", () => {
(function () {
let called;
$("#compose_invite_users").append = function (html) {
$("#compose_invite_users").append = (html) => {
called = true;
assert.equal(html, "fake-compose-invite-user-template");
};
@ -1338,7 +1320,7 @@ test_ui("warn_if_mentioning_unsubscribed_user", () => {
const warning_row = $("<warning row>");
let looked_for_existing;
warning_row.data = function (field) {
warning_row.data = (field) => {
if (field === "user-id") {
looked_for_existing = true;
return "34";
@ -1367,7 +1349,7 @@ test_ui("on_events", () => {
const container = $.create("fake " + container_sel);
let container_removed = false;
container.remove = function () {
container.remove = () => {
container_removed = true;
};
@ -1406,7 +1388,7 @@ test_ui("on_events", () => {
$("#compose-send-status").show();
let compose_finish_checked = false;
compose.finish = function () {
compose.finish = () => {
compose_finish_checked = true;
};
@ -1432,7 +1414,7 @@ test_ui("on_events", () => {
};
people.add_active_user(mentioned);
let invite_user_to_stream_called = false;
stream_edit.invite_user_to_stream = function (user_ids, sub, success) {
stream_edit.invite_user_to_stream = (user_ids, sub, success) => {
invite_user_to_stream_called = true;
assert.deepEqual(user_ids, [mentioned.user_id]);
assert.equal(sub, subscription);
@ -1445,7 +1427,7 @@ test_ui("on_events", () => {
".compose_invite_user",
);
helper.container.data = function (field) {
helper.container.data = (field) => {
if (field === "user-id") {
return "34";
}
@ -1460,7 +1442,7 @@ test_ui("on_events", () => {
stream_data.add_sub(subscription);
$("#stream_message_recipient_stream").val("test");
let all_invite_children_called = false;
$("#compose_invite_users").children = function () {
$("#compose_invite_users").children = () => {
all_invite_children_called = true;
return [];
};
@ -1484,7 +1466,7 @@ test_ui("on_events", () => {
);
let all_invite_children_called = false;
$("#compose_invite_users").children = function () {
$("#compose_invite_users").children = () => {
all_invite_children_called = true;
return [];
};
@ -1505,7 +1487,7 @@ test_ui("on_events", () => {
subscribed: false,
};
let compose_not_subscribed_called = false;
subs.sub_or_unsub = function () {
subs.sub_or_unsub = () => {
compose_not_subscribed_called = true;
};
@ -1549,7 +1531,7 @@ test_ui("on_events", () => {
(function test_attach_files_compose_clicked() {
const handler = $("#compose").get_on_handler("click", "#attach_files");
$("#file_input").clone = function (param) {
$("#file_input").clone = (param) => {
assert(param);
};
let compose_file_input_clicked = false;
@ -1577,7 +1559,7 @@ test_ui("on_events", () => {
},
};
compose_ui.insert_syntax_and_focus = function () {
compose_ui.insert_syntax_and_focus = () => {
called = true;
};
@ -1601,7 +1583,7 @@ test_ui("on_events", () => {
},
};
compose_ui.insert_syntax_and_focus = function (syntax) {
compose_ui.insert_syntax_and_focus = (syntax) => {
syntax_to_insert = syntax;
called = true;
};
@ -1637,7 +1619,7 @@ test_ui("on_events", () => {
},
};
compose_ui.insert_syntax_and_focus = function (syntax) {
compose_ui.insert_syntax_and_focus = (syntax) => {
syntax_to_insert = syntax;
called = true;
};
@ -1649,7 +1631,7 @@ test_ui("on_events", () => {
page_params.realm_available_video_chat_providers.zoom.id;
page_params.has_zoom_token = false;
window.open = function (url) {
window.open = (url) => {
assert(url.endsWith("/calls/zoom/register"));
// The event here has value=true. We keep it in events.js to
@ -1657,7 +1639,7 @@ test_ui("on_events", () => {
server_events_dispatch.dispatch_normal_event(events.fixtures.has_zoom_token);
};
channel.post = function (payload) {
channel.post = (payload) => {
assert.equal(payload.url, "/json/calls/zoom/create");
payload.success({url: "example.zoom.com"});
return {abort: () => {}};
@ -1682,7 +1664,7 @@ test_ui("on_events", () => {
},
};
compose_ui.insert_syntax_and_focus = function (syntax) {
compose_ui.insert_syntax_and_focus = (syntax) => {
syntax_to_insert = syntax;
called = true;
};
@ -1693,7 +1675,7 @@ test_ui("on_events", () => {
page_params.realm_video_chat_provider =
page_params.realm_available_video_chat_providers.big_blue_button.id;
channel.get = function (options) {
channel.get = (options) => {
assert(options.url === "/json/calls/bigbluebutton/create");
options.success({
url:
@ -1724,14 +1706,14 @@ test_ui("on_events", () => {
}
function setup_mock_markdown_contains_backend_only_syntax(msg_content, return_val) {
markdown.contains_backend_only_syntax = function (msg) {
markdown.contains_backend_only_syntax = (msg) => {
assert.equal(msg, msg_content);
return return_val;
};
}
function setup_mock_markdown_is_status_message(msg_content, return_val) {
markdown.is_status_message = function (content) {
markdown.is_status_message = (content) => {
assert.equal(content, msg_content);
return return_val;
};
@ -1751,7 +1733,7 @@ test_ui("on_events", () => {
}
function mock_channel_post(msg) {
channel.post = function (payload) {
channel.post = (payload) => {
assert.equal(payload.url, "/json/messages/render");
assert(payload.idempotent);
assert(payload.data);
@ -1759,7 +1741,7 @@ test_ui("on_events", () => {
function test(func, param) {
let destroy_indicator_called = false;
loading.destroy_indicator = function (spinner) {
loading.destroy_indicator = (spinner) => {
assert.equal(spinner, $("#markdown_preview_spinner"));
destroy_indicator_called = true;
};
@ -1795,7 +1777,7 @@ test_ui("on_events", () => {
setup_visibilities();
setup_mock_markdown_contains_backend_only_syntax("```foobarfoobar```", true);
setup_mock_markdown_is_status_message("```foobarfoobar```", false);
loading.make_indicator = function (spinner) {
loading.make_indicator = (spinner) => {
assert.equal(spinner.selector, "#markdown_preview_spinner");
make_indicator_called = true;
};
@ -1812,7 +1794,7 @@ test_ui("on_events", () => {
setup_mock_markdown_contains_backend_only_syntax("foobarfoobar", false);
setup_mock_markdown_is_status_message("foobarfoobar", false);
mock_channel_post("foobarfoobar");
markdown.apply_markdown = function (msg) {
markdown.apply_markdown = (msg) => {
assert.equal(msg.raw_content, "foobarfoobar");
apply_markdown_called = true;
return msg;
@ -1858,9 +1840,7 @@ test_ui("create_message_object", () => {
$("#stream_message_recipient_topic").val("lunch");
$("#compose-textarea").val("burrito");
compose_state.get_message_type = function () {
return "stream";
};
compose_state.get_message_type = () => "stream";
let message = compose.create_message_object();
assert.equal(message.to, sub.stream_id);
@ -1875,12 +1855,8 @@ test_ui("create_message_object", () => {
assert.equal(message.topic, "lunch");
assert.equal(message.content, "burrito");
compose_state.get_message_type = function () {
return "private";
};
compose_state.private_message_recipient = function () {
return "alice@example.com, bob@example.com";
};
compose_state.get_message_type = () => "private";
compose_state.private_message_recipient = () => "alice@example.com, bob@example.com";
message = compose.create_message_object();
assert.deepEqual(message.to, [alice.user_id, bob.user_id]);

View File

@ -6,13 +6,9 @@ const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const noop = function () {};
const return_false = function () {
return false;
};
const return_true = function () {
return true;
};
const noop = () => {};
const return_false = () => false;
const return_true = () => true;
set_global("document", {
location: {}, // we need this to load compose.js
@ -125,7 +121,7 @@ run_test("start", () => {
compose_actions.clear_textarea = noop;
// Start stream message
narrow_state.set_compose_defaults = function () {
narrow_state.set_compose_defaults = () => {
const opts = {};
opts.stream = "stream1";
opts.topic = "topic1";
@ -152,7 +148,7 @@ run_test("start", () => {
};
stream_data.add_sub(denmark);
narrow_state.set_compose_defaults = function () {
narrow_state.set_compose_defaults = () => {
const opts = {};
opts.trigger = "new topic button";
return opts;
@ -163,7 +159,7 @@ run_test("start", () => {
assert.equal($("#stream_message_recipient_stream").val(), "Denmark");
assert.equal($("#stream_message_recipient_topic").val(), "");
narrow_state.set_compose_defaults = function () {
narrow_state.set_compose_defaults = () => {
const opts = {};
opts.trigger = "compose_hotkey";
return opts;
@ -190,7 +186,7 @@ run_test("start", () => {
stream_data.clear_subscriptions();
// Start PM
narrow_state.set_compose_defaults = function () {
narrow_state.set_compose_defaults = () => {
const opts = {};
opts.private_message_recipient = "foo@example.com";
return opts;
@ -212,7 +208,7 @@ run_test("start", () => {
// Cancel compose.
let pill_cleared;
compose_pm_pill.clear = function () {
compose_pm_pill.clear = () => {
pill_cleared = true;
};
@ -325,15 +321,13 @@ run_test("quote_and_reply", () => {
raw_content: "Testing.",
});
current_msg_list.selected_id = function () {
return 100;
};
current_msg_list.selected_id = () => 100;
compose_ui.insert_syntax_and_focus = function (syntax) {
compose_ui.insert_syntax_and_focus = (syntax) => {
assert.equal(syntax, "[Quoting…]\n");
};
compose_ui.replace_syntax = function (syntax, replacement) {
compose_ui.replace_syntax = (syntax, replacement) => {
assert.equal(syntax, "[Quoting…]");
assert.equal(
replacement,
@ -351,17 +345,15 @@ run_test("quote_and_reply", () => {
quote_and_reply(opts);
current_msg_list.selected_message = function () {
return {
type: "stream",
stream: "devel",
topic: "test",
reply_to: "bob",
sender_full_name: "Bob Roberts",
sender_id: 40,
raw_content: "Testing.",
};
};
current_msg_list.selected_message = () => ({
type: "stream",
stream: "devel",
topic: "test",
reply_to: "bob",
sender_full_name: "Bob Roberts",
sender_id: 40,
raw_content: "Testing.",
});
set_global("channel", {
get() {
@ -371,18 +363,16 @@ run_test("quote_and_reply", () => {
quote_and_reply(opts);
current_msg_list.selected_message = function () {
return {
type: "stream",
stream: "devel",
topic: "test",
reply_to: "bob",
sender_full_name: "Bob Roberts",
sender_id: 40,
raw_content: "```\nmultiline code block\nshoudln't mess with quotes\n```",
};
};
compose_ui.replace_syntax = function (syntax, replacement) {
current_msg_list.selected_message = () => ({
type: "stream",
stream: "devel",
topic: "test",
reply_to: "bob",
sender_full_name: "Bob Roberts",
sender_id: 40,
raw_content: "```\nmultiline code block\nshoudln't mess with quotes\n```",
});
compose_ui.replace_syntax = (syntax, replacement) => {
assert.equal(syntax, "[Quoting…]");
assert.equal(
replacement,
@ -410,7 +400,7 @@ run_test("get_focus_area", () => {
});
run_test("focus_in_empty_compose", () => {
$("#compose-textarea").is = function (attr) {
$("#compose-textarea").is = (attr) => {
assert.equal(attr, ":focus");
return $("#compose-textarea").is_focused;
};
@ -432,7 +422,7 @@ run_test("focus_in_empty_compose", () => {
run_test("on_narrow", () => {
let cancel_called = false;
compose_actions.cancel = function () {
compose_actions.cancel = () => {
cancel_called = true;
};
compose_actions.on_narrow({
@ -441,42 +431,32 @@ run_test("on_narrow", () => {
assert(cancel_called);
let on_topic_narrow_called = false;
compose_actions.on_topic_narrow = function () {
compose_actions.on_topic_narrow = () => {
on_topic_narrow_called = true;
};
narrow_state.narrowed_by_topic_reply = function () {
return true;
};
narrow_state.narrowed_by_topic_reply = () => true;
compose_actions.on_narrow({
force_close: false,
});
assert(on_topic_narrow_called);
let update_message_list_called = false;
narrow_state.narrowed_by_topic_reply = function () {
return false;
};
compose_fade.update_message_list = function () {
narrow_state.narrowed_by_topic_reply = () => false;
compose_fade.update_message_list = () => {
update_message_list_called = true;
};
compose_state.has_message_content = function () {
return true;
};
compose_state.has_message_content = () => true;
compose_actions.on_narrow({
force_close: false,
});
assert(update_message_list_called);
compose_state.has_message_content = function () {
return false;
};
compose_state.has_message_content = () => false;
let start_called = false;
compose_actions.start = function () {
compose_actions.start = () => {
start_called = true;
};
narrow_state.narrowed_by_pm_reply = function () {
return true;
};
narrow_state.narrowed_by_pm_reply = () => true;
compose_actions.on_narrow({
force_close: false,
trigger: "not-search",
@ -492,9 +472,7 @@ run_test("on_narrow", () => {
});
assert(!start_called);
narrow_state.narrowed_by_pm_reply = function () {
return false;
};
narrow_state.narrowed_by_pm_reply = () => false;
cancel_called = false;
compose_actions.on_narrow({
force_close: false,

View File

@ -35,9 +35,7 @@ run_test("pills", () => {
full_name: "Hamlet",
};
people.get_realm_users = function () {
return [iago, othello, hamlet];
};
people.get_realm_users = () => [iago, othello, hamlet];
const recipient_stub = $("#private_message_recipient");
const pill_container_stub = "pill-container";
@ -46,22 +44,20 @@ run_test("pills", () => {
const all_pills = new Map();
pills.appendValidatedData = function (item) {
pills.appendValidatedData = (item) => {
const id = item.user_id;
assert(!all_pills.has(id));
all_pills.set(id, item);
};
pills.items = function () {
return Array.from(all_pills.values());
};
pills.items = () => Array.from(all_pills.values());
let text_cleared;
pills.clear_text = function () {
pills.clear_text = () => {
text_cleared = true;
};
let pills_cleared;
pills.clear = function () {
pills.clear = () => {
pills_cleared = true;
pills = {
pill: {},
@ -77,7 +73,7 @@ run_test("pills", () => {
};
let get_by_email_called = false;
people.get_by_email = function (user_email) {
people.get_by_email = (user_email) => {
get_by_email_called = true;
if (user_email === iago.email) {
return iago;
@ -89,7 +85,7 @@ run_test("pills", () => {
};
let get_by_user_id_called = false;
people.get_by_user_id = function (id) {
people.get_by_user_id = (id) => {
get_by_user_id_called = true;
if (id === othello.user_id) {
return othello;

View File

@ -39,7 +39,7 @@ function make_textbox(s) {
widget.s = s;
widget.focused = false;
widget.caret = function (arg) {
widget.caret = (arg) => {
if (typeof arg === "number") {
widget.pos = arg;
return this;
@ -58,7 +58,7 @@ function make_textbox(s) {
return widget.pos;
};
widget.val = function (new_val) {
widget.val = (new_val) => {
if (new_val) {
widget.s = new_val;
return this;
@ -66,7 +66,7 @@ function make_textbox(s) {
return widget.s;
};
widget.trigger = function (type) {
widget.trigger = (type) => {
if (type === "focus") {
widget.focused = true;
} else if (type === "blur") {
@ -95,7 +95,7 @@ run_test("autosize_textarea", (override) => {
run_test("insert_syntax_and_focus", () => {
$("#compose-textarea").val("xyz ");
$("#compose-textarea").caret = function (syntax) {
$("#compose-textarea").caret = (syntax) => {
if (syntax !== undefined) {
$("#compose-textarea").val($("#compose-textarea").val() + syntax);
return this;

View File

@ -32,7 +32,7 @@ const message_store = set_global("message_store", {
});
const ct = composebox_typeahead;
const noop = function () {};
const noop = () => {};
// Use a slightly larger value than what's user-facing
// to facilitate testing different combinations of
@ -285,9 +285,10 @@ user_groups.add(hamletcharacters);
user_groups.add(backend);
user_groups.add(call_center);
const make_emoji = function (emoji_dict) {
return {emoji_name: emoji_dict.name, emoji_code: emoji_dict.emoji_code};
};
const make_emoji = (emoji_dict) => ({
emoji_name: emoji_dict.name,
emoji_code: emoji_dict.emoji_code,
});
run_test("topics_seen_for", () => {
stream_topic_history.get_recent_topic_names = (stream_id) => {
@ -312,7 +313,7 @@ run_test("content_typeahead_selected", () => {
};
let caret_called1 = false;
let caret_called2 = false;
fake_this.$element.caret = function (...args) {
fake_this.$element.caret = (...args) => {
if (args.length === 0) {
// .caret() used in split_at_cursor
caret_called1 = true;
@ -522,9 +523,7 @@ run_test("content_typeahead_selected", () => {
// Test special case to not close code blocks if there is text afterward
fake_this.query = "```p\nsome existing code";
fake_this.token = "p";
fake_this.$element.caret = function () {
return 4; // Put cursor right after ```p
};
fake_this.$element.caret = () => 4; // Put cursor right after ```p
actual_value = ct.content_typeahead_selected.call(fake_this, "python");
expected_value = "```python\nsome existing code";
assert.equal(actual_value, expected_value);
@ -551,7 +550,7 @@ run_test("initialize", () => {
let expected_value;
let stream_typeahead_called = false;
$("#stream_message_recipient_stream").typeahead = function (options) {
$("#stream_message_recipient_stream").typeahead = (options) => {
// options.source()
//
let actual_value = options.source();
@ -585,7 +584,7 @@ run_test("initialize", () => {
};
let subject_typeahead_called = false;
$("#stream_message_recipient_topic").typeahead = function (options) {
$("#stream_message_recipient_topic").typeahead = (options) => {
const topics = ["<&>", "even more ice", "furniture", "ice", "kronor", "more ice"];
stream_topic_history.get_recent_topic_names = (stream_id) => {
assert.equal(stream_id, sweden_stream.stream_id);
@ -653,11 +652,9 @@ run_test("initialize", () => {
};
let pm_recipient_typeahead_called = false;
$("#private_message_recipient").typeahead = function (options) {
$("#private_message_recipient").typeahead = (options) => {
let inserted_users = [];
user_pill.get_user_ids = function () {
return inserted_users;
};
user_pill.get_user_ids = () => inserted_users;
// This should match the users added at the beginning of this test file.
let actual_value = options.source("");
@ -786,7 +783,7 @@ run_test("initialize", () => {
};
let appended_name;
compose_pm_pill.set_from_typeahead = function (item) {
compose_pm_pill.set_from_typeahead = (item) => {
appended_name = item.full_name;
};
@ -808,7 +805,7 @@ run_test("initialize", () => {
let appended_names = [];
compose_pm_pill.set_from_typeahead = function (item) {
compose_pm_pill.set_from_typeahead = (item) => {
appended_names.push(item.full_name);
};
@ -834,7 +831,7 @@ run_test("initialize", () => {
};
let compose_textarea_typeahead_called = false;
$("#compose-textarea").typeahead = function (options) {
$("#compose-textarea").typeahead = (options) => {
// options.source()
//
// For now we only test that get_sorted_filtered_items has been
@ -844,7 +841,7 @@ run_test("initialize", () => {
$element: {},
};
let caret_called = false;
fake_this.$element.caret = function () {
fake_this.$element.caret = () => {
caret_called = true;
return 7;
};
@ -952,17 +949,13 @@ run_test("initialize", () => {
subscribed: false,
};
// Subscribed stream is active
stream_data.is_active = function () {
return false;
};
stream_data.is_active = () => false;
fake_this = {completing: "stream", token: "s"};
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
expected_value = [sweden_stream, serbia_stream];
assert.deepEqual(actual_value, expected_value);
// Subscribed stream is inactive
stream_data.is_active = function () {
return true;
};
stream_data.is_active = () => true;
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
expected_value = [sweden_stream, serbia_stream];
assert.deepEqual(actual_value, expected_value);
@ -996,14 +989,10 @@ run_test("initialize", () => {
preventDefault: noop,
};
$("#stream_message_recipient_topic").data = function () {
return {typeahead: {shown: true}};
};
$("#stream_message_recipient_topic").data = () => ({typeahead: {shown: true}});
$("form#send_message_form").trigger(event);
const stub_typeahead_hidden = function () {
return {typeahead: {shown: false}};
};
const stub_typeahead_hidden = () => ({typeahead: {shown: false}});
$("#stream_message_recipient_topic").data = stub_typeahead_hidden;
$("#stream_message_recipient_stream").data = stub_typeahead_hidden;
$("#private_message_recipient").data = stub_typeahead_hidden;
@ -1023,14 +1012,12 @@ run_test("initialize", () => {
// Set up jquery functions used in compose_textarea Enter
// handler.
let range_length = 0;
$("#compose-textarea").range = function () {
return {
length: range_length,
range: noop,
start: 0,
end: 0 + range_length,
};
};
$("#compose-textarea").range = () => ({
length: range_length,
range: noop,
start: 0,
end: 0 + range_length,
});
$("#compose-textarea").caret = noop;
event.keyCode = 13;
@ -1040,7 +1027,7 @@ run_test("initialize", () => {
page_params.enter_sends = false;
event.metaKey = true;
let compose_finish_called = false;
compose.finish = function () {
compose.finish = () => {
compose_finish_called = true;
};
@ -1077,9 +1064,7 @@ run_test("initialize", () => {
preventDefault: noop,
};
// We trigger keydown in order to make nextFocus !== false
$("#stream_message_recipient_topic").data = function () {
return {typeahead: {shown: true}};
};
$("#stream_message_recipient_topic").data = () => ({typeahead: {shown: true}});
$("form#send_message_form").trigger(event);
$("#stream_message_recipient_topic").off("mouseup");
event.type = "keyup";
@ -1096,23 +1081,19 @@ run_test("initialize", () => {
$("#compose-send-button").fadeOut = noop;
$("#compose-send-button").fadeIn = noop;
let channel_post_called = false;
channel.post = function (params) {
channel.post = (params) => {
assert.equal(params.url, "/json/users/me/enter-sends");
assert.equal(params.idempotent, true);
assert.deepEqual(params.data, {enter_sends: page_params.enter_sends});
channel_post_called = true;
};
$("#enter_sends").is = function () {
return false;
};
$("#enter_sends").is = () => false;
$("#enter_sends").trigger("click");
// Now we re-run both .initialize() and the click handler, this time
// with enter_sends: page_params.enter_sends being true
$("#enter_sends").is = function () {
return true;
};
$("#enter_sends").is = () => true;
$("#enter_sends").trigger("click");
$("#stream_message_recipient_stream").off("focus");
@ -1151,9 +1132,7 @@ run_test("begins_typeahead", () => {
function get_values(input, rest) {
// Stub out split_at_cursor that uses $(':focus')
ct.split_at_cursor = function () {
return [input, rest];
};
ct.split_at_cursor = () => [input, rest];
const values = ct.get_candidates.call(begin_typehead_this, input);
return values;
}
@ -1374,7 +1353,7 @@ run_test("content_highlighter", () => {
let fake_this = {completing: "emoji"};
const emoji = {emoji_name: "person shrugging", emoji_url: "¯\\_(ツ)_/¯"};
let th_render_typeahead_item_called = false;
typeahead_helper.render_emoji = function (item) {
typeahead_helper.render_emoji = (item) => {
assert.deepEqual(item, emoji);
th_render_typeahead_item_called = true;
};
@ -1382,14 +1361,14 @@ run_test("content_highlighter", () => {
fake_this = {completing: "mention"};
let th_render_person_called = false;
typeahead_helper.render_person = function (person) {
typeahead_helper.render_person = (person) => {
assert.deepEqual(person, othello);
th_render_person_called = true;
};
ct.content_highlighter.call(fake_this, othello);
let th_render_user_group_called = false;
typeahead_helper.render_user_group = function (user_group) {
typeahead_helper.render_user_group = (user_group) => {
assert.deepEqual(user_group, backend);
th_render_user_group_called = true;
};
@ -1401,7 +1380,7 @@ run_test("content_highlighter", () => {
const me_slash = {
text: "/me is excited (Display action text)",
};
typeahead_helper.render_typeahead_item = function (item) {
typeahead_helper.render_typeahead_item = (item) => {
assert.deepEqual(item, {
primary: "/me is excited (Display action text)",
});
@ -1411,7 +1390,7 @@ run_test("content_highlighter", () => {
fake_this = {completing: "stream"};
let th_render_stream_called = false;
typeahead_helper.render_stream = function (stream) {
typeahead_helper.render_stream = (stream) => {
assert.deepEqual(stream, denmark_stream);
th_render_stream_called = true;
};
@ -1419,7 +1398,7 @@ run_test("content_highlighter", () => {
fake_this = {completing: "syntax"};
th_render_typeahead_item_called = false;
typeahead_helper.render_typeahead_item = function (item) {
typeahead_helper.render_typeahead_item = (item) => {
assert.deepEqual(item, {primary: "py"});
th_render_typeahead_item_called = true;
};

View File

@ -7,7 +7,7 @@ const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const noop = function () {};
const noop = () => {};
const events = require("./lib/events");

View File

@ -29,7 +29,7 @@ const stream_list = set_global("stream_list", {});
const server_events_dispatch = zrequire("server_events_dispatch");
const noop = function () {};
const noop = () => {};
people.add_active_user(test_user);

View File

@ -13,9 +13,7 @@ const timerender = zrequire("timerender");
zrequire("stream_color");
const ls_container = new Map();
const noop = function () {
return;
};
const noop = () => {};
const localStorage = set_global("localStorage", {
getItem(key) {
@ -163,10 +161,10 @@ run_test("snapshot_message", (override) => {
});
run_test("initialize", () => {
window.addEventListener = function (event_name, f) {
window.addEventListener = (event_name, f) => {
assert.equal(event_name, "beforeunload");
let called = false;
drafts.update_draft = function () {
drafts.update_draft = () => {
called = true;
};
f();
@ -287,9 +285,7 @@ run_test("format_drafts", (override) => {
assert.deepEqual(draft_model.get(), data);
const stub_render_now = timerender.render_now;
timerender.render_now = function (time) {
return stub_render_now(time, new Date(1549958107000));
};
timerender.render_now = (time) => stub_render_now(time, new Date(1549958107000));
stub_templates((template_name, data) => {
assert.equal(template_name, "draft_table_body");

View File

@ -1550,7 +1550,7 @@ run_test("navbar_helpers", () => {
run_test("error_cases", () => {
// This test just gives us 100% line coverage on defensive code that
// should not be reached unless we break other code.
people.pm_with_user_ids = function () {};
people.pm_with_user_ids = () => {};
const predicate = get_predicate([["pm-with", "Joe@example.com"]]);
assert(!predicate({type: "private"}));

View File

@ -12,7 +12,7 @@ zrequire("templates");
set_global("document", {});
const noop = function () {};
const noop = () => {};
const example_img_link = "http://example.com/example.png";
set_global("ui_util", {
@ -28,7 +28,7 @@ run_test("set_up_ids", () => {
// just get coverage on a simple one-liner:
input_pill.random_id();
input_pill.random_id = function () {
input_pill.random_id = () => {
id_seq += 1;
return "some_id" + id_seq;
};
@ -80,7 +80,7 @@ run_test("basics", () => {
let inserted_before;
const expected_html = pill_html("JavaScript", "some_id1", example_img_link);
pill_input.before = function (elem) {
pill_input.before = (elem) => {
inserted_before = true;
assert.equal(elem.html(), expected_html);
};
@ -115,9 +115,7 @@ function set_up() {
pill_input[0] = {};
pill_input.before = () => {};
const create_item_from_text = function (text) {
return items[text];
};
const create_item_from_text = (text) => items[text];
const container = $.create("container");
container.set_find_results(".input", pill_input);
@ -368,7 +366,7 @@ run_test("insert_remove", () => {
const container = info.container;
const inserted_html = [];
pill_input.before = function (elem) {
pill_input.before = (elem) => {
inserted_html.push(elem.html());
};

View File

@ -95,7 +95,7 @@ function config_fake_channel(conf) {
let called;
let called_with_newest_flag = false;
channel.get = function (opts) {
channel.get = (opts) => {
assert.equal(opts.url, "/json/messages");
// There's a separate call with anchor="newest" that happens
// unconditionally; do basic verfication of that call.
@ -127,17 +127,17 @@ function config_process_results(messages) {
const messages_processed_for_bools = [];
message_store.set_message_booleans = function (message) {
message_store.set_message_booleans = (message) => {
messages_processed_for_bools.push(message);
};
message_store.add_message_metadata = (message) => message;
message_util.do_unread_count_updates = function (arg) {
message_util.do_unread_count_updates = (arg) => {
assert.deepEqual(arg, messages);
};
message_util.add_old_messages = function (new_messages, msg_list) {
message_util.add_old_messages = (new_messages, msg_list) => {
assert.deepEqual(new_messages, messages);
msg_list.add_messages(new_messages);
};
@ -146,7 +146,7 @@ function config_process_results(messages) {
pm_list.update_private_messages = noop;
self.verify = function () {
self.verify = () => {
assert.deepEqual(messages_processed_for_bools, messages);
};
@ -216,7 +216,7 @@ function initial_fetch_step() {
let fetch;
const response = initialize_data.initial_fetch.resp;
self.prep = function () {
self.prep = () => {
fetch = config_fake_channel({
expected_opts_data: initialize_data.initial_fetch.req,
});
@ -224,7 +224,7 @@ function initial_fetch_step() {
message_fetch.initialize();
};
self.finish = function () {
self.finish = () => {
test_fetch_success({
fetch,
response,
@ -239,17 +239,17 @@ function forward_fill_step() {
let fetch;
self.prep = function () {
self.prep = () => {
fetch = config_fake_channel({
expected_opts_data: initialize_data.forward_fill.req,
});
};
self.finish = function () {
self.finish = () => {
const response = initialize_data.forward_fill.resp;
let idle_config;
$("document-stub").idle = function (config) {
$("document-stub").idle = (config) => {
idle_config = config;
};
@ -304,9 +304,7 @@ function simulate_narrow() {
public_operators: () => [{operator: "pm-with", operand: alice.email}],
};
narrow_state.active = function () {
return true;
};
narrow_state.active = () => true;
const msg_list = new message_list.MessageList({
table_name: "zfilt",

View File

@ -158,7 +158,7 @@ run_test("muting", () => {
assert.deepEqual(mld._all_items, []);
let messages_filtered_for_topic_mutes_calls = 0;
mld.messages_filtered_for_topic_mutes = function (messages) {
mld.messages_filtered_for_topic_mutes = (messages) => {
messages_filtered_for_topic_mutes_calls = messages_filtered_for_topic_mutes_calls + 1;
return messages;
};

View File

@ -15,7 +15,7 @@ zrequire("MessageListData", "js/message_list_data");
const MessageListView = zrequire("MessageListView", "js/message_list_view");
const message_list = zrequire("message_list");
const noop = function () {};
const noop = () => {};
const page_params = set_global("page_params", {
twenty_four_hour_time: false,
@ -450,9 +450,7 @@ run_test("render_windows", () => {
// Stub out functionality that is not core to the rendering window
// logic.
list.data.unmuted_messages = function (messages) {
return messages;
};
list.data.unmuted_messages = (messages) => messages;
// We don't need to actually render the DOM. The windowing logic
// sits above that layer.
@ -476,9 +474,7 @@ run_test("render_windows", () => {
messages = _.range(opts.count).map((i) => ({
id: i,
}));
list.selected_idx = function () {
return 0;
};
list.selected_idx = () => 0;
list.clear();
list.add_messages(messages, {});
@ -490,9 +486,7 @@ run_test("render_windows", () => {
// a re-render. The code avoids hasty re-renders for
// performance reasons.
for (const idx of _.range(start, end)) {
list.selected_idx = function () {
return idx;
};
list.selected_idx = () => idx;
const rendered = view.maybe_rerender();
assert.equal(rendered, false);
}
@ -502,9 +496,7 @@ run_test("render_windows", () => {
const start = range[0];
const end = range[1];
list.selected_idx = function () {
return idx;
};
list.selected_idx = () => idx;
const rendered = view.maybe_rerender();
assert.equal(rendered, true);
assert.equal(view._render_win_start, start);

View File

@ -11,7 +11,7 @@ const people = zrequire("people");
const pm_conversations = zrequire("pm_conversations");
const message_store = zrequire("message_store");
const noop = function () {};
const noop = () => {};
set_global("document", "document-stub");

View File

@ -252,7 +252,7 @@ run_test("narrow_to_compose_target", () => {
const stream_topic_history = set_global("stream_topic_history", {});
const args = {called: false};
const activate_backup = narrow.activate;
narrow.activate = function (operators, opts) {
narrow.activate = (operators, opts) => {
args.operators = operators;
args.opts = opts;
args.called = true;

View File

@ -16,17 +16,17 @@ run_test("basics", () => {
const bar = (function () {
const self = {};
self.width = function (width) {
self.width = (width) => {
self.w = width;
return self;
};
self.removeClass = function (arg) {
self.removeClass = (arg) => {
assert.equal(arg, "bar-success bar-danger");
return self;
};
self.addClass = function (arg) {
self.addClass = (arg) => {
self.added_class = arg;
return self;
};
@ -37,7 +37,7 @@ run_test("basics", () => {
function password_field(min_length, min_guesses) {
const self = {};
self.data = function (field) {
self.data = (field) => {
if (field === "minLength") {
return min_length;
} else if (field === "minGuesses") {

View File

@ -7,12 +7,8 @@ const {run_test} = require("../zjsunit/test");
const people = zrequire("people");
const return_false = function () {
return false;
};
const return_true = function () {
return true;
};
const return_false = () => false;
const return_true = () => true;
const reload_state = set_global("reload_state", {
is_in_progress: return_false,
});

View File

@ -8,9 +8,7 @@ const {run_test} = require("../zjsunit/test");
const people = zrequire("people");
const presence = zrequire("presence");
const return_false = function () {
return false;
};
const return_false = () => false;
const server_events = set_global("server_events", {});
const reload_state = set_global("reload_state", {
@ -269,9 +267,7 @@ run_test("big realms", () => {
// which case we will not provide default values for
// users that aren't in our presences payload.
const get_active_human_count = people.get_active_human_count;
people.get_active_human_count = function () {
return 1000;
};
people.get_active_human_count = () => 1000;
presence.set_info(presences, now);
assert(presence.presence_info.has(sally.user_id));
assert(!presence.presence_info.has(zoe.user_id));

View File

@ -131,7 +131,7 @@ run_test("open_reactions_popover", () => {
$(".selected-row").set_find_results(".reaction_button", ["reaction-stub"]);
let called = false;
emoji_picker.toggle_emoji_popover = function (target, id) {
emoji_picker.toggle_emoji_popover = (target, id) => {
called = true;
assert.equal(id, 42);
assert.equal(target, "action-stub");
@ -140,12 +140,10 @@ run_test("open_reactions_popover", () => {
assert(reactions.open_reactions_popover());
assert(called);
current_msg_list.selected_message = function () {
return {sent_by_me: false};
};
current_msg_list.selected_message = () => ({sent_by_me: false});
called = false;
emoji_picker.toggle_emoji_popover = function (target, id) {
emoji_picker.toggle_emoji_popover = (target, id) => {
called = true;
assert.equal(id, 42);
assert.equal(target, "reaction-stub");
@ -281,9 +279,7 @@ run_test("sending", (override) => {
// similarly, we only exercise the failure codepath
// Since this path calls blueslip.warn, we need to handle it.
blueslip.expect("warn", "XHR Error Message.");
channel.xhr_error_message = function () {
return "XHR Error Message.";
};
channel.xhr_error_message = () => "XHR Error Message.";
args.error();
}
emoji_name = "alien"; // not set yet
@ -386,12 +382,12 @@ run_test("add_and_remove_reaction", () => {
const message_reactions = $.create("our-reactions");
reactions.get_reaction_section = function (message_id) {
reactions.get_reaction_section = (message_id) => {
assert.equal(message_id, 1001);
return message_reactions;
};
message_reactions.find = function (selector) {
message_reactions.find = (selector) => {
assert.equal(selector, ".reaction_button");
return "reaction-button-stub";
};
@ -408,7 +404,7 @@ run_test("add_and_remove_reaction", () => {
});
let insert_called;
$("<new reaction html>").insertBefore = function (element) {
$("<new reaction html>").insertBefore = (element) => {
assert.equal(element, "reaction-button-stub");
insert_called = true;
};
@ -445,7 +441,7 @@ run_test("add_and_remove_reaction", () => {
const reaction_element = $.create("reaction-element");
reaction_element.set_find_results(".message_reaction_count", count_element);
message_reactions.find = function (selector) {
message_reactions.find = (selector) => {
assert.equal(selector, "[data-reaction-id='unicode_emoji\\,1f3b1']");
return reaction_element;
};
@ -462,7 +458,7 @@ run_test("add_and_remove_reaction", () => {
// Next, remove Alice's reaction, which exercises removing the
// emoji icon.
let removed;
reaction_element.remove = function () {
reaction_element.remove = () => {
removed = true;
};
@ -494,7 +490,7 @@ run_test("add_and_remove_reaction", () => {
return "<new reaction html>";
});
message_reactions.find = function (selector) {
message_reactions.find = (selector) => {
assert.equal(selector, ".reaction_button");
return "reaction-button-stub";
};
@ -512,11 +508,11 @@ run_test("add_and_remove_reaction", () => {
user_id: alice.user_id,
};
message_reactions.find = function (selector) {
message_reactions.find = (selector) => {
assert.equal(selector, "[data-reaction-id='realm_emoji\\,991']");
return reaction_element;
};
reaction_element.prop = function () {};
reaction_element.prop = () => {};
reactions.add_reaction(alice_event);
const result = reactions.get_message_reactions(message);
@ -540,9 +536,7 @@ run_test("with_view_stubs", () => {
reactions: [],
};
message_store.get = function () {
return message;
};
message_store.get = () => message;
function test_view_calls(test_params) {
const calls = [];
@ -686,9 +680,7 @@ run_test("with_view_stubs", () => {
});
run_test("error_handling", (override) => {
message_store.get = function () {
return;
};
message_store.get = () => {};
blueslip.expect("error", "reactions: Bad message id: 55");
@ -768,7 +760,7 @@ run_test("process_reaction_click", () => {
reaction_type: "unicode_emoji",
emoji_code: "1f3b1",
};
message_store.get = function (message_id) {
message_store.get = (message_id) => {
assert.equal(message_id, 1001);
return message;
};

View File

@ -86,9 +86,7 @@ run_test("initialize", () => {
search_query_box[0] = "stub";
search_pill.get_search_string_for_current_filter = function () {
return "is:starred";
};
search_pill.get_search_string_for_current_filter = () => "is:starred";
search_suggestion.max_num_of_search_results = 99;
search_query_box.typeahead = (opts) => {

View File

@ -74,7 +74,7 @@ run_test("get_items", () => {
run_test("create_pills", () => {
let input_pill_create_called = false;
input_pill.create = function () {
input_pill.create = () => {
input_pill_create_called = true;
return {dummy: "dummy"};
};

View File

@ -87,13 +87,9 @@ function get_suggestions(base_query, query) {
run_test("basic_get_suggestions", () => {
const query = "fred";
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return "office";
};
narrow_state.stream = () => "office";
const suggestions = get_suggestions("", query);
@ -105,13 +101,9 @@ run_test("subset_suggestions", () => {
const query = "shakespeare";
const base_query = "stream:Denmark topic:Hamlet";
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
const suggestions = get_suggestions(base_query, query);
@ -121,13 +113,9 @@ run_test("subset_suggestions", () => {
});
run_test("private_suggestions", () => {
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
let query = "is:private";
let suggestions = get_suggestions("", query);
@ -242,13 +230,9 @@ run_test("private_suggestions", () => {
});
run_test("group_suggestions", () => {
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
// Entering a comma in a pm-with query should immediately generate
// suggestions for the next person.
@ -387,13 +371,9 @@ init();
run_test("empty_query_suggestions", () => {
const query = "";
stream_data.subscribed_streams = function () {
return ["devel", "office"];
};
stream_data.subscribed_streams = () => ["devel", "office"];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
const suggestions = get_suggestions("", query);
@ -433,12 +413,8 @@ run_test("has_suggestions", () => {
// Checks that category wise suggestions are displayed instead of a single
// default suggestion when suggesting `has` operator.
let query = "h";
stream_data.subscribed_streams = function () {
return ["devel", "office"];
};
narrow_state.stream = function () {
return;
};
stream_data.subscribed_streams = () => ["devel", "office"];
narrow_state.stream = () => {};
let suggestions = get_suggestions("", query);
let expected = ["h", "has:link", "has:image", "has:attachment"];
@ -491,12 +467,8 @@ run_test("has_suggestions", () => {
run_test("check_is_suggestions", () => {
let query = "i";
stream_data.subscribed_streams = function () {
return ["devel", "office"];
};
narrow_state.stream = function () {
return;
};
stream_data.subscribed_streams = () => ["devel", "office"];
narrow_state.stream = () => {};
let suggestions = get_suggestions("", query);
let expected = [
@ -598,13 +570,9 @@ run_test("check_is_suggestions", () => {
});
run_test("sent_by_me_suggestions", () => {
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
let query = "";
let suggestions = get_suggestions("", query);
@ -681,18 +649,14 @@ run_test("topic_suggestions", () => {
let suggestions;
let expected;
stream_data.subscribed_streams = function () {
return ["office"];
};
stream_data.subscribed_streams = () => ["office"];
narrow_state.stream = function () {
return "office";
};
narrow_state.stream = () => "office";
const devel_id = 44;
const office_id = 77;
stream_data.get_stream_id = function (stream_name) {
stream_data.get_stream_id = (stream_name) => {
switch (stream_name) {
case "office":
return office_id;
@ -774,13 +738,9 @@ run_test("topic_suggestions", () => {
run_test("whitespace_glitch", () => {
const query = "stream:office "; // note trailing space
stream_data.subscribed_streams = function () {
return ["office"];
};
stream_data.subscribed_streams = () => ["office"];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
stream_topic_history.reset();
@ -792,13 +752,9 @@ run_test("whitespace_glitch", () => {
});
run_test("stream_completion", () => {
stream_data.subscribed_streams = function () {
return ["office", "dev help"];
};
stream_data.subscribed_streams = () => ["office", "dev help"];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
stream_topic_history.reset();
@ -966,13 +922,9 @@ run_test("operator_suggestions", () => {
});
run_test("queries_with_spaces", () => {
stream_data.subscribed_streams = function () {
return ["office", "dev help"];
};
stream_data.subscribed_streams = () => ["office", "dev help"];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
stream_topic_history.reset();

View File

@ -85,13 +85,9 @@ function get_suggestions(base_query, query) {
run_test("basic_get_suggestions", () => {
const query = "fred";
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return "office";
};
narrow_state.stream = () => "office";
const suggestions = get_suggestions("", query);
@ -102,13 +98,9 @@ run_test("basic_get_suggestions", () => {
run_test("subset_suggestions", () => {
const query = "stream:Denmark topic:Hamlet shakespeare";
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
const suggestions = get_suggestions("", query);
@ -122,13 +114,9 @@ run_test("subset_suggestions", () => {
});
run_test("private_suggestions", () => {
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
let query = "is:private";
let suggestions = get_suggestions("", query);
@ -239,13 +227,9 @@ run_test("private_suggestions", () => {
});
run_test("group_suggestions", () => {
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
// Entering a comma in a pm-with query should immediately generate
// suggestions for the next person.
@ -391,13 +375,9 @@ init();
run_test("empty_query_suggestions", () => {
const query = "";
stream_data.subscribed_streams = function () {
return ["devel", "office"];
};
stream_data.subscribed_streams = () => ["devel", "office"];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
const suggestions = get_suggestions("", query);
@ -437,12 +417,8 @@ run_test("has_suggestions", () => {
// Checks that category wise suggestions are displayed instead of a single
// default suggestion when suggesting `has` operator.
let query = "h";
stream_data.subscribed_streams = function () {
return ["devel", "office"];
};
narrow_state.stream = function () {
return;
};
stream_data.subscribed_streams = () => ["devel", "office"];
narrow_state.stream = () => {};
let suggestions = get_suggestions("", query);
let expected = ["h", "has:link", "has:image", "has:attachment"];
@ -497,12 +473,8 @@ run_test("has_suggestions", () => {
});
run_test("check_is_suggestions", () => {
stream_data.subscribed_streams = function () {
return ["devel", "office"];
};
narrow_state.stream = function () {
return;
};
stream_data.subscribed_streams = () => ["devel", "office"];
narrow_state.stream = () => {};
let query = "i";
let suggestions = get_suggestions("", query);
@ -570,13 +542,9 @@ run_test("check_is_suggestions", () => {
});
run_test("sent_by_me_suggestions", () => {
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
let query = "";
let suggestions = get_suggestions("", query);
@ -648,18 +616,14 @@ run_test("topic_suggestions", () => {
let suggestions;
let expected;
stream_data.subscribed_streams = function () {
return ["office"];
};
stream_data.subscribed_streams = () => ["office"];
narrow_state.stream = function () {
return "office";
};
narrow_state.stream = () => "office";
const devel_id = 44;
const office_id = 77;
stream_data.get_stream_id = function (stream_name) {
stream_data.get_stream_id = (stream_name) => {
switch (stream_name) {
case "office":
return office_id;
@ -747,13 +711,9 @@ run_test("topic_suggestions", () => {
run_test("whitespace_glitch", () => {
const query = "stream:office "; // note trailing space
stream_data.subscribed_streams = function () {
return ["office"];
};
stream_data.subscribed_streams = () => ["office"];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
stream_topic_history.reset();
@ -765,13 +725,9 @@ run_test("whitespace_glitch", () => {
});
run_test("stream_completion", () => {
stream_data.subscribed_streams = function () {
return ["office", "dev help"];
};
stream_data.subscribed_streams = () => ["office", "dev help"];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
stream_topic_history.reset();
@ -794,13 +750,9 @@ run_test("stream_completion", () => {
run_test("people_suggestions", () => {
let query = "te";
stream_data.subscribed_streams = function () {
return [];
};
stream_data.subscribed_streams = () => [];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
const ted = {
email: "ted@zulip.com",
@ -912,13 +864,9 @@ run_test("operator_suggestions", () => {
});
run_test("queries_with_spaces", () => {
stream_data.subscribed_streams = function () {
return ["office", "dev help"];
};
stream_data.subscribed_streams = () => ["office", "dev help"];
narrow_state.stream = function () {
return;
};
narrow_state.stream = () => {};
stream_topic_history.reset();

View File

@ -6,7 +6,7 @@ const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const noop = function () {};
const noop = () => {};
set_global("document", {
to_$() {
@ -79,7 +79,7 @@ run_test("message_event", () => {
// Start blueslip tests here
const setup = function () {
const setup = () => {
server_events.home_view_loaded();
set_global("message_events", {
insert_new_messages() {
@ -100,7 +100,7 @@ run_test("event_dispatch_error", () => {
setup();
const data = {events: [{type: "stream", op: "update", id: 1, other: "thing"}]};
channel.get = function (options) {
channel.get = (options) => {
options.success(data);
};
@ -120,7 +120,7 @@ run_test("event_new_message_error", () => {
setup();
const data = {events: [{type: "message", id: 1, other: "thing", message: {}}]};
channel.get = function (options) {
channel.get = (options) => {
options.success(data);
};
@ -136,7 +136,7 @@ run_test("event_new_message_error", () => {
run_test("event_edit_message_error", () => {
setup();
const data = {events: [{type: "update_message", id: 1, other: "thing"}]};
channel.get = function (options) {
channel.get = (options) => {
options.success(data);
};
blueslip.expect("error", "Failed to update messages\nupdate error");

View File

@ -11,13 +11,13 @@ const settings_emoji = zrequire("settings_emoji");
run_test("build_emoji_upload_widget", () => {
let build_widget_stub = false;
upload_widget.build_widget = function (
upload_widget.build_widget = (
get_file_input,
file_name_field,
input_error,
clear_button,
upload_button,
) {
) => {
assert.deepEqual(get_file_input(), $("#emoji_file_input"));
assert.deepEqual(file_name_field, $("#emoji-file-name"));
assert.deepEqual(input_error, $("#emoji_file_input_error"));

View File

@ -12,7 +12,7 @@ const stream_data = zrequire("stream_data");
const muting = zrequire("muting");
const muting_ui = set_global("muting_ui", {});
const noop = function () {};
const noop = () => {};
const frontend = {
stream_id: 101,
@ -23,7 +23,7 @@ stream_data.add_sub(frontend);
run_test("settings", () => {
muting.add_muted_topic(frontend.stream_id, "js", 1577836800);
let set_up_topic_ui_called = false;
muting_ui.set_up_muted_topics_ui = function () {
muting_ui.set_up_muted_topics_ui = () => {
const opts = muting.get_muted_topics();
assert.deepEqual(opts, [
{
@ -51,13 +51,13 @@ run_test("settings", () => {
const topic_fake_this = $.create("fake.settings-unmute-topic");
const topic_tr_html = $('tr[data-topic="js"]');
topic_fake_this.closest = function (opts) {
topic_fake_this.closest = (opts) => {
assert.equal(opts, "tr");
return topic_tr_html;
};
let topic_data_called = 0;
topic_tr_html.attr = function (opts) {
topic_tr_html.attr = (opts) => {
if (opts === "data-stream-id") {
topic_data_called += 1;
return frontend.stream_id;
@ -70,7 +70,7 @@ run_test("settings", () => {
};
let unmute_topic_called = false;
muting_ui.unmute_topic = function (stream_id, topic) {
muting_ui.unmute_topic = (stream_id, topic) => {
assert.equal(stream_id, frontend.stream_id);
assert.equal(topic, "js");
unmute_topic_called = true;

View File

@ -102,7 +102,7 @@ function simulate_realm_domains_table() {
$("#realm_domains_table tbody").set_find_results("tr", $.create("realm-tr-stub"));
let appended;
$("#realm_domains_table tbody").append = function (html) {
$("#realm_domains_table tbody").append = (html) => {
appended = true;
assert.equal(html, "stub-domains-list");
};
@ -128,7 +128,7 @@ function test_realms_domain_modal(add_realm_domain) {
let posted;
let success_callback;
let error_callback;
channel.post = function (req) {
channel.post = (req) => {
posted = true;
assert.equal(req.url, "/json/realm/domains");
success_callback = req.success;
@ -365,7 +365,7 @@ function test_upload_realm_icon(upload_realm_logo_or_icon) {
const file_input = [{files: ["image1.png", "image2.png"]}];
let posted;
channel.post = function (req) {
channel.post = (req) => {
posted = true;
assert.equal(req.url, "/json/realm/icon");
assert.equal(req.data.csrfmiddlewaretoken, "token-stub");
@ -389,7 +389,7 @@ function test_change_allow_subdomains(change_allow_subdomains) {
let success_callback;
let error_callback;
channel.patch = function (req) {
channel.patch = (req) => {
assert.equal(req.url, "/json/realm/domains/example.com");
assert.equal(req.data.allow_subdomains, JSON.stringify(allow));
success_callback = req.success;
@ -758,7 +758,7 @@ run_test("set_up", (override) => {
};
let upload_realm_logo_or_icon;
realm_icon.build_realm_icon_widget = function (f) {
realm_icon.build_realm_icon_widget = (f) => {
upload_realm_logo_or_icon = f;
};
@ -786,7 +786,7 @@ run_test("set_up", (override) => {
const allow_topic_edit_label_parent = $.create("allow-topic-edit-label-parent");
$("#id_realm_allow_community_topic_editing_label").set_parent(allow_topic_edit_label_parent);
channel.get = function (opts) {
channel.get = (opts) => {
assert.equal(opts.url, "/json/export/realm");
};
@ -1024,10 +1024,8 @@ run_test("misc", () => {
let setting_name = "realm_notifications_stream_id";
let elem = $(`#${CSS.escape(setting_name)}_widget #${CSS.escape(setting_name)}_name`);
elem.closest = function () {
return stub_notification_disable_parent;
};
stream_data.get_sub_by_id = function (stream_id) {
elem.closest = () => stub_notification_disable_parent;
stream_data.get_sub_by_id = (stream_id) => {
assert.equal(stream_id, 42);
return {name: "some_stream"};
};
@ -1041,10 +1039,8 @@ run_test("misc", () => {
setting_name = "realm_signup_notifications_stream_id";
elem = $(`#${CSS.escape(setting_name)}_widget #${CSS.escape(setting_name)}_name`);
elem.closest = function () {
return stub_notification_disable_parent;
};
stream_data.get_sub_by_id = function (stream_id) {
elem.closest = () => stub_notification_disable_parent;
stream_data.get_sub_by_id = (stream_id) => {
assert.equal(stream_id, 75);
return {name: "some_stream"};
};

View File

@ -14,7 +14,7 @@ const settings_user_groups = zrequire("settings_user_groups");
const confirm_dialog = set_global("confirm_dialog", {});
const noop = function () {};
const noop = () => {};
const pills = {
pill: {},
@ -123,17 +123,11 @@ test_ui("populate_user_groups", () => {
full_name: "Bob",
};
people.get_realm_users = function () {
return [iago, alice, bob];
};
people.get_realm_users = () => [iago, alice, bob];
user_groups.get_realm_user_groups = function () {
return [realm_user_group];
};
user_groups.get_realm_user_groups = () => [realm_user_group];
people.get_visible_email = function () {
return bob.email;
};
people.get_visible_email = () => bob.email;
let templates_render_called = false;
const fake_rendered_temp = $.create("fake_admin_user_group_list_template_rendered");
@ -147,13 +141,13 @@ test_ui("populate_user_groups", () => {
});
let user_groups_list_append_called = false;
$("#user-groups").append = function (rendered_temp) {
$("#user-groups").append = (rendered_temp) => {
assert.equal(rendered_temp, fake_rendered_temp);
user_groups_list_append_called = true;
};
let get_by_user_id_called = false;
people.get_by_user_id = function (user_id) {
people.get_by_user_id = (user_id) => {
if (user_id === iago.user_id) {
return iago;
}
@ -166,34 +160,28 @@ test_ui("populate_user_groups", () => {
return undefined;
};
settings_user_groups.can_edit = function () {
return true;
};
settings_user_groups.can_edit = () => true;
const all_pills = new Map();
const pill_container_stub = $(`.pill-container[data-group-pills="${CSS.escape(1)}"]`);
pills.appendValidatedData = function (item) {
pills.appendValidatedData = (item) => {
const id = item.user_id;
assert(!all_pills.has(id));
all_pills.set(id, item);
};
pills.items = function () {
return Array.from(all_pills.values());
};
pills.items = () => Array.from(all_pills.values());
let text_cleared;
pills.clear_text = function () {
pills.clear_text = () => {
text_cleared = true;
};
const input_field_stub = $.create("fake-input-field");
pill_container_stub.children = function () {
return input_field_stub;
};
pill_container_stub.children = () => input_field_stub;
let input_typeahead_called = false;
input_field_stub.typeahead = function (config) {
input_field_stub.typeahead = (config) => {
assert.equal(config.items, 5);
assert(config.fixed);
assert(config.dropup);
@ -206,9 +194,7 @@ test_ui("populate_user_groups", () => {
(function test_highlighter() {
const fake_person = $.create("fake-person");
typeahead_helper.render_person = function () {
return fake_person;
};
typeahead_helper.render_person = () => fake_person;
assert.equal(config.highlighter(), fake_person);
})();
@ -248,7 +234,7 @@ test_ui("populate_user_groups", () => {
(function test_sorter() {
let sort_recipientbox_typeahead_called = false;
typeahead_helper.sort_recipientbox_typeahead = function () {
typeahead_helper.sort_recipientbox_typeahead = () => {
sort_recipientbox_typeahead_called = true;
};
config.sorter.call(fake_context);
@ -257,17 +243,15 @@ test_ui("populate_user_groups", () => {
(function test_updater() {
input_field_stub.text("@ali");
user_groups.get_user_group_from_id = function () {
return realm_user_group;
};
user_groups.get_user_group_from_id = () => realm_user_group;
let saved_fade_out_called = false;
let cancel_fade_to_called = false;
let instructions_fade_to_called = false;
$(saved_selector).fadeOut = function () {
$(saved_selector).fadeOut = () => {
saved_fade_out_called = true;
};
$(cancel_selector).css = function (data) {
$(cancel_selector).css = (data) => {
if (typeof data === "string") {
assert.equal(data, "display");
}
@ -276,10 +260,10 @@ test_ui("populate_user_groups", () => {
assert.equal(data.opacity, "0");
return $(cancel_selector);
};
$(cancel_selector).fadeTo = function () {
$(cancel_selector).fadeTo = () => {
cancel_fade_to_called = true;
};
$(instructions_selector).css = function (data) {
$(instructions_selector).css = (data) => {
if (typeof data === "string") {
assert.equal(data, "display");
}
@ -288,7 +272,7 @@ test_ui("populate_user_groups", () => {
assert.equal(data.opacity, "0");
return $(instructions_selector);
};
$(instructions_selector).fadeTo = function () {
$(instructions_selector).fadeTo = () => {
instructions_fade_to_called = true;
};
@ -304,7 +288,7 @@ test_ui("populate_user_groups", () => {
};
let get_by_email_called = false;
people.get_by_email = function (user_email) {
people.get_by_email = (user_email) => {
get_by_email_called = true;
if (user_email === iago.email) {
return iago;
@ -314,7 +298,7 @@ test_ui("populate_user_groups", () => {
}
throw new Error("Expected user email to be of Alice or Iago here.");
};
pills.onPillCreate = function (handler) {
pills.onPillCreate = (handler) => {
assert.equal(typeof handler, "function");
handler();
};
@ -336,7 +320,7 @@ test_ui("populate_user_groups", () => {
})();
}
pills.onPillRemove = function (handler) {
pills.onPillRemove = (handler) => {
set_global("setTimeout", (func) => {
func();
});
@ -371,27 +355,19 @@ test_ui("with_external_user", () => {
members: new Set([2, 4]),
};
user_groups.get_realm_user_groups = function () {
return [realm_user_group];
};
user_groups.get_realm_user_groups = () => [realm_user_group];
// We return noop because these are already tested, so we skip them
people.get_realm_users = function () {
return noop;
};
people.get_realm_users = () => noop;
stub_templates(() => noop);
people.get_by_user_id = function () {
return noop;
};
people.get_by_user_id = () => noop;
user_pill.append_person = function () {
return noop;
};
user_pill.append_person = () => noop;
let can_edit_called = 0;
settings_user_groups.can_edit = function () {
settings_user_groups.can_edit = () => {
can_edit_called += 1;
return false;
};
@ -404,7 +380,7 @@ test_ui("with_external_user", () => {
const name_field_stub = $.create("fake-name-field");
const description_field_stub = $.create("fake-description-field");
const input_stub = $.create("fake-input");
user_group_stub.find = function (elem) {
user_group_stub.find = (elem) => {
if (elem === ".name") {
user_group_find_called += 1;
return name_field_stub;
@ -419,7 +395,7 @@ test_ui("with_external_user", () => {
const pill_container_stub = $(`.pill-container[data-group-pills="${CSS.escape(1)}"]`);
const pill_stub = $.create("fake-pill");
let pill_container_find_called = 0;
pill_container_stub.find = function (elem) {
pill_container_stub.find = (elem) => {
if (elem === ".input") {
pill_container_find_called += 1;
return input_stub;
@ -431,14 +407,14 @@ test_ui("with_external_user", () => {
throw new Error(`Unknown element ${elem}`);
};
input_stub.css = function (property, val) {
input_stub.css = (property, val) => {
assert.equal(property, "display");
assert.equal(val, "none");
};
// Test the 'off' handlers on the pill-container
const turned_off = {};
pill_container_stub.off = function (event_name, sel) {
pill_container_stub.off = (event_name, sel) => {
if (sel === undefined) {
sel = "whole";
}
@ -448,20 +424,16 @@ test_ui("with_external_user", () => {
const exit_button = $.create("fake-pill-exit");
pill_stub.set_find_results(".exit", exit_button);
let exit_button_called = false;
exit_button.css = function (property, value) {
exit_button.css = (property, value) => {
exit_button_called = true;
assert.equal(property, "opacity");
assert.equal(value, "0.5");
};
// We return noop because these are already tested, so we skip them
pill_container_stub.children = function () {
return noop;
};
pill_container_stub.children = () => noop;
$("#user-groups").append = function () {
return noop;
};
$("#user-groups").append = () => noop;
reset_test_setup(pill_container_stub);
@ -515,7 +487,7 @@ test_ui("with_external_user", () => {
test_ui("reload", () => {
$("#user-groups").html("Some text");
let populate_user_groups_called = false;
settings_user_groups.populate_user_groups = function () {
settings_user_groups.populate_user_groups = () => {
populate_user_groups_called = true;
};
settings_user_groups.reload();
@ -530,9 +502,7 @@ test_ui("reset", () => {
});
test_ui("on_events", () => {
settings_user_groups.can_edit = function () {
return true;
};
settings_user_groups.can_edit = () => true;
(function test_admin_user_group_form_submit_triggered() {
const handler = $(".organization form.admin-user-group-form").get_on_handler("submit");
@ -551,10 +521,8 @@ test_ui("on_events", () => {
value: "fake-value",
},
];
fake_this.serializeArray = function () {
return fake_object_array;
};
channel.post = function (opts) {
fake_this.serializeArray = () => fake_object_array;
channel.post = (opts) => {
const data = {
members: "[null]",
};
@ -565,7 +533,7 @@ test_ui("on_events", () => {
(function test_post_success() {
$("#admin-user-group-status").show();
$("form.admin-user-group-form input[type='text']").val("fake-content");
ui_report.success = function (text, ele) {
ui_report.success = (text, ele) => {
assert.equal(text, "translated: User group added!");
assert.equal(ele, $("#admin-user-group-status"));
};
@ -578,7 +546,7 @@ test_ui("on_events", () => {
(function test_post_error() {
$("#admin-user-group-status").show();
ui_report.error = function (error_msg, error_obj, ele) {
ui_report.error = (error_msg, error_obj, ele) => {
const xhr = {
responseText: '{"msg":"fake-msg"}',
};
@ -604,7 +572,7 @@ test_ui("on_events", () => {
fake_this.set_parents_result(".user-group", $(".user-group"));
$(".user-group").attr("id", "1");
channel.del = function (opts) {
channel.del = (opts) => {
const data = {
id: 1,
};
@ -612,7 +580,7 @@ test_ui("on_events", () => {
assert.equal(opts.url, "/json/user_groups/1");
assert.deepEqual(opts.data, data);
settings_user_groups.reload = function () {
settings_user_groups.reload = () => {
settings_user_groups_reload_called = true;
};
opts.success();
@ -646,7 +614,7 @@ test_ui("on_events", () => {
(function test_do_not_blur() {
const blur_event_classes = [".name", ".description", ".input"];
let api_endpoint_called = false;
channel.post = function () {
channel.post = () => {
api_endpoint_called = true;
};
channel.patch = noop;
@ -665,7 +633,7 @@ test_ui("on_events", () => {
for (const blur_exception of blur_exceptions) {
api_endpoint_called = false;
fake_this.closest = function (class_name) {
fake_this.closest = (class_name) => {
if (class_name === blur_exception || class_name === user_group_selector) {
return [1];
}
@ -676,7 +644,7 @@ test_ui("on_events", () => {
}
api_endpoint_called = false;
fake_this.closest = function (class_name) {
fake_this.closest = (class_name) => {
if (class_name === ".typeahead") {
return [1];
}
@ -687,11 +655,11 @@ test_ui("on_events", () => {
// Cancel button triggers blur event.
let settings_user_groups_reload_called = false;
settings_user_groups.reload = function () {
settings_user_groups.reload = () => {
settings_user_groups_reload_called = true;
};
api_endpoint_called = false;
fake_this.closest = function (class_name) {
fake_this.closest = (class_name) => {
if (
class_name === ".save-status.btn-danger" ||
class_name === user_group_selector
@ -719,17 +687,15 @@ test_ui("on_events", () => {
description: "translated: All mobile members",
members: new Set([2, 31]),
};
user_groups.get_user_group_from_id = function () {
return group_data;
};
user_groups.get_user_group_from_id = () => group_data;
let cancel_fade_out_called = false;
let instructions_fade_out_called = false;
$(cancel_selector).show();
$(cancel_selector).fadeOut = function () {
$(cancel_selector).fadeOut = () => {
cancel_fade_out_called = true;
};
$(instructions_selector).fadeOut = function () {
$(instructions_selector).fadeOut = () => {
instructions_fade_out_called = true;
};
@ -764,20 +730,18 @@ test_ui("on_events", () => {
sib_des.text(i18n.t("All mobile members"));
const group_data = {members: new Set([2, 31])};
user_groups.get_user_group_from_id = function () {
return group_data;
};
user_groups.get_user_group_from_id = () => group_data;
let api_endpoint_called = false;
let cancel_fade_out_called = false;
let saved_fade_to_called = false;
let instructions_fade_out_called = false;
$(instructions_selector).fadeOut = function () {
$(instructions_selector).fadeOut = () => {
instructions_fade_out_called = true;
};
$(cancel_selector).fadeOut = function () {
$(cancel_selector).fadeOut = () => {
cancel_fade_out_called = true;
};
$(saved_selector).css = function (data) {
$(saved_selector).css = (data) => {
if (typeof data === "string") {
assert.equal(data, "display");
}
@ -786,12 +750,12 @@ test_ui("on_events", () => {
assert.equal(data.opacity, "0");
return $(saved_selector);
};
$(saved_selector).fadeTo = function () {
$(saved_selector).fadeTo = () => {
saved_fade_to_called = true;
return $(saved_selector);
};
channel.patch = function (opts) {
channel.patch = (opts) => {
assert.equal(opts.url, "/json/user_groups/1");
assert.equal(opts.data.name, "translated: mobile");
assert.equal(opts.data.description, "translated: All mobile members");
@ -808,7 +772,7 @@ test_ui("on_events", () => {
(function test_post_error() {
const user_group_error = $(user_group_selector + " .user-group-status");
user_group_error.show();
ui_report.error = function (error_msg, error_obj, ele) {
ui_report.error = (error_msg, error_obj, ele) => {
const xhr = {
responseText: '{"msg":"fake-msg"}',
};
@ -826,9 +790,7 @@ test_ui("on_events", () => {
};
const fake_this = $.create("fake-#user-groups_blur_name");
fake_this.closest = function () {
return [];
};
fake_this.closest = () => [];
fake_this.set_parents_result(user_group_selector, $(user_group_selector));
const event = {
relatedTarget: fake_this,
@ -860,7 +822,7 @@ test_ui("on_events", () => {
members: new Set([2, 4]),
};
user_groups.get_user_group_from_id = function (id) {
user_groups.get_user_group_from_id = (id) => {
assert.equal(id, 1);
return realm_user_group;
};
@ -868,22 +830,20 @@ test_ui("on_events", () => {
let cancel_fade_out_called = false;
let saved_fade_to_called = false;
let instructions_fade_out_called = false;
$(instructions_selector).fadeOut = function () {
$(instructions_selector).fadeOut = () => {
instructions_fade_out_called = true;
};
$(cancel_selector).fadeOut = function () {
$(cancel_selector).fadeOut = () => {
cancel_fade_out_called = true;
};
$(saved_selector).css = function () {
return $(saved_selector);
};
$(saved_selector).fadeTo = function () {
$(saved_selector).css = () => $(saved_selector);
$(saved_selector).fadeTo = () => {
saved_fade_to_called = true;
return $(saved_selector);
};
let api_endpoint_called = false;
channel.post = function (opts) {
channel.post = (opts) => {
assert.equal(opts.url, "/json/user_groups/1/members");
assert.equal(opts.data.add, "[31]");
assert.equal(opts.data.delete, "[4]");
@ -899,9 +859,7 @@ test_ui("on_events", () => {
const fake_this = $.create("fake-#user-groups_blur_input");
fake_this.set_parents_result(user_group_selector, $(user_group_selector));
fake_this.closest = function () {
return [];
};
fake_this.closest = () => [];
const event = {
relatedTarget: fake_this,
};

View File

@ -657,9 +657,7 @@ run_test("create_sub", () => {
color: "#76ce90",
};
color_data.pick_color = function () {
return "#bd86e5";
};
color_data.pick_color = () => "#bd86e5";
const india_sub = stream_data.create_sub_from_server_data(india);
assert(india_sub);

View File

@ -108,14 +108,10 @@ test_ui("subscriber_pills", () => {
)}']`;
const $sub_settings_container = $.create(sub_settings_selector);
$sub_settings_container.find = noop;
$sub_settings_container.find = function () {
return input_field_stub;
};
$sub_settings_container.find = () => input_field_stub;
const pill_container_stub = $.create(sub_settings_selector + " .pill-container");
pill_container_stub.find = function () {
return input_field_stub;
};
pill_container_stub.find = () => input_field_stub;
const $subscription_settings = $.create(".subscription_settings");
$subscription_settings.addClass = noop;
@ -141,7 +137,7 @@ test_ui("subscriber_pills", () => {
add_subscribers_request = true;
};
input_field_stub.typeahead = function (config) {
input_field_stub.typeahead = (config) => {
assert.equal(config.items, 5);
assert(config.fixed);
assert(config.dropup);
@ -159,9 +155,7 @@ test_ui("subscriber_pills", () => {
(function test_highlighter() {
const fake_stream = $.create("fake-stream");
typeahead_helper.render_stream = function () {
return fake_stream;
};
typeahead_helper.render_stream = () => fake_stream;
assert.equal(config.highlighter.call(fake_this, denmark), fake_stream);
})();
@ -175,7 +169,7 @@ test_ui("subscriber_pills", () => {
(function test_sorter() {
let sort_streams_called = false;
typeahead_helper.sort_streams = function () {
typeahead_helper.sort_streams = () => {
sort_streams_called = true;
};
config.sorter.call(fake_this);

View File

@ -7,10 +7,8 @@ const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const noop = function () {};
const return_true = function () {
return true;
};
const noop = () => {};
const return_true = () => true;
const _settings_notifications = {
update_page: () => {},
};

View File

@ -27,13 +27,9 @@ const page_params = set_global("page_params", {
stream_color.initialize();
const noop = function () {};
const return_false = function () {
return false;
};
const return_true = function () {
return true;
};
const noop = () => {};
const return_false = () => false;
const return_true = () => true;
const topic_list = set_global("topic_list", {});
set_global("overlays", {});
@ -127,7 +123,7 @@ test_ui("create_sidebar_row", (override) => {
const social_sidebar = $("<social sidebar row>");
let appended_elems;
$("#stream_filters").append = function (elems) {
$("#stream_filters").append = (elems) => {
appended_elems = elems;
};
@ -183,7 +179,7 @@ test_ui("create_sidebar_row", (override) => {
assert(social_li.hasClass("inactive_stream"));
let removed;
social_li.remove = function () {
social_li.remove = () => {
removed = true;
};
@ -466,12 +462,10 @@ test_ui("sort_streams", () => {
initialize_stream_data();
stream_data.is_active = function (sub) {
return sub.name !== "cars";
};
stream_data.is_active = (sub) => sub.name !== "cars";
let appended_elems;
$("#stream_filters").append = function (elems) {
$("#stream_filters").append = (elems) => {
appended_elems = elems;
};
@ -546,12 +540,10 @@ test_ui("separators_only_pinned_and_dormant", () => {
};
add_row(DenmarkSub);
stream_data.is_active = function (sub) {
return sub.name !== "Denmark";
};
stream_data.is_active = (sub) => sub.name !== "Denmark";
let appended_elems;
$("#stream_filters").append = function (elems) {
$("#stream_filters").append = (elems) => {
appended_elems = elems;
};
@ -596,7 +588,7 @@ test_ui("separators_only_pinned", () => {
add_row(RomeSub);
let appended_elems;
$("#stream_filters").append = function (elems) {
$("#stream_filters").append = (elems) => {
appended_elems = elems;
};

View File

@ -303,7 +303,7 @@ run_test("server_history_end_to_end", () => {
let get_success_callback;
let on_success_called;
channel.get = function (opts) {
channel.get = (opts) => {
assert.equal(opts.url, "/json/users/me/99/topics");
assert.deepEqual(opts.data, {});
get_success_callback = opts.success;

View File

@ -46,7 +46,7 @@ run_test("make_server_callback", () => {
const callback = submessage.make_server_callback(message_id);
let was_posted;
channel.post = function (opts) {
channel.post = (opts) => {
was_posted = true;
assert.deepEqual(opts, {
url: "/json/submessage",

View File

@ -103,15 +103,13 @@ run_test("redraw_left_panel", (override) => {
sub_stubs.push(sub_row);
$(sub_row).attr("data-stream-id", data.stream_id);
$(sub_row).detach = function () {
return sub_row;
};
$(sub_row).detach = () => sub_row;
}
$.create("#subscriptions_table .stream-row", {children: sub_stubs});
let ui_called = false;
ui.reset_scrollbar = function (elem) {
ui.reset_scrollbar = (elem) => {
ui_called = true;
assert.equal(elem, $("#subscription_overlay .streams-list"));
};
@ -193,11 +191,11 @@ run_test("redraw_left_panel", (override) => {
// active stream-row is not included in results
$(".stream-row-denmark").addClass("active");
$(".stream-row.active").hasClass = function (cls) {
$(".stream-row.active").hasClass = (cls) => {
assert.equal(cls, "notdisplayed");
return $(".stream-row-denmark").hasClass("active");
};
$(".stream-row.active").removeClass = function (cls) {
$(".stream-row.active").removeClass = (cls) => {
assert.equal(cls, "active");
$(".stream-row-denmark").removeClass("active");
};

View File

@ -92,12 +92,12 @@ run_test("render_date_renders_time_html", () => {
const attrs = {};
const span_stub = $("<span />");
span_stub.attr = function (name, val) {
span_stub.attr = (name, val) => {
attrs[name] = val;
return span_stub;
};
span_stub.append = function (str) {
span_stub.append = (str) => {
span_stub.html(str);
return span_stub;
};
@ -116,7 +116,7 @@ run_test("render_date_renders_time_above_html", () => {
const span_stub = $("<span />");
let appended_val;
span_stub.append = function (val) {
span_stub.append = (val) => {
appended_val = val;
return span_stub;
};
@ -228,7 +228,7 @@ run_test("set_full_datetime", () => {
const time_element = $("<span/>");
const attrs = {};
time_element.attr = function (name, val) {
time_element.attr = (name, val) => {
attrs[name] = val;
return time_element;
};

View File

@ -21,9 +21,7 @@ run_test("streams", () => {
assert.equal(actual, expected);
}
stream_sort.get_streams = function () {
return ["announce", "muted", "devel", "test here"];
};
stream_sort.get_streams = () => ["announce", "muted", "devel", "test here"];
assert_next_stream(undefined, "announce");
assert_next_stream("NOT THERE", "announce");
@ -77,9 +75,7 @@ run_test("topics", () => {
// Now test the deeper function that is wired up to
// real functions stream_data/stream_sort/unread.
stream_sort.get_streams = function () {
return ["announce", "muted", "devel", "test here"];
};
stream_sort.get_streams = () => ["announce", "muted", "devel", "test here"];
const muted_stream_id = 400;
const devel_stream_id = 401;
@ -89,7 +85,7 @@ run_test("topics", () => {
devel: devel_stream_id,
};
stream_topic_history.get_recent_topic_names = function (stream_id) {
stream_topic_history.get_recent_topic_names = (stream_id) => {
switch (stream_id) {
case muted_stream_id:
return ["ms-topic1", "ms-topic2"];
@ -100,21 +96,14 @@ run_test("topics", () => {
return [];
};
stream_data.get_stream_id = function (stream_name) {
return stream_id_dct[stream_name];
};
stream_data.get_stream_id = (stream_name) => stream_id_dct[stream_name];
stream_data.is_stream_muted_by_name = function (stream_name) {
return stream_name === "muted";
};
stream_data.is_stream_muted_by_name = (stream_name) => stream_name === "muted";
unread.topic_has_any_unread = function (stream_id) {
return [devel_stream_id, muted_stream_id].includes(stream_id);
};
unread.topic_has_any_unread = (stream_id) =>
[devel_stream_id, muted_stream_id].includes(stream_id);
muting.is_topic_muted = function (stream_name, topic) {
return topic === "muted";
};
muting.is_topic_muted = (stream_name, topic) => topic === "muted";
let next_item = tg.get_next_topic("announce", "whatever");
assert.deepEqual(next_item, {
@ -130,11 +119,9 @@ run_test("topics", () => {
});
run_test("get_next_unread_pm_string", () => {
pm_conversations.recent.get_strings = function () {
return ["1", "read", "2,3", "4", "unk"];
};
pm_conversations.recent.get_strings = () => ["1", "read", "2,3", "4", "unk"];
unread.num_unread_for_person = function (user_ids_string) {
unread.num_unread_for_person = (user_ids_string) => {
if (user_ids_string === "unk") {
return undefined;
}

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const noop = function () {};
const noop = () => {};
const page_params = set_global("page_params", {});
const channel = set_global("channel", {});
@ -21,13 +21,13 @@ const transmit = zrequire("transmit");
run_test("transmit_message_ajax", () => {
let success_func_called;
const success = function () {
const success = () => {
success_func_called = true;
};
const request = {foo: "bar"};
channel.post = function (opts) {
channel.post = (opts) => {
assert.equal(opts.url, "/json/messages");
assert.equal(opts.data.foo, "bar");
opts.success();
@ -37,12 +37,12 @@ run_test("transmit_message_ajax", () => {
assert(success_func_called);
channel.xhr_error_message = function (msg) {
channel.xhr_error_message = (msg) => {
assert.equal(msg, "Error sending message");
return msg;
};
channel.post = function (opts) {
channel.post = (opts) => {
assert.equal(opts.url, "/json/messages");
assert.equal(opts.data.foo, "bar");
const xhr = "whatever";
@ -50,7 +50,7 @@ run_test("transmit_message_ajax", () => {
};
let error_func_called;
const error = function (response) {
const error = (response) => {
assert.equal(response, "Error sending message");
error_func_called = true;
};
@ -59,16 +59,14 @@ run_test("transmit_message_ajax", () => {
});
run_test("transmit_message_ajax_reload_pending", () => {
const success = function () {
const success = () => {
throw new Error("unexpected success");
};
reload_state.is_pending = function () {
return true;
};
reload_state.is_pending = () => true;
let reload_initiated;
reload.initiate = function (opts) {
reload.initiate = (opts) => {
reload_initiated = true;
assert.deepEqual(opts, {
immediate: true,
@ -82,13 +80,13 @@ run_test("transmit_message_ajax_reload_pending", () => {
const request = {foo: "bar"};
let error_func_called;
const error = function (response) {
const error = (response) => {
assert.equal(response, "Error sending message");
error_func_called = true;
};
error_func_called = false;
channel.post = function (opts) {
channel.post = (opts) => {
assert.equal(opts.url, "/json/messages");
assert.equal(opts.data.foo, "bar");
const xhr = "whatever";

View File

@ -715,7 +715,7 @@ function make_jquery_helper() {
const stream_filters = jquery_elem();
let appended_data;
stream_filters.append = function (data) {
stream_filters.append = (data) => {
appended_data = data;
};

View File

@ -80,9 +80,7 @@ run_test("sort_streams", () => {
},
];
stream_data.is_active = function (sub) {
return sub.name !== "dead";
};
stream_data.is_active = (sub) => sub.name !== "dead";
test_streams = th.sort_streams(test_streams, "d");
assert.deepEqual(test_streams[0].name, "Denmark"); // Pinned streams first

View File

@ -241,7 +241,7 @@ run_test("basics", () => {
// Switch to bob now.
worker.get_current_time = returns_time(171);
worker.notify_server_start = function (recipient) {
worker.notify_server_start = (recipient) => {
assert.equal(recipient, "bob");
events.started = true;
};

View File

@ -182,9 +182,7 @@ run_test("changing_topics", () => {
message_dict.set(other_message.id, other_message);
message_dict.set(sticky_message.id, sticky_message);
message_store.get = function (msg_id) {
return message_dict.get(msg_id);
};
message_store.get = (msg_id) => message_dict.get(msg_id);
unread.process_loaded_messages([sticky_message]);
count = unread.num_unread_for_topic(stream_id, "sticky");
@ -260,7 +258,7 @@ run_test("num_unread_for_topic", () => {
const stream_id = 301;
stream_data.get_sub_by_id = function (arg) {
stream_data.get_sub_by_id = (arg) => {
if (arg === stream_id) {
return {name: "Some Stream"};
}
@ -329,20 +327,14 @@ run_test("num_unread_for_topic", () => {
});
run_test("home_messages", () => {
stream_data.is_subscribed = function () {
return true;
};
stream_data.is_muted = function () {
return false;
};
stream_data.is_subscribed = () => true;
stream_data.is_muted = () => false;
const stream_id = 401;
stream_data.get_sub_by_id = function () {
return {
name: "whatever",
};
};
stream_data.get_sub_by_id = () => ({
name: "whatever",
});
const message = {
id: 15,
@ -373,9 +365,7 @@ run_test("home_messages", () => {
test_notifiable_count(counts.home_unread_messages, 0);
// Now unsubscribe all our streams.
stream_data.is_subscribed = function () {
return false;
};
stream_data.is_subscribed = () => false;
counts = unread.get_counts();
assert.equal(counts.home_unread_messages, 0);
test_notifiable_count(counts.home_unread_messages, 0);
@ -389,9 +379,7 @@ run_test("phantom_messages", () => {
topic: "phantom",
};
stream_data.get_sub_by_id = function () {
return;
};
stream_data.get_sub_by_id = () => {};
unread.mark_as_read(message.id);
const counts = unread.get_counts();

View File

@ -110,7 +110,7 @@ run_test("updates", () => {
let user_id;
let full_name;
message_live_update.update_user_full_name = function (user_id_arg, full_name_arg) {
message_live_update.update_user_full_name = (user_id_arg, full_name_arg) => {
user_id = user_id_arg;
full_name = full_name_arg;
};
@ -144,7 +144,7 @@ run_test("updates", () => {
assert.equal(person.full_name, "Me V2");
let avatar_url;
message_live_update.update_avatar = function (user_id_arg, avatar_url_arg) {
message_live_update.update_avatar = (user_id_arg, avatar_url_arg) => {
user_id = user_id_arg;
avatar_url = avatar_url_arg;
};