mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
node tests: Eliminate many __Rewire__ calls.
For most functions that we were using __Rewire__ for,
it's better to just use the override helper, which
use __Rewire__ under the hood, but also resets
the reference at the end of run_tests.
Another nice thing about override() is that it reports
when you never actually needed the mock, and this
commit fixes the instances found here.
I didn't replace every call to __Rewire__. The
remaining ones fall under these categories:
* I looked for ") =>" in my code sweep,
so I missed stuff like "noop" helpers.
* Sometimes we directly update something
in a module that's not a function. This
is generally evil, and we should use setters.
* Some tests have setup() helpers or similar
that complicated this code sweep, so I
simply punted.
* Somes modules rely on intra-test leaks. We
should fix those, but I just punted for the
main code sweep.
This commit is contained in:
committed by
Steve Howell
parent
8ab5475b37
commit
9c8fa3930f
@@ -602,7 +602,7 @@ test_ui("searching", () => {
|
|||||||
assert.equal(activity.searching(), false);
|
assert.equal(activity.searching(), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("update_presence_info", () => {
|
test_ui("update_presence_info", (override) => {
|
||||||
page_params.realm_presence_disabled = false;
|
page_params.realm_presence_disabled = false;
|
||||||
|
|
||||||
const server_time = 500;
|
const server_time = 500;
|
||||||
@@ -613,7 +613,7 @@ test_ui("update_presence_info", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
buddy_data.__Rewire__("matches_filter", () => true);
|
override(buddy_data, "matches_filter", () => true);
|
||||||
|
|
||||||
const alice_li = $.create("alice stub");
|
const alice_li = $.create("alice stub");
|
||||||
buddy_list_add(alice.user_id, alice_li);
|
buddy_list_add(alice.user_id, alice_li);
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ run_test("copy_data_attribute_value", (override) => {
|
|||||||
assert(faded_out);
|
assert(faded_out);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("adjust_mac_shortcuts non-mac", () => {
|
run_test("adjust_mac_shortcuts non-mac", (override) => {
|
||||||
common.__Rewire__("has_mac_keyboard", () => false);
|
override(common, "has_mac_keyboard", () => false);
|
||||||
|
|
||||||
// The adjust_mac_shortcuts has a really simple guard
|
// The adjust_mac_shortcuts has a really simple guard
|
||||||
// at the top, and we just test the early-return behavior
|
// at the top, and we just test the early-return behavior
|
||||||
@@ -79,7 +79,7 @@ run_test("adjust_mac_shortcuts non-mac", () => {
|
|||||||
common.adjust_mac_shortcuts("selector-that-does-not-exist");
|
common.adjust_mac_shortcuts("selector-that-does-not-exist");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("adjust_mac_shortcuts mac", () => {
|
run_test("adjust_mac_shortcuts mac", (override) => {
|
||||||
const keys_to_test_mac = new Map([
|
const keys_to_test_mac = new Map([
|
||||||
["Backspace", "Delete"],
|
["Backspace", "Delete"],
|
||||||
["Enter", "Return"],
|
["Enter", "Return"],
|
||||||
@@ -95,7 +95,7 @@ run_test("adjust_mac_shortcuts mac", () => {
|
|||||||
["Ctrl + Backspace + End", "⌘ + Delete + Fn + →"],
|
["Ctrl + Backspace + End", "⌘ + Delete + Fn + →"],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
common.__Rewire__("has_mac_keyboard", () => true);
|
override(common, "has_mac_keyboard", () => true);
|
||||||
|
|
||||||
const test_items = [];
|
const test_items = [];
|
||||||
let key_no = 1;
|
let key_no = 1;
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ test_ui("test_wildcard_mention_allowed", () => {
|
|||||||
assert(!compose.wildcard_mention_allowed());
|
assert(!compose.wildcard_mention_allowed());
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("validate_stream_message", () => {
|
test_ui("validate_stream_message", (override) => {
|
||||||
// This test is in kind of continuation to test_validate but since it is
|
// This test is in kind of continuation to test_validate but since it is
|
||||||
// primarily used to get coverage over functions called from validate()
|
// primarily used to get coverage over functions called from validate()
|
||||||
// we are separating it up in different test. Though their relative position
|
// we are separating it up in different test. Though their relative position
|
||||||
@@ -394,7 +394,7 @@ test_ui("validate_stream_message", () => {
|
|||||||
compose_content = data;
|
compose_content = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
compose.__Rewire__("wildcard_mention_allowed", () => true);
|
override(compose, "wildcard_mention_allowed", () => true);
|
||||||
compose_state.message_content("Hey @**all**");
|
compose_state.message_content("Hey @**all**");
|
||||||
assert(!compose.validate());
|
assert(!compose.validate());
|
||||||
assert.equal($("#compose-send-button").prop("disabled"), false);
|
assert.equal($("#compose-send-button").prop("disabled"), false);
|
||||||
@@ -402,7 +402,7 @@ test_ui("validate_stream_message", () => {
|
|||||||
assert.equal(compose_content, "compose_all_everyone_stub");
|
assert.equal(compose_content, "compose_all_everyone_stub");
|
||||||
assert($("#compose-all-everyone").visible());
|
assert($("#compose-all-everyone").visible());
|
||||||
|
|
||||||
compose.__Rewire__("wildcard_mention_allowed", () => false);
|
override(compose, "wildcard_mention_allowed", () => false);
|
||||||
assert(!compose.validate());
|
assert(!compose.validate());
|
||||||
assert.equal(
|
assert.equal(
|
||||||
$("#compose-error-msg").html(),
|
$("#compose-error-msg").html(),
|
||||||
@@ -473,14 +473,14 @@ test_ui("test_validate_stream_message_post_policy_full_members_only", () => {
|
|||||||
page_params.is_guest = false;
|
page_params.is_guest = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("markdown_rtl", () => {
|
test_ui("markdown_rtl", (override) => {
|
||||||
const textarea = $("#compose-textarea");
|
const textarea = $("#compose-textarea");
|
||||||
|
|
||||||
const event = {
|
const event = {
|
||||||
keyCode: 65, // A
|
keyCode: 65, // A
|
||||||
};
|
};
|
||||||
|
|
||||||
rtl.__Rewire__("get_direction", (text) => {
|
override(rtl, "get_direction", (text) => {
|
||||||
assert.equal(text, " foo");
|
assert.equal(text, " foo");
|
||||||
return "rtl";
|
return "rtl";
|
||||||
});
|
});
|
||||||
@@ -493,10 +493,6 @@ test_ui("markdown_rtl", () => {
|
|||||||
assert.equal(textarea.hasClass("rtl"), true);
|
assert.equal(textarea.hasClass("rtl"), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// This is important for subsequent tests--put
|
|
||||||
// us back to the "normal" ltr case.
|
|
||||||
rtl.__Rewire__("get_direction", () => "ltr");
|
|
||||||
|
|
||||||
test_ui("markdown_ltr", () => {
|
test_ui("markdown_ltr", () => {
|
||||||
const textarea = $("#compose-textarea");
|
const textarea = $("#compose-textarea");
|
||||||
|
|
||||||
@@ -721,7 +717,7 @@ test_ui("send_message", (override) => {
|
|||||||
compose_state.topic("");
|
compose_state.topic("");
|
||||||
compose_state.set_message_type("private");
|
compose_state.set_message_type("private");
|
||||||
page_params.user_id = 101;
|
page_params.user_id = 101;
|
||||||
compose_state.__Rewire__("private_message_recipient", () => "alice@example.com");
|
override(compose_state, "private_message_recipient", () => "alice@example.com");
|
||||||
|
|
||||||
const server_message_id = 127;
|
const server_message_id = 127;
|
||||||
local_message.insert_message = (message) => {
|
local_message.insert_message = (message) => {
|
||||||
@@ -847,7 +843,7 @@ test_ui("send_message", (override) => {
|
|||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("enter_with_preview_open", () => {
|
test_ui("enter_with_preview_open", (override) => {
|
||||||
// Test sending a message with content.
|
// Test sending a message with content.
|
||||||
compose_state.set_message_type("stream");
|
compose_state.set_message_type("stream");
|
||||||
$("#compose-textarea").val("message me");
|
$("#compose-textarea").val("message me");
|
||||||
@@ -857,7 +853,7 @@ test_ui("enter_with_preview_open", () => {
|
|||||||
$("#markdown_preview").hide();
|
$("#markdown_preview").hide();
|
||||||
page_params.enter_sends = true;
|
page_params.enter_sends = true;
|
||||||
let send_message_called = false;
|
let send_message_called = false;
|
||||||
compose.__Rewire__("send_message", () => {
|
override(compose, "send_message", () => {
|
||||||
send_message_called = true;
|
send_message_called = true;
|
||||||
});
|
});
|
||||||
compose.enter_with_preview_open();
|
compose.enter_with_preview_open();
|
||||||
@@ -884,7 +880,7 @@ test_ui("enter_with_preview_open", () => {
|
|||||||
assert.equal($("#compose-error-msg").html(), i18n.t("You have nothing to send!"));
|
assert.equal($("#compose-error-msg").html(), i18n.t("You have nothing to send!"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("finish", () => {
|
test_ui("finish", (override) => {
|
||||||
(function test_when_compose_validation_fails() {
|
(function test_when_compose_validation_fails() {
|
||||||
$("#compose_invite_users").show();
|
$("#compose_invite_users").show();
|
||||||
$("#compose-send-button").prop("disabled", false);
|
$("#compose-send-button").prop("disabled", false);
|
||||||
@@ -908,14 +904,14 @@ test_ui("finish", () => {
|
|||||||
$("#markdown_preview").hide();
|
$("#markdown_preview").hide();
|
||||||
$("#compose-textarea").val("foobarfoobar");
|
$("#compose-textarea").val("foobarfoobar");
|
||||||
compose_state.set_message_type("private");
|
compose_state.set_message_type("private");
|
||||||
compose_state.__Rewire__("private_message_recipient", () => "bob@example.com");
|
override(compose_state, "private_message_recipient", () => "bob@example.com");
|
||||||
|
|
||||||
let compose_finished_event_checked = false;
|
let compose_finished_event_checked = false;
|
||||||
$(document).on("compose_finished.zulip", () => {
|
$(document).on("compose_finished.zulip", () => {
|
||||||
compose_finished_event_checked = true;
|
compose_finished_event_checked = true;
|
||||||
});
|
});
|
||||||
let send_message_called = false;
|
let send_message_called = false;
|
||||||
compose.__Rewire__("send_message", () => {
|
override(compose, "send_message", () => {
|
||||||
send_message_called = true;
|
send_message_called = true;
|
||||||
});
|
});
|
||||||
assert(compose.finish());
|
assert(compose.finish());
|
||||||
@@ -1027,7 +1023,7 @@ test_ui("initialize", (override) => {
|
|||||||
|
|
||||||
let setup_upload_called = false;
|
let setup_upload_called = false;
|
||||||
let uppy_cancel_all_called = false;
|
let uppy_cancel_all_called = false;
|
||||||
upload.__Rewire__("setup_upload", (config) => {
|
override(upload, "setup_upload", (config) => {
|
||||||
assert.equal(config.mode, "compose");
|
assert.equal(config.mode, "compose");
|
||||||
setup_upload_called = true;
|
setup_upload_called = true;
|
||||||
return {
|
return {
|
||||||
@@ -1112,7 +1108,7 @@ test_ui("update_fade", (override) => {
|
|||||||
assert(update_all_called);
|
assert(update_all_called);
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("trigger_submit_compose_form", () => {
|
test_ui("trigger_submit_compose_form", (override) => {
|
||||||
let prevent_default_checked = false;
|
let prevent_default_checked = false;
|
||||||
let compose_finish_checked = false;
|
let compose_finish_checked = false;
|
||||||
const e = {
|
const e = {
|
||||||
@@ -1120,7 +1116,7 @@ test_ui("trigger_submit_compose_form", () => {
|
|||||||
prevent_default_checked = true;
|
prevent_default_checked = true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
compose.__Rewire__("finish", () => {
|
override(compose, "finish", () => {
|
||||||
compose_finish_checked = true;
|
compose_finish_checked = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1167,7 +1163,7 @@ test_ui("needs_subscribe_warning", () => {
|
|||||||
assert.equal(compose.needs_subscribe_warning(bob.user_id, sub.stream_id), true);
|
assert.equal(compose.needs_subscribe_warning(bob.user_id, sub.stream_id), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("warn_if_mentioning_unsubscribed_user", () => {
|
test_ui("warn_if_mentioning_unsubscribed_user", (override) => {
|
||||||
let mentioned = {
|
let mentioned = {
|
||||||
email: "foo@bar.com",
|
email: "foo@bar.com",
|
||||||
};
|
};
|
||||||
@@ -1211,7 +1207,7 @@ test_ui("warn_if_mentioning_unsubscribed_user", () => {
|
|||||||
const checks = [
|
const checks = [
|
||||||
(function () {
|
(function () {
|
||||||
let called;
|
let called;
|
||||||
compose.__Rewire__("needs_subscribe_warning", (user_id, stream_id) => {
|
override(compose, "needs_subscribe_warning", (user_id, stream_id) => {
|
||||||
called = true;
|
called = true;
|
||||||
assert.equal(user_id, 34);
|
assert.equal(user_id, 34);
|
||||||
assert.equal(stream_id, 111);
|
assert.equal(stream_id, 111);
|
||||||
@@ -1291,7 +1287,7 @@ test_ui("warn_if_mentioning_unsubscribed_user", () => {
|
|||||||
assert(looked_for_existing);
|
assert(looked_for_existing);
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("on_events", () => {
|
test_ui("on_events", (override) => {
|
||||||
function setup_parents_and_mock_remove(container_sel, target_sel, parent) {
|
function setup_parents_and_mock_remove(container_sel, target_sel, parent) {
|
||||||
const container = $.create("fake " + container_sel);
|
const container = $.create("fake " + container_sel);
|
||||||
let container_removed = false;
|
let container_removed = false;
|
||||||
@@ -1335,7 +1331,7 @@ test_ui("on_events", () => {
|
|||||||
$("#compose-send-status").show();
|
$("#compose-send-status").show();
|
||||||
|
|
||||||
let compose_finish_checked = false;
|
let compose_finish_checked = false;
|
||||||
compose.__Rewire__("finish", () => {
|
override(compose, "finish", () => {
|
||||||
compose_finish_checked = true;
|
compose_finish_checked = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1633,7 +1629,7 @@ test_ui("on_events", () => {
|
|||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("create_message_object", () => {
|
test_ui("create_message_object", (override) => {
|
||||||
const sub = {
|
const sub = {
|
||||||
stream_id: 101,
|
stream_id: 101,
|
||||||
name: "social",
|
name: "social",
|
||||||
@@ -1645,7 +1641,7 @@ test_ui("create_message_object", () => {
|
|||||||
$("#stream_message_recipient_topic").val("lunch");
|
$("#stream_message_recipient_topic").val("lunch");
|
||||||
$("#compose-textarea").val("burrito");
|
$("#compose-textarea").val("burrito");
|
||||||
|
|
||||||
compose_state.__Rewire__("get_message_type", () => "stream");
|
override(compose_state, "get_message_type", () => "stream");
|
||||||
|
|
||||||
let message = compose.create_message_object();
|
let message = compose.create_message_object();
|
||||||
assert.equal(message.to, sub.stream_id);
|
assert.equal(message.to, sub.stream_id);
|
||||||
@@ -1660,7 +1656,7 @@ test_ui("create_message_object", () => {
|
|||||||
assert.equal(message.topic, "lunch");
|
assert.equal(message.topic, "lunch");
|
||||||
assert.equal(message.content, "burrito");
|
assert.equal(message.content, "burrito");
|
||||||
|
|
||||||
compose_state.__Rewire__("get_message_type", () => "private");
|
override(compose_state, "get_message_type", () => "private");
|
||||||
compose_state.__Rewire__(
|
compose_state.__Rewire__(
|
||||||
"private_message_recipient",
|
"private_message_recipient",
|
||||||
() => "alice@example.com, bob@example.com",
|
() => "alice@example.com, bob@example.com",
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ run_test("start", (override) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let abort_xhr_called = false;
|
let abort_xhr_called = false;
|
||||||
compose.__Rewire__("abort_xhr", () => {
|
override(compose, "abort_xhr", () => {
|
||||||
abort_xhr_called = true;
|
abort_xhr_called = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -318,7 +318,7 @@ run_test("quote_and_reply", (override) => {
|
|||||||
|
|
||||||
current_msg_list.selected_id = () => 100;
|
current_msg_list.selected_id = () => 100;
|
||||||
|
|
||||||
compose_ui.__Rewire__("insert_syntax_and_focus", (syntax) => {
|
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||||
assert.equal(syntax, "[Quoting…]\n");
|
assert.equal(syntax, "[Quoting…]\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -388,18 +388,18 @@ run_test("get_focus_area", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("focus_in_empty_compose", () => {
|
run_test("focus_in_empty_compose", (override) => {
|
||||||
$("#compose-textarea").is = (attr) => {
|
$("#compose-textarea").is = (attr) => {
|
||||||
assert.equal(attr, ":focus");
|
assert.equal(attr, ":focus");
|
||||||
return $("#compose-textarea").is_focused;
|
return $("#compose-textarea").is_focused;
|
||||||
};
|
};
|
||||||
|
|
||||||
compose_state.__Rewire__("composing", () => true);
|
override(compose_state, "composing", () => true);
|
||||||
$("#compose-textarea").val("");
|
$("#compose-textarea").val("");
|
||||||
$("#compose-textarea").trigger("focus");
|
$("#compose-textarea").trigger("focus");
|
||||||
assert(compose_state.focus_in_empty_compose());
|
assert(compose_state.focus_in_empty_compose());
|
||||||
|
|
||||||
compose_state.__Rewire__("composing", () => false);
|
override(compose_state, "composing", () => false);
|
||||||
assert(!compose_state.focus_in_empty_compose());
|
assert(!compose_state.focus_in_empty_compose());
|
||||||
|
|
||||||
$("#compose-textarea").val("foo");
|
$("#compose-textarea").val("foo");
|
||||||
@@ -420,7 +420,7 @@ run_test("on_narrow", (override) => {
|
|||||||
override(compose_state, "has_message_content", () => has_message_content);
|
override(compose_state, "has_message_content", () => has_message_content);
|
||||||
|
|
||||||
let cancel_called = false;
|
let cancel_called = false;
|
||||||
compose_actions.__Rewire__("cancel", () => {
|
override(compose_actions, "cancel", () => {
|
||||||
cancel_called = true;
|
cancel_called = true;
|
||||||
});
|
});
|
||||||
compose_actions.on_narrow({
|
compose_actions.on_narrow({
|
||||||
@@ -429,7 +429,7 @@ run_test("on_narrow", (override) => {
|
|||||||
assert(cancel_called);
|
assert(cancel_called);
|
||||||
|
|
||||||
let on_topic_narrow_called = false;
|
let on_topic_narrow_called = false;
|
||||||
compose_actions.__Rewire__("on_topic_narrow", () => {
|
override(compose_actions, "on_topic_narrow", () => {
|
||||||
on_topic_narrow_called = true;
|
on_topic_narrow_called = true;
|
||||||
});
|
});
|
||||||
narrowed_by_topic_reply = true;
|
narrowed_by_topic_reply = true;
|
||||||
@@ -451,7 +451,7 @@ run_test("on_narrow", (override) => {
|
|||||||
|
|
||||||
has_message_content = false;
|
has_message_content = false;
|
||||||
let start_called = false;
|
let start_called = false;
|
||||||
compose_actions.__Rewire__("start", () => {
|
override(compose_actions, "start", () => {
|
||||||
start_called = true;
|
start_called = true;
|
||||||
});
|
});
|
||||||
narrowed_by_pm_reply = true;
|
narrowed_by_pm_reply = true;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ run_test("videos", (override) => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
compose_ui.__Rewire__("insert_syntax_and_focus", () => {
|
override(compose_ui, "insert_syntax_and_focus", () => {
|
||||||
called = true;
|
called = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ run_test("videos", (override) => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
compose_ui.__Rewire__("insert_syntax_and_focus", (syntax) => {
|
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||||
syntax_to_insert = syntax;
|
syntax_to_insert = syntax;
|
||||||
called = true;
|
called = true;
|
||||||
});
|
});
|
||||||
@@ -139,7 +139,7 @@ run_test("videos", (override) => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
compose_ui.__Rewire__("insert_syntax_and_focus", (syntax) => {
|
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||||
syntax_to_insert = syntax;
|
syntax_to_insert = syntax;
|
||||||
called = true;
|
called = true;
|
||||||
});
|
});
|
||||||
@@ -184,7 +184,7 @@ run_test("videos", (override) => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
compose_ui.__Rewire__("insert_syntax_and_focus", (syntax) => {
|
override(compose_ui, "insert_syntax_and_focus", (syntax) => {
|
||||||
syntax_to_insert = syntax;
|
syntax_to_insert = syntax;
|
||||||
called = true;
|
called = true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -551,7 +551,7 @@ function sorted_names_from(subs) {
|
|||||||
return subs.map((sub) => sub.name).sort();
|
return subs.map((sub) => sub.name).sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test("initialize", () => {
|
run_test("initialize", (override) => {
|
||||||
let expected_value;
|
let expected_value;
|
||||||
|
|
||||||
let stream_typeahead_called = false;
|
let stream_typeahead_called = false;
|
||||||
@@ -659,7 +659,7 @@ run_test("initialize", () => {
|
|||||||
let pm_recipient_typeahead_called = false;
|
let pm_recipient_typeahead_called = false;
|
||||||
$("#private_message_recipient").typeahead = (options) => {
|
$("#private_message_recipient").typeahead = (options) => {
|
||||||
let inserted_users = [];
|
let inserted_users = [];
|
||||||
user_pill.__Rewire__("get_user_ids", () => inserted_users);
|
override(user_pill, "get_user_ids", () => inserted_users);
|
||||||
|
|
||||||
// This should match the users added at the beginning of this test file.
|
// This should match the users added at the beginning of this test file.
|
||||||
let actual_value = options.source("");
|
let actual_value = options.source("");
|
||||||
@@ -788,7 +788,7 @@ run_test("initialize", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let appended_name;
|
let appended_name;
|
||||||
compose_pm_pill.__Rewire__("set_from_typeahead", (item) => {
|
override(compose_pm_pill, "set_from_typeahead", (item) => {
|
||||||
appended_name = item.full_name;
|
appended_name = item.full_name;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -810,7 +810,7 @@ run_test("initialize", () => {
|
|||||||
|
|
||||||
let appended_names = [];
|
let appended_names = [];
|
||||||
|
|
||||||
compose_pm_pill.__Rewire__("set_from_typeahead", (item) => {
|
override(compose_pm_pill, "set_from_typeahead", (item) => {
|
||||||
appended_names.push(item.full_name);
|
appended_names.push(item.full_name);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -954,13 +954,13 @@ run_test("initialize", () => {
|
|||||||
subscribed: false,
|
subscribed: false,
|
||||||
};
|
};
|
||||||
// Subscribed stream is active
|
// Subscribed stream is active
|
||||||
stream_data.__Rewire__("is_active", () => false);
|
override(stream_data, "is_active", () => false);
|
||||||
fake_this = {completing: "stream", token: "s"};
|
fake_this = {completing: "stream", token: "s"};
|
||||||
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
|
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
|
||||||
expected_value = [sweden_stream, serbia_stream];
|
expected_value = [sweden_stream, serbia_stream];
|
||||||
assert.deepEqual(actual_value, expected_value);
|
assert.deepEqual(actual_value, expected_value);
|
||||||
// Subscribed stream is inactive
|
// Subscribed stream is inactive
|
||||||
stream_data.__Rewire__("is_active", () => true);
|
override(stream_data, "is_active", () => true);
|
||||||
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
|
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
|
||||||
expected_value = [sweden_stream, serbia_stream];
|
expected_value = [sweden_stream, serbia_stream];
|
||||||
assert.deepEqual(actual_value, expected_value);
|
assert.deepEqual(actual_value, expected_value);
|
||||||
@@ -1119,7 +1119,7 @@ run_test("initialize", () => {
|
|||||||
assert(compose_textarea_typeahead_called);
|
assert(compose_textarea_typeahead_called);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("begins_typeahead", () => {
|
run_test("begins_typeahead", (override) => {
|
||||||
const begin_typehead_this = {
|
const begin_typehead_this = {
|
||||||
options: {
|
options: {
|
||||||
completions: {
|
completions: {
|
||||||
@@ -1137,7 +1137,7 @@ run_test("begins_typeahead", () => {
|
|||||||
|
|
||||||
function get_values(input, rest) {
|
function get_values(input, rest) {
|
||||||
// Stub out split_at_cursor that uses $(':focus')
|
// Stub out split_at_cursor that uses $(':focus')
|
||||||
ct.__Rewire__("split_at_cursor", () => [input, rest]);
|
override(ct, "split_at_cursor", () => [input, rest]);
|
||||||
const values = ct.get_candidates.call(begin_typehead_this, input);
|
const values = ct.get_candidates.call(begin_typehead_this, input);
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
@@ -1354,11 +1354,11 @@ run_test("tokenizing", () => {
|
|||||||
assert.equal(ct.tokenize_compose_str("foo #streams@foo"), "#streams@foo");
|
assert.equal(ct.tokenize_compose_str("foo #streams@foo"), "#streams@foo");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("content_highlighter", () => {
|
run_test("content_highlighter", (override) => {
|
||||||
let fake_this = {completing: "emoji"};
|
let fake_this = {completing: "emoji"};
|
||||||
const emoji = {emoji_name: "person shrugging", emoji_url: "¯\\_(ツ)_/¯"};
|
const emoji = {emoji_name: "person shrugging", emoji_url: "¯\\_(ツ)_/¯"};
|
||||||
let th_render_typeahead_item_called = false;
|
let th_render_typeahead_item_called = false;
|
||||||
typeahead_helper.__Rewire__("render_emoji", (item) => {
|
override(typeahead_helper, "render_emoji", (item) => {
|
||||||
assert.deepEqual(item, emoji);
|
assert.deepEqual(item, emoji);
|
||||||
th_render_typeahead_item_called = true;
|
th_render_typeahead_item_called = true;
|
||||||
});
|
});
|
||||||
@@ -1366,14 +1366,14 @@ run_test("content_highlighter", () => {
|
|||||||
|
|
||||||
fake_this = {completing: "mention"};
|
fake_this = {completing: "mention"};
|
||||||
let th_render_person_called = false;
|
let th_render_person_called = false;
|
||||||
typeahead_helper.__Rewire__("render_person", (person) => {
|
override(typeahead_helper, "render_person", (person) => {
|
||||||
assert.deepEqual(person, othello);
|
assert.deepEqual(person, othello);
|
||||||
th_render_person_called = true;
|
th_render_person_called = true;
|
||||||
});
|
});
|
||||||
ct.content_highlighter.call(fake_this, othello);
|
ct.content_highlighter.call(fake_this, othello);
|
||||||
|
|
||||||
let th_render_user_group_called = false;
|
let th_render_user_group_called = false;
|
||||||
typeahead_helper.__Rewire__("render_user_group", (user_group) => {
|
override(typeahead_helper, "render_user_group", (user_group) => {
|
||||||
assert.deepEqual(user_group, backend);
|
assert.deepEqual(user_group, backend);
|
||||||
th_render_user_group_called = true;
|
th_render_user_group_called = true;
|
||||||
});
|
});
|
||||||
@@ -1385,7 +1385,7 @@ run_test("content_highlighter", () => {
|
|||||||
const me_slash = {
|
const me_slash = {
|
||||||
text: "/me is excited (Display action text)",
|
text: "/me is excited (Display action text)",
|
||||||
};
|
};
|
||||||
typeahead_helper.__Rewire__("render_typeahead_item", (item) => {
|
override(typeahead_helper, "render_typeahead_item", (item) => {
|
||||||
assert.deepEqual(item, {
|
assert.deepEqual(item, {
|
||||||
primary: "/me is excited (Display action text)",
|
primary: "/me is excited (Display action text)",
|
||||||
});
|
});
|
||||||
@@ -1395,7 +1395,7 @@ run_test("content_highlighter", () => {
|
|||||||
|
|
||||||
fake_this = {completing: "stream"};
|
fake_this = {completing: "stream"};
|
||||||
let th_render_stream_called = false;
|
let th_render_stream_called = false;
|
||||||
typeahead_helper.__Rewire__("render_stream", (stream) => {
|
override(typeahead_helper, "render_stream", (stream) => {
|
||||||
assert.deepEqual(stream, denmark_stream);
|
assert.deepEqual(stream, denmark_stream);
|
||||||
th_render_stream_called = true;
|
th_render_stream_called = true;
|
||||||
});
|
});
|
||||||
@@ -1403,7 +1403,7 @@ run_test("content_highlighter", () => {
|
|||||||
|
|
||||||
fake_this = {completing: "syntax"};
|
fake_this = {completing: "syntax"};
|
||||||
th_render_typeahead_item_called = false;
|
th_render_typeahead_item_called = false;
|
||||||
typeahead_helper.__Rewire__("render_typeahead_item", (item) => {
|
override(typeahead_helper, "render_typeahead_item", (item) => {
|
||||||
assert.deepEqual(item, {primary: "py"});
|
assert.deepEqual(item, {primary: "py"});
|
||||||
th_render_typeahead_item_called = true;
|
th_render_typeahead_item_called = true;
|
||||||
});
|
});
|
||||||
@@ -1516,7 +1516,6 @@ run_test("typeahead_results", () => {
|
|||||||
run_test("message people", () => {
|
run_test("message people", () => {
|
||||||
let results;
|
let results;
|
||||||
|
|
||||||
compose_state.__Rewire__("stream_name", () => undefined);
|
|
||||||
ct.__Rewire__("max_num_items", 2);
|
ct.__Rewire__("max_num_items", 2);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -158,11 +158,11 @@ run_test("snapshot_message", (override) => {
|
|||||||
assert.equal(drafts.snapshot_message(), undefined);
|
assert.equal(drafts.snapshot_message(), undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("initialize", () => {
|
run_test("initialize", (override) => {
|
||||||
window.addEventListener = (event_name, f) => {
|
window.addEventListener = (event_name, f) => {
|
||||||
assert.equal(event_name, "beforeunload");
|
assert.equal(event_name, "beforeunload");
|
||||||
let called = false;
|
let called = false;
|
||||||
drafts.__Rewire__("update_draft", () => {
|
override(drafts, "update_draft", () => {
|
||||||
called = true;
|
called = true;
|
||||||
});
|
});
|
||||||
f();
|
f();
|
||||||
@@ -283,7 +283,7 @@ run_test("format_drafts", (override) => {
|
|||||||
assert.deepEqual(draft_model.get(), data);
|
assert.deepEqual(draft_model.get(), data);
|
||||||
|
|
||||||
const stub_render_now = timerender.render_now;
|
const stub_render_now = timerender.render_now;
|
||||||
timerender.__Rewire__("render_now", (time) => stub_render_now(time, new Date(1549958107000)));
|
override(timerender, "render_now", (time) => stub_render_now(time, new Date(1549958107000)));
|
||||||
|
|
||||||
stub_templates((template_name, data) => {
|
stub_templates((template_name, data) => {
|
||||||
assert.equal(template_name, "draft_table_body");
|
assert.equal(template_name, "draft_table_body");
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ const hashchange = zrequire("hashchange");
|
|||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
|
|
||||||
const recent_topics = zrequire("recent_topics");
|
const recent_topics = zrequire("recent_topics");
|
||||||
recent_topics.__Rewire__("show", () => {});
|
|
||||||
recent_topics.__Rewire__("is_visible", () => false);
|
|
||||||
|
|
||||||
run_test("operators_round_trip", () => {
|
run_test("operators_round_trip", () => {
|
||||||
let operators;
|
let operators;
|
||||||
@@ -162,7 +160,9 @@ function test_helper() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test("hash_interactions", () => {
|
run_test("hash_interactions", (override) => {
|
||||||
|
override(recent_topics, "show", () => {});
|
||||||
|
override(recent_topics, "is_visible", () => false);
|
||||||
const helper = test_helper();
|
const helper = test_helper();
|
||||||
|
|
||||||
window.location.hash = "#all_messages";
|
window.location.hash = "#all_messages";
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ const rows = zrequire("rows");
|
|||||||
|
|
||||||
const lightbox = zrequire("lightbox");
|
const lightbox = zrequire("lightbox");
|
||||||
|
|
||||||
rows.__Rewire__("is_draft_row", () => false);
|
|
||||||
|
|
||||||
run_test("pan_and_zoom", (override) => {
|
run_test("pan_and_zoom", (override) => {
|
||||||
const img = $.create("img-stub");
|
const img = $.create("img-stub");
|
||||||
const link = $.create("link-stub");
|
const link = $.create("link-stub");
|
||||||
|
|||||||
@@ -194,12 +194,12 @@ run_test("get_unread_ids", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("defensive code", () => {
|
run_test("defensive code", (override) => {
|
||||||
// Test defensive code. We actually avoid calling
|
// Test defensive code. We actually avoid calling
|
||||||
// _possible_unread_message_ids for any case where we
|
// _possible_unread_message_ids for any case where we
|
||||||
// couldn't compute the unread message ids, but that
|
// couldn't compute the unread message ids, but that
|
||||||
// invariant is hard to future-proof.
|
// invariant is hard to future-proof.
|
||||||
narrow_state.__Rewire__("_possible_unread_message_ids", () => undefined);
|
override(narrow_state, "_possible_unread_message_ids", () => undefined);
|
||||||
const terms = [{operator: "some-unhandled-case", operand: "whatever"}];
|
const terms = [{operator: "some-unhandled-case", operand: "whatever"}];
|
||||||
set_filter(terms);
|
set_filter(terms);
|
||||||
assert_unread_info({
|
assert_unread_info({
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ run_test("is_my_user_id", () => {
|
|||||||
assert.equal(people.is_my_user_id(me.user_id.toString()), true);
|
assert.equal(people.is_my_user_id(me.user_id.toString()), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("blueslip", () => {
|
run_test("blueslip", (override) => {
|
||||||
const unknown_email = "alicebobfred@example.com";
|
const unknown_email = "alicebobfred@example.com";
|
||||||
|
|
||||||
blueslip.expect("debug", "User email operand unknown: " + unknown_email);
|
blueslip.expect("debug", "User email operand unknown: " + unknown_email);
|
||||||
@@ -103,8 +103,8 @@ run_test("blueslip", () => {
|
|||||||
const reply_to = people.pm_reply_to(message);
|
const reply_to = people.pm_reply_to(message);
|
||||||
assert(reply_to.includes("?"));
|
assert(reply_to.includes("?"));
|
||||||
|
|
||||||
people.__Rewire__("pm_with_user_ids", () => [42]);
|
override(people, "pm_with_user_ids", () => [42]);
|
||||||
people.__Rewire__("get_by_user_id", () => {});
|
override(people, "get_by_user_id", () => {});
|
||||||
blueslip.expect("error", "Unknown people in message");
|
blueslip.expect("error", "Unknown people in message");
|
||||||
const uri = people.pm_with_url({});
|
const uri = people.pm_with_url({});
|
||||||
assert.equal(uri.indexOf("unk"), uri.length - 3);
|
assert.equal(uri.indexOf("unk"), uri.length - 3);
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ test_ui("actions_popover", (override) => {
|
|||||||
return message;
|
return message;
|
||||||
};
|
};
|
||||||
|
|
||||||
message_edit.__Rewire__("get_editability", () => 4);
|
override(message_edit, "get_editability", () => 4);
|
||||||
|
|
||||||
stream_data.id_to_slug = (stream_id) => {
|
stream_data.id_to_slug = (stream_id) => {
|
||||||
assert.equal(stream_id, 123);
|
assert.equal(stream_id, 123);
|
||||||
|
|||||||
@@ -358,7 +358,7 @@ run_test("test_recent_topics_show", () => {
|
|||||||
assert.equal(rt.inplace_rerender("stream_unknown:topic_unknown"), false);
|
assert.equal(rt.inplace_rerender("stream_unknown:topic_unknown"), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("test_filter_all", () => {
|
run_test("test_filter_all", (override) => {
|
||||||
// Just tests inplace rerender of a message
|
// Just tests inplace rerender of a message
|
||||||
// in All topics filter.
|
// in All topics filter.
|
||||||
const expected = {
|
const expected = {
|
||||||
@@ -385,7 +385,7 @@ run_test("test_filter_all", () => {
|
|||||||
i = row_data.length;
|
i = row_data.length;
|
||||||
rt.clear_for_tests();
|
rt.clear_for_tests();
|
||||||
stub_out_filter_buttons();
|
stub_out_filter_buttons();
|
||||||
rt.__Rewire__("is_visible", () => true);
|
override(rt, "is_visible", () => true);
|
||||||
rt.set_filter("all");
|
rt.set_filter("all");
|
||||||
rt.process_messages([messages[0]]);
|
rt.process_messages([messages[0]]);
|
||||||
|
|
||||||
@@ -403,7 +403,7 @@ run_test("test_filter_all", () => {
|
|||||||
assert.equal(rt.inplace_rerender("1:topic-1"), true);
|
assert.equal(rt.inplace_rerender("1:topic-1"), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("test_filter_unread", () => {
|
run_test("test_filter_unread", (override) => {
|
||||||
// Tests rerender of all topics when filter changes to "unread".
|
// Tests rerender of all topics when filter changes to "unread".
|
||||||
const expected = {
|
const expected = {
|
||||||
filter_participated: false,
|
filter_participated: false,
|
||||||
@@ -426,7 +426,7 @@ run_test("test_filter_unread", () => {
|
|||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
rt.clear_for_tests();
|
rt.clear_for_tests();
|
||||||
rt.__Rewire__("is_visible", () => true);
|
override(rt, "is_visible", () => true);
|
||||||
rt.set_default_focus();
|
rt.set_default_focus();
|
||||||
|
|
||||||
stub_templates(() => "<recent_topics table stub>");
|
stub_templates(() => "<recent_topics table stub>");
|
||||||
@@ -470,7 +470,7 @@ run_test("test_filter_unread", () => {
|
|||||||
rt.set_filter("all");
|
rt.set_filter("all");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("test_filter_participated", () => {
|
run_test("test_filter_participated", (override) => {
|
||||||
// Tests rerender of all topics when filter changes to "unread".
|
// Tests rerender of all topics when filter changes to "unread".
|
||||||
const expected = {
|
const expected = {
|
||||||
filter_participated: true,
|
filter_participated: true,
|
||||||
@@ -493,7 +493,7 @@ run_test("test_filter_participated", () => {
|
|||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
rt.clear_for_tests();
|
rt.clear_for_tests();
|
||||||
rt.__Rewire__("is_visible", () => true);
|
override(rt, "is_visible", () => true);
|
||||||
rt.set_default_focus();
|
rt.set_default_focus();
|
||||||
stub_templates(() => "<recent_topics table stub>");
|
stub_templates(() => "<recent_topics table stub>");
|
||||||
stub_out_filter_buttons();
|
stub_out_filter_buttons();
|
||||||
@@ -549,10 +549,10 @@ run_test("test_update_unread_count", () => {
|
|||||||
// template rendering is tested in test_recent_topics_launch.
|
// template rendering is tested in test_recent_topics_launch.
|
||||||
stub_templates(() => "<recent_topics table stub>");
|
stub_templates(() => "<recent_topics table stub>");
|
||||||
|
|
||||||
run_test("basic assertions", () => {
|
run_test("basic assertions", (override) => {
|
||||||
rt.clear_for_tests();
|
rt.clear_for_tests();
|
||||||
stub_out_filter_buttons();
|
stub_out_filter_buttons();
|
||||||
rt.__Rewire__("is_visible", () => true);
|
override(rt, "is_visible", () => true);
|
||||||
rt.set_default_focus();
|
rt.set_default_focus();
|
||||||
rt.set_filter("all");
|
rt.set_filter("all");
|
||||||
rt.process_messages(messages);
|
rt.process_messages(messages);
|
||||||
@@ -630,10 +630,10 @@ run_test("basic assertions", () => {
|
|||||||
assert.equal(rt.update_topic_is_muted(stream1, "topic-10"), false);
|
assert.equal(rt.update_topic_is_muted(stream1, "topic-10"), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("test_reify_local_echo_message", () => {
|
run_test("test_reify_local_echo_message", (override) => {
|
||||||
rt.clear_for_tests();
|
rt.clear_for_tests();
|
||||||
stub_out_filter_buttons();
|
stub_out_filter_buttons();
|
||||||
rt.__Rewire__("is_visible", () => true);
|
override(rt, "is_visible", () => true);
|
||||||
rt.set_filter("all");
|
rt.set_filter("all");
|
||||||
rt.process_messages(messages);
|
rt.process_messages(messages);
|
||||||
|
|
||||||
@@ -776,7 +776,6 @@ run_test("test_topic_edit", () => {
|
|||||||
|
|
||||||
run_test("test_search", () => {
|
run_test("test_search", () => {
|
||||||
rt.clear_for_tests();
|
rt.clear_for_tests();
|
||||||
rt.__Rewire__("is_visible", () => true);
|
|
||||||
assert.equal(rt.topic_in_search_results("t", "general", "Recent Topic"), true);
|
assert.equal(rt.topic_in_search_results("t", "general", "Recent Topic"), true);
|
||||||
assert.equal(rt.topic_in_search_results("T", "general", "Recent Topic"), true);
|
assert.equal(rt.topic_in_search_results("T", "general", "Recent Topic"), true);
|
||||||
assert.equal(rt.topic_in_search_results("to", "general", "Recent Topic"), true);
|
assert.equal(rt.topic_in_search_results("to", "general", "Recent Topic"), true);
|
||||||
|
|||||||
@@ -70,10 +70,10 @@ run_test("get_items", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("create_pills", () => {
|
run_test("create_pills", (override) => {
|
||||||
let input_pill_create_called = false;
|
let input_pill_create_called = false;
|
||||||
|
|
||||||
input_pill.__Rewire__("create", () => {
|
override(input_pill, "create", () => {
|
||||||
input_pill_create_called = true;
|
input_pill_create_called = true;
|
||||||
return {dummy: "dummy"};
|
return {dummy: "dummy"};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -79,12 +79,12 @@ function get_suggestions(base_query, query) {
|
|||||||
return search.get_suggestions(base_query, query);
|
return search.get_suggestions(base_query, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test("basic_get_suggestions", () => {
|
run_test("basic_get_suggestions", (override) => {
|
||||||
const query = "fred";
|
const query = "fred";
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
override(stream_data, "subscribed_streams", () => []);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => "office");
|
override(narrow_state, "stream", () => "office");
|
||||||
|
|
||||||
const suggestions = get_suggestions("", query);
|
const suggestions = get_suggestions("", query);
|
||||||
|
|
||||||
@@ -96,10 +96,6 @@ run_test("subset_suggestions", () => {
|
|||||||
const query = "shakespeare";
|
const query = "shakespeare";
|
||||||
const base_query = "stream:Denmark topic:Hamlet";
|
const base_query = "stream:Denmark topic:Hamlet";
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
const suggestions = get_suggestions(base_query, query);
|
const suggestions = get_suggestions(base_query, query);
|
||||||
|
|
||||||
const expected = ["shakespeare"];
|
const expected = ["shakespeare"];
|
||||||
@@ -108,10 +104,6 @@ run_test("subset_suggestions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
run_test("private_suggestions", () => {
|
run_test("private_suggestions", () => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
let query = "is:private";
|
let query = "is:private";
|
||||||
let suggestions = get_suggestions("", query);
|
let suggestions = get_suggestions("", query);
|
||||||
let expected = [
|
let expected = [
|
||||||
@@ -225,10 +217,6 @@ run_test("private_suggestions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
run_test("group_suggestions", () => {
|
run_test("group_suggestions", () => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
// Entering a comma in a pm-with query should immediately generate
|
// Entering a comma in a pm-with query should immediately generate
|
||||||
// suggestions for the next person.
|
// suggestions for the next person.
|
||||||
let query = "pm-with:bob@zulip.com,";
|
let query = "pm-with:bob@zulip.com,";
|
||||||
@@ -363,12 +351,10 @@ run_test("group_suggestions", () => {
|
|||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
run_test("empty_query_suggestions", () => {
|
run_test("empty_query_suggestions", (override) => {
|
||||||
const query = "";
|
const query = "";
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["devel", "office"]);
|
override(stream_data, "subscribed_streams", () => ["devel", "office"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
const suggestions = get_suggestions("", query);
|
const suggestions = get_suggestions("", query);
|
||||||
|
|
||||||
@@ -404,12 +390,12 @@ run_test("empty_query_suggestions", () => {
|
|||||||
assert.equal(describe("has:attachment"), "Messages with one or more attachment");
|
assert.equal(describe("has:attachment"), "Messages with one or more attachment");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("has_suggestions", () => {
|
run_test("has_suggestions", (override) => {
|
||||||
// Checks that category wise suggestions are displayed instead of a single
|
// Checks that category wise suggestions are displayed instead of a single
|
||||||
// default suggestion when suggesting `has` operator.
|
// default suggestion when suggesting `has` operator.
|
||||||
let query = "h";
|
let query = "h";
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["devel", "office"]);
|
override(stream_data, "subscribed_streams", () => ["devel", "office"]);
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
override(narrow_state, "stream", () => {});
|
||||||
|
|
||||||
let suggestions = get_suggestions("", query);
|
let suggestions = get_suggestions("", query);
|
||||||
let expected = ["h", "has:link", "has:image", "has:attachment"];
|
let expected = ["h", "has:link", "has:image", "has:attachment"];
|
||||||
@@ -460,10 +446,10 @@ run_test("has_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("check_is_suggestions", () => {
|
run_test("check_is_suggestions", (override) => {
|
||||||
let query = "i";
|
let query = "i";
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["devel", "office"]);
|
override(stream_data, "subscribed_streams", () => ["devel", "office"]);
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
override(narrow_state, "stream", () => {});
|
||||||
|
|
||||||
let suggestions = get_suggestions("", query);
|
let suggestions = get_suggestions("", query);
|
||||||
let expected = [
|
let expected = [
|
||||||
@@ -564,10 +550,10 @@ run_test("check_is_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("sent_by_me_suggestions", () => {
|
run_test("sent_by_me_suggestions", (override) => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
override(stream_data, "subscribed_streams", () => []);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
override(narrow_state, "stream", () => {});
|
||||||
|
|
||||||
let query = "";
|
let query = "";
|
||||||
let suggestions = get_suggestions("", query);
|
let suggestions = get_suggestions("", query);
|
||||||
@@ -640,18 +626,18 @@ run_test("sent_by_me_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("topic_suggestions", () => {
|
run_test("topic_suggestions", (override) => {
|
||||||
let suggestions;
|
let suggestions;
|
||||||
let expected;
|
let expected;
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["office"]);
|
override(stream_data, "subscribed_streams", () => ["office"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => "office");
|
override(narrow_state, "stream", () => "office");
|
||||||
|
|
||||||
const devel_id = 44;
|
const devel_id = 44;
|
||||||
const office_id = 77;
|
const office_id = 77;
|
||||||
|
|
||||||
stream_data.__Rewire__("get_stream_id", (stream_name) => {
|
override(stream_data, "get_stream_id", (stream_name) => {
|
||||||
switch (stream_name) {
|
switch (stream_name) {
|
||||||
case "office":
|
case "office":
|
||||||
return office_id;
|
return office_id;
|
||||||
@@ -730,12 +716,10 @@ run_test("topic_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("whitespace_glitch", () => {
|
run_test("whitespace_glitch", (override) => {
|
||||||
const query = "stream:office "; // note trailing space
|
const query = "stream:office "; // note trailing space
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["office"]);
|
override(stream_data, "subscribed_streams", () => ["office"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
stream_topic_history.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
@@ -746,10 +730,10 @@ run_test("whitespace_glitch", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("stream_completion", () => {
|
run_test("stream_completion", (override) => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["office", "dev help"]);
|
override(stream_data, "subscribed_streams", () => ["office", "dev help"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
override(narrow_state, "stream", () => {});
|
||||||
|
|
||||||
stream_topic_history.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
@@ -770,7 +754,6 @@ run_test("stream_completion", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function people_suggestion_setup() {
|
function people_suggestion_setup() {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
|
||||||
narrow_state.__Rewire__("stream", noop);
|
narrow_state.__Rewire__("stream", noop);
|
||||||
|
|
||||||
const ted = {
|
const ted = {
|
||||||
@@ -916,10 +899,8 @@ run_test("operator_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("queries_with_spaces", () => {
|
run_test("queries_with_spaces", (override) => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["office", "dev help"]);
|
override(stream_data, "subscribed_streams", () => ["office", "dev help"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
stream_topic_history.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
|
|||||||
@@ -76,12 +76,12 @@ function get_suggestions(base_query, query) {
|
|||||||
return search.get_suggestions(base_query, query);
|
return search.get_suggestions(base_query, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test("basic_get_suggestions", () => {
|
run_test("basic_get_suggestions", (override) => {
|
||||||
const query = "fred";
|
const query = "fred";
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
override(stream_data, "subscribed_streams", () => []);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => "office");
|
override(narrow_state, "stream", () => "office");
|
||||||
|
|
||||||
const suggestions = get_suggestions("", query);
|
const suggestions = get_suggestions("", query);
|
||||||
|
|
||||||
@@ -92,10 +92,6 @@ run_test("basic_get_suggestions", () => {
|
|||||||
run_test("subset_suggestions", () => {
|
run_test("subset_suggestions", () => {
|
||||||
const query = "stream:Denmark topic:Hamlet shakespeare";
|
const query = "stream:Denmark topic:Hamlet shakespeare";
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
const suggestions = get_suggestions("", query);
|
const suggestions = get_suggestions("", query);
|
||||||
|
|
||||||
const expected = [
|
const expected = [
|
||||||
@@ -108,10 +104,6 @@ run_test("subset_suggestions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
run_test("private_suggestions", () => {
|
run_test("private_suggestions", () => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
let query = "is:private";
|
let query = "is:private";
|
||||||
let suggestions = get_suggestions("", query);
|
let suggestions = get_suggestions("", query);
|
||||||
let expected = [
|
let expected = [
|
||||||
@@ -221,10 +213,6 @@ run_test("private_suggestions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
run_test("group_suggestions", () => {
|
run_test("group_suggestions", () => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
// Entering a comma in a pm-with query should immediately generate
|
// Entering a comma in a pm-with query should immediately generate
|
||||||
// suggestions for the next person.
|
// suggestions for the next person.
|
||||||
let query = "pm-with:bob@zulip.com,";
|
let query = "pm-with:bob@zulip.com,";
|
||||||
@@ -366,12 +354,10 @@ run_test("group_suggestions", () => {
|
|||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
run_test("empty_query_suggestions", () => {
|
run_test("empty_query_suggestions", (override) => {
|
||||||
const query = "";
|
const query = "";
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["devel", "office"]);
|
override(stream_data, "subscribed_streams", () => ["devel", "office"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
const suggestions = get_suggestions("", query);
|
const suggestions = get_suggestions("", query);
|
||||||
|
|
||||||
@@ -407,12 +393,12 @@ run_test("empty_query_suggestions", () => {
|
|||||||
assert.equal(describe("has:attachment"), "Messages with one or more attachment");
|
assert.equal(describe("has:attachment"), "Messages with one or more attachment");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("has_suggestions", () => {
|
run_test("has_suggestions", (override) => {
|
||||||
// Checks that category wise suggestions are displayed instead of a single
|
// Checks that category wise suggestions are displayed instead of a single
|
||||||
// default suggestion when suggesting `has` operator.
|
// default suggestion when suggesting `has` operator.
|
||||||
let query = "h";
|
let query = "h";
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["devel", "office"]);
|
override(stream_data, "subscribed_streams", () => ["devel", "office"]);
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
override(narrow_state, "stream", () => {});
|
||||||
|
|
||||||
let suggestions = get_suggestions("", query);
|
let suggestions = get_suggestions("", query);
|
||||||
let expected = ["h", "has:link", "has:image", "has:attachment"];
|
let expected = ["h", "has:link", "has:image", "has:attachment"];
|
||||||
@@ -466,9 +452,9 @@ run_test("has_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("check_is_suggestions", () => {
|
run_test("check_is_suggestions", (override) => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["devel", "office"]);
|
override(stream_data, "subscribed_streams", () => ["devel", "office"]);
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
override(narrow_state, "stream", () => {});
|
||||||
|
|
||||||
let query = "i";
|
let query = "i";
|
||||||
let suggestions = get_suggestions("", query);
|
let suggestions = get_suggestions("", query);
|
||||||
@@ -535,10 +521,10 @@ run_test("check_is_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("sent_by_me_suggestions", () => {
|
run_test("sent_by_me_suggestions", (override) => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
override(stream_data, "subscribed_streams", () => []);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
override(narrow_state, "stream", () => {});
|
||||||
|
|
||||||
let query = "";
|
let query = "";
|
||||||
let suggestions = get_suggestions("", query);
|
let suggestions = get_suggestions("", query);
|
||||||
@@ -606,18 +592,18 @@ run_test("sent_by_me_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("topic_suggestions", () => {
|
run_test("topic_suggestions", (override) => {
|
||||||
let suggestions;
|
let suggestions;
|
||||||
let expected;
|
let expected;
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["office"]);
|
override(stream_data, "subscribed_streams", () => ["office"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => "office");
|
override(narrow_state, "stream", () => "office");
|
||||||
|
|
||||||
const devel_id = 44;
|
const devel_id = 44;
|
||||||
const office_id = 77;
|
const office_id = 77;
|
||||||
|
|
||||||
stream_data.__Rewire__("get_stream_id", (stream_name) => {
|
override(stream_data, "get_stream_id", (stream_name) => {
|
||||||
switch (stream_name) {
|
switch (stream_name) {
|
||||||
case "office":
|
case "office":
|
||||||
return office_id;
|
return office_id;
|
||||||
@@ -702,12 +688,10 @@ run_test("topic_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("whitespace_glitch", () => {
|
run_test("whitespace_glitch", (override) => {
|
||||||
const query = "stream:office "; // note trailing space
|
const query = "stream:office "; // note trailing space
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["office"]);
|
override(stream_data, "subscribed_streams", () => ["office"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
stream_topic_history.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
@@ -718,10 +702,10 @@ run_test("whitespace_glitch", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("stream_completion", () => {
|
run_test("stream_completion", (override) => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["office", "dev help"]);
|
override(stream_data, "subscribed_streams", () => ["office", "dev help"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
override(narrow_state, "stream", () => {});
|
||||||
|
|
||||||
stream_topic_history.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
@@ -741,12 +725,12 @@ run_test("stream_completion", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("people_suggestions", () => {
|
run_test("people_suggestions", (override) => {
|
||||||
let query = "te";
|
let query = "te";
|
||||||
|
|
||||||
stream_data.__Rewire__("subscribed_streams", () => []);
|
override(stream_data, "subscribed_streams", () => []);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
override(narrow_state, "stream", () => {});
|
||||||
|
|
||||||
const ted = {
|
const ted = {
|
||||||
email: "ted@zulip.com",
|
email: "ted@zulip.com",
|
||||||
@@ -857,10 +841,8 @@ run_test("operator_suggestions", () => {
|
|||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("queries_with_spaces", () => {
|
run_test("queries_with_spaces", (override) => {
|
||||||
stream_data.__Rewire__("subscribed_streams", () => ["office", "dev help"]);
|
override(stream_data, "subscribed_streams", () => ["office", "dev help"]);
|
||||||
|
|
||||||
narrow_state.__Rewire__("stream", () => {});
|
|
||||||
|
|
||||||
stream_topic_history.reset();
|
stream_topic_history.reset();
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ const name_selector = `#user-groups #${CSS.escape(1)} .name`;
|
|||||||
const description_selector = `#user-groups #${CSS.escape(1)} .description`;
|
const description_selector = `#user-groups #${CSS.escape(1)} .description`;
|
||||||
const instructions_selector = `#user-groups #${CSS.escape(1)} .save-instructions`;
|
const instructions_selector = `#user-groups #${CSS.escape(1)} .save-instructions`;
|
||||||
|
|
||||||
test_ui("populate_user_groups", () => {
|
test_ui("populate_user_groups", (override) => {
|
||||||
const realm_user_group = {
|
const realm_user_group = {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: "Mobile",
|
name: "Mobile",
|
||||||
@@ -157,7 +157,7 @@ test_ui("populate_user_groups", () => {
|
|||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
settings_user_groups.__Rewire__("can_edit", () => true);
|
override(settings_user_groups, "can_edit", () => true);
|
||||||
|
|
||||||
const all_pills = new Map();
|
const all_pills = new Map();
|
||||||
|
|
||||||
@@ -344,7 +344,7 @@ test_ui("populate_user_groups", () => {
|
|||||||
"function",
|
"function",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test_ui("with_external_user", () => {
|
test_ui("with_external_user", (override) => {
|
||||||
const realm_user_group = {
|
const realm_user_group = {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: "Mobile",
|
name: "Mobile",
|
||||||
@@ -361,10 +361,10 @@ test_ui("with_external_user", () => {
|
|||||||
|
|
||||||
people.get_by_user_id = () => noop;
|
people.get_by_user_id = () => noop;
|
||||||
|
|
||||||
user_pill.__Rewire__("append_person", () => noop);
|
override(user_pill, "append_person", () => noop);
|
||||||
|
|
||||||
let can_edit_called = 0;
|
let can_edit_called = 0;
|
||||||
settings_user_groups.__Rewire__("can_edit", () => {
|
override(settings_user_groups, "can_edit", () => {
|
||||||
can_edit_called += 1;
|
can_edit_called += 1;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -481,10 +481,10 @@ test_ui("with_external_user", () => {
|
|||||||
assert.equal(turned_off["click/whole"], true);
|
assert.equal(turned_off["click/whole"], true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("reload", () => {
|
test_ui("reload", (override) => {
|
||||||
$("#user-groups").html("Some text");
|
$("#user-groups").html("Some text");
|
||||||
let populate_user_groups_called = false;
|
let populate_user_groups_called = false;
|
||||||
settings_user_groups.__Rewire__("populate_user_groups", () => {
|
override(settings_user_groups, "populate_user_groups", () => {
|
||||||
populate_user_groups_called = true;
|
populate_user_groups_called = true;
|
||||||
});
|
});
|
||||||
settings_user_groups.reload();
|
settings_user_groups.reload();
|
||||||
@@ -498,8 +498,8 @@ test_ui("reset", () => {
|
|||||||
assert.equal(result, undefined);
|
assert.equal(result, undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("on_events", () => {
|
test_ui("on_events", (override) => {
|
||||||
settings_user_groups.__Rewire__("can_edit", () => true);
|
override(settings_user_groups, "can_edit", () => true);
|
||||||
|
|
||||||
(function test_admin_user_group_form_submit_triggered() {
|
(function test_admin_user_group_form_submit_triggered() {
|
||||||
const handler = $(".organization form.admin-user-group-form").get_on_handler("submit");
|
const handler = $(".organization form.admin-user-group-form").get_on_handler("submit");
|
||||||
@@ -577,7 +577,7 @@ test_ui("on_events", () => {
|
|||||||
assert.equal(opts.url, "/json/user_groups/1");
|
assert.equal(opts.url, "/json/user_groups/1");
|
||||||
assert.deepEqual(opts.data, data);
|
assert.deepEqual(opts.data, data);
|
||||||
|
|
||||||
settings_user_groups.__Rewire__("reload", () => {
|
override(settings_user_groups, "reload", () => {
|
||||||
settings_user_groups_reload_called = true;
|
settings_user_groups_reload_called = true;
|
||||||
});
|
});
|
||||||
opts.success();
|
opts.success();
|
||||||
@@ -652,7 +652,7 @@ test_ui("on_events", () => {
|
|||||||
|
|
||||||
// Cancel button triggers blur event.
|
// Cancel button triggers blur event.
|
||||||
let settings_user_groups_reload_called = false;
|
let settings_user_groups_reload_called = false;
|
||||||
settings_user_groups.__Rewire__("reload", () => {
|
override(settings_user_groups, "reload", () => {
|
||||||
settings_user_groups_reload_called = true;
|
settings_user_groups_reload_called = true;
|
||||||
});
|
});
|
||||||
api_endpoint_called = false;
|
api_endpoint_called = false;
|
||||||
|
|||||||
@@ -632,7 +632,7 @@ run_test("canonicalized_name", () => {
|
|||||||
assert.deepStrictEqual(stream_data.canonicalized_name("Stream_Bar"), "stream_bar");
|
assert.deepStrictEqual(stream_data.canonicalized_name("Stream_Bar"), "stream_bar");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("create_sub", () => {
|
run_test("create_sub", (override) => {
|
||||||
stream_data.clear_subscriptions();
|
stream_data.clear_subscriptions();
|
||||||
const india = {
|
const india = {
|
||||||
stream_id: 102,
|
stream_id: 102,
|
||||||
@@ -652,7 +652,7 @@ run_test("create_sub", () => {
|
|||||||
color: "#76ce90",
|
color: "#76ce90",
|
||||||
};
|
};
|
||||||
|
|
||||||
color_data.__Rewire__("pick_color", () => "#bd86e5");
|
override(color_data, "pick_color", () => "#bd86e5");
|
||||||
|
|
||||||
const india_sub = stream_data.create_sub_from_server_data(india);
|
const india_sub = stream_data.create_sub_from_server_data(india);
|
||||||
assert(india_sub);
|
assert(india_sub);
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ function test_ui(label, f) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
test_ui("subscriber_pills", () => {
|
test_ui("subscriber_pills", (override) => {
|
||||||
const subscriptions_table_selector = "#subscriptions_table";
|
const subscriptions_table_selector = "#subscriptions_table";
|
||||||
const input_field_stub = $.create(".input");
|
const input_field_stub = $.create(".input");
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ test_ui("subscriber_pills", () => {
|
|||||||
let expected_user_ids = [];
|
let expected_user_ids = [];
|
||||||
let input_typeahead_called = false;
|
let input_typeahead_called = false;
|
||||||
let add_subscribers_request = false;
|
let add_subscribers_request = false;
|
||||||
stream_edit.__Rewire__("invite_user_to_stream", (user_ids, sub) => {
|
override(stream_edit, "invite_user_to_stream", (user_ids, sub) => {
|
||||||
assert.equal(sub.stream_id, denmark.stream_id);
|
assert.equal(sub.stream_id, denmark.stream_id);
|
||||||
assert.deepEqual(user_ids.sort(), expected_user_ids.sort());
|
assert.deepEqual(user_ids.sort(), expected_user_ids.sort());
|
||||||
add_subscribers_request = true;
|
add_subscribers_request = true;
|
||||||
@@ -244,7 +244,7 @@ test_ui("subscriber_pills", () => {
|
|||||||
|
|
||||||
// Only Denmark stream pill is created and a
|
// Only Denmark stream pill is created and a
|
||||||
// request is sent to add all it's subscribers.
|
// request is sent to add all it's subscribers.
|
||||||
user_pill.__Rewire__("get_user_ids", () => []);
|
override(user_pill, "get_user_ids", () => []);
|
||||||
expected_user_ids = potential_denmark_stream_subscribers;
|
expected_user_ids = potential_denmark_stream_subscribers;
|
||||||
add_subscribers_handler(event);
|
add_subscribers_handler(event);
|
||||||
|
|
||||||
@@ -256,14 +256,14 @@ test_ui("subscriber_pills", () => {
|
|||||||
|
|
||||||
// No request is sent if we try to subscribe ourselves
|
// No request is sent if we try to subscribe ourselves
|
||||||
// only and are already subscribed to the stream.
|
// only and are already subscribed to the stream.
|
||||||
user_pill.__Rewire__("get_user_ids", () => [me.user_id]);
|
override(user_pill, "get_user_ids", () => [me.user_id]);
|
||||||
add_subscribers_handler(event);
|
add_subscribers_handler(event);
|
||||||
assert(!add_subscribers_request);
|
assert(!add_subscribers_request);
|
||||||
|
|
||||||
// Denmark stream pill and fred and mark user pills are created.
|
// Denmark stream pill and fred and mark user pills are created.
|
||||||
// But only one request for mark is sent even though a mark user
|
// But only one request for mark is sent even though a mark user
|
||||||
// pill is created and mark is also a subscriber of Denmark stream.
|
// pill is created and mark is also a subscriber of Denmark stream.
|
||||||
user_pill.__Rewire__("get_user_ids", () => [mark.user_id, fred.user_id]);
|
override(user_pill, "get_user_ids", () => [mark.user_id, fred.user_id]);
|
||||||
stream_pill.get_user_ids = () => peer_data.get_subscribers(denmark.stream_id);
|
stream_pill.get_user_ids = () => peer_data.get_subscribers(denmark.stream_id);
|
||||||
expected_user_ids = potential_denmark_stream_subscribers.concat(fred.user_id);
|
expected_user_ids = potential_denmark_stream_subscribers.concat(fred.user_id);
|
||||||
add_subscribers_handler(event);
|
add_subscribers_handler(event);
|
||||||
|
|||||||
@@ -164,11 +164,11 @@ test_ui("create_sidebar_row", (override) => {
|
|||||||
assert(!social_li.hasClass("out_of_home_view"));
|
assert(!social_li.hasClass("out_of_home_view"));
|
||||||
|
|
||||||
const row = stream_list.stream_sidebar.get_row(stream_id);
|
const row = stream_list.stream_sidebar.get_row(stream_id);
|
||||||
stream_data.__Rewire__("is_active", () => true);
|
override(stream_data, "is_active", () => true);
|
||||||
row.update_whether_active();
|
row.update_whether_active();
|
||||||
assert(!social_li.hasClass("inactive_stream"));
|
assert(!social_li.hasClass("inactive_stream"));
|
||||||
|
|
||||||
stream_data.__Rewire__("is_active", () => false);
|
override(stream_data, "is_active", () => false);
|
||||||
row.update_whether_active();
|
row.update_whether_active();
|
||||||
assert(social_li.hasClass("inactive_stream"));
|
assert(social_li.hasClass("inactive_stream"));
|
||||||
|
|
||||||
@@ -194,16 +194,16 @@ test_ui("pinned_streams_never_inactive", (override) => {
|
|||||||
const social_sidebar = $("<social sidebar row>");
|
const social_sidebar = $("<social sidebar row>");
|
||||||
let stream_id = social.stream_id;
|
let stream_id = social.stream_id;
|
||||||
let row = stream_list.stream_sidebar.get_row(stream_id);
|
let row = stream_list.stream_sidebar.get_row(stream_id);
|
||||||
stream_data.__Rewire__("is_active", () => false);
|
override(stream_data, "is_active", () => false);
|
||||||
|
|
||||||
stream_list.build_stream_list();
|
stream_list.build_stream_list();
|
||||||
assert(social_sidebar.hasClass("inactive_stream"));
|
assert(social_sidebar.hasClass("inactive_stream"));
|
||||||
|
|
||||||
stream_data.__Rewire__("is_active", () => true);
|
override(stream_data, "is_active", () => true);
|
||||||
row.update_whether_active();
|
row.update_whether_active();
|
||||||
assert(!social_sidebar.hasClass("inactive_stream"));
|
assert(!social_sidebar.hasClass("inactive_stream"));
|
||||||
|
|
||||||
stream_data.__Rewire__("is_active", () => false);
|
override(stream_data, "is_active", () => false);
|
||||||
row.update_whether_active();
|
row.update_whether_active();
|
||||||
assert(social_sidebar.hasClass("inactive_stream"));
|
assert(social_sidebar.hasClass("inactive_stream"));
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ test_ui("pinned_streams_never_inactive", (override) => {
|
|||||||
const devel_sidebar = $("<devel sidebar row>");
|
const devel_sidebar = $("<devel sidebar row>");
|
||||||
stream_id = devel.stream_id;
|
stream_id = devel.stream_id;
|
||||||
row = stream_list.stream_sidebar.get_row(stream_id);
|
row = stream_list.stream_sidebar.get_row(stream_id);
|
||||||
stream_data.__Rewire__("is_active", () => false);
|
override(stream_data, "is_active", () => false);
|
||||||
|
|
||||||
stream_list.build_stream_list();
|
stream_list.build_stream_list();
|
||||||
assert(!devel_sidebar.hasClass("inactive_stream"));
|
assert(!devel_sidebar.hasClass("inactive_stream"));
|
||||||
@@ -438,13 +438,13 @@ test_ui("focus_user_filter", () => {
|
|||||||
click_handler(e);
|
click_handler(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("sort_streams", () => {
|
test_ui("sort_streams", (override) => {
|
||||||
// Get coverage on early-exit.
|
// Get coverage on early-exit.
|
||||||
stream_list.build_stream_list();
|
stream_list.build_stream_list();
|
||||||
|
|
||||||
initialize_stream_data();
|
initialize_stream_data();
|
||||||
|
|
||||||
stream_data.__Rewire__("is_active", (sub) => sub.name !== "cars");
|
override(stream_data, "is_active", (sub) => sub.name !== "cars");
|
||||||
|
|
||||||
let appended_elems;
|
let appended_elems;
|
||||||
$("#stream_filters").append = (elems) => {
|
$("#stream_filters").append = (elems) => {
|
||||||
@@ -488,7 +488,7 @@ test_ui("sort_streams", () => {
|
|||||||
assert(!stream_list.stream_sidebar.has_row_for(stream_id));
|
assert(!stream_list.stream_sidebar.has_row_for(stream_id));
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("separators_only_pinned_and_dormant", () => {
|
test_ui("separators_only_pinned_and_dormant", (override) => {
|
||||||
// Test only pinned and dormant streams
|
// Test only pinned and dormant streams
|
||||||
|
|
||||||
// Get coverage on early-exit.
|
// Get coverage on early-exit.
|
||||||
@@ -522,7 +522,7 @@ test_ui("separators_only_pinned_and_dormant", () => {
|
|||||||
};
|
};
|
||||||
add_row(DenmarkSub);
|
add_row(DenmarkSub);
|
||||||
|
|
||||||
stream_data.__Rewire__("is_active", (sub) => sub.name !== "Denmark");
|
override(stream_data, "is_active", (sub) => sub.name !== "Denmark");
|
||||||
|
|
||||||
let appended_elems;
|
let appended_elems;
|
||||||
$("#stream_filters").append = (elems) => {
|
$("#stream_filters").append = (elems) => {
|
||||||
@@ -634,7 +634,7 @@ test_ui("update_count_in_dom", () => {
|
|||||||
|
|
||||||
narrow_state.active = () => false;
|
narrow_state.active = () => false;
|
||||||
|
|
||||||
test_ui("rename_stream", () => {
|
test_ui("rename_stream", (override) => {
|
||||||
initialize_stream_data();
|
initialize_stream_data();
|
||||||
|
|
||||||
const sub = stream_data.get_sub_by_name("devel");
|
const sub = stream_data.get_sub_by_name("devel");
|
||||||
@@ -662,7 +662,7 @@ test_ui("rename_stream", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let count_updated;
|
let count_updated;
|
||||||
stream_list.__Rewire__("update_count_in_dom", (li) => {
|
override(stream_list, "update_count_in_dom", (li) => {
|
||||||
assert.equal(li, li_stub);
|
assert.equal(li, li_stub);
|
||||||
count_updated = true;
|
count_updated = true;
|
||||||
});
|
});
|
||||||
@@ -671,7 +671,7 @@ test_ui("rename_stream", () => {
|
|||||||
assert(count_updated);
|
assert(count_updated);
|
||||||
});
|
});
|
||||||
|
|
||||||
test_ui("refresh_pin", () => {
|
test_ui("refresh_pin", (override) => {
|
||||||
initialize_stream_data();
|
initialize_stream_data();
|
||||||
|
|
||||||
const sub = {
|
const sub = {
|
||||||
@@ -697,7 +697,7 @@ test_ui("refresh_pin", () => {
|
|||||||
$("#stream_filters").append = noop;
|
$("#stream_filters").append = noop;
|
||||||
|
|
||||||
let scrolled;
|
let scrolled;
|
||||||
stream_list.__Rewire__("scroll_stream_into_view", (li) => {
|
override(stream_list, "scroll_stream_into_view", (li) => {
|
||||||
assert.equal(li, li_stub);
|
assert.equal(li, li_stub);
|
||||||
scrolled = true;
|
scrolled = true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ function clear_search_input() {
|
|||||||
stream_list.clear_search({stopPropagation: noop});
|
stream_list.clear_search({stopPropagation: noop});
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test("basics", () => {
|
run_test("basics", (override) => {
|
||||||
let cursor_helper;
|
let cursor_helper;
|
||||||
const input = $(".stream-list-filter");
|
const input = $(".stream-list-filter");
|
||||||
const section = $(".stream_search_section");
|
const section = $(".stream_search_section");
|
||||||
@@ -96,7 +96,7 @@ run_test("basics", () => {
|
|||||||
|
|
||||||
function verify_list_updated(f) {
|
function verify_list_updated(f) {
|
||||||
let updated;
|
let updated;
|
||||||
stream_list.__Rewire__("update_streams_sidebar", () => {
|
override(stream_list, "update_streams_sidebar", () => {
|
||||||
updated = true;
|
updated = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ run_test("streams", () => {
|
|||||||
assert_prev_stream("announce", "test here");
|
assert_prev_stream("announce", "test here");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("topics", () => {
|
run_test("topics", (override) => {
|
||||||
const streams = [1, 2, 3, 4];
|
const streams = [1, 2, 3, 4];
|
||||||
const topics = new Map([
|
const topics = new Map([
|
||||||
[1, ["read", "read", "1a", "1b", "read", "1c"]],
|
[1, ["read", "read", "1a", "1b", "read", "1c"]],
|
||||||
@@ -85,7 +85,7 @@ run_test("topics", () => {
|
|||||||
devel: devel_stream_id,
|
devel: devel_stream_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
stream_topic_history.__Rewire__("get_recent_topic_names", (stream_id) => {
|
override(stream_topic_history, "get_recent_topic_names", (stream_id) => {
|
||||||
switch (stream_id) {
|
switch (stream_id) {
|
||||||
case muted_stream_id:
|
case muted_stream_id:
|
||||||
return ["ms-topic1", "ms-topic2"];
|
return ["ms-topic1", "ms-topic2"];
|
||||||
@@ -96,15 +96,15 @@ run_test("topics", () => {
|
|||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
|
||||||
stream_data.__Rewire__("get_stream_id", (stream_name) => stream_id_dct[stream_name]);
|
override(stream_data, "get_stream_id", (stream_name) => stream_id_dct[stream_name]);
|
||||||
|
|
||||||
stream_data.__Rewire__("is_stream_muted_by_name", (stream_name) => stream_name === "muted");
|
override(stream_data, "is_stream_muted_by_name", (stream_name) => stream_name === "muted");
|
||||||
|
|
||||||
unread.__Rewire__("topic_has_any_unread", (stream_id) =>
|
override(unread, "topic_has_any_unread", (stream_id) =>
|
||||||
[devel_stream_id, muted_stream_id].includes(stream_id),
|
[devel_stream_id, muted_stream_id].includes(stream_id),
|
||||||
);
|
);
|
||||||
|
|
||||||
muting.__Rewire__("is_topic_muted", (stream_name, topic) => topic === "muted");
|
override(muting, "is_topic_muted", (stream_name, topic) => topic === "muted");
|
||||||
|
|
||||||
let next_item = tg.get_next_topic("announce", "whatever");
|
let next_item = tg.get_next_topic("announce", "whatever");
|
||||||
assert.deepEqual(next_item, {
|
assert.deepEqual(next_item, {
|
||||||
@@ -119,10 +119,10 @@ run_test("topics", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("get_next_unread_pm_string", () => {
|
run_test("get_next_unread_pm_string", (override) => {
|
||||||
pm_conversations.recent.get_strings = () => ["1", "read", "2,3", "4", "unk"];
|
pm_conversations.recent.get_strings = () => ["1", "read", "2,3", "4", "unk"];
|
||||||
|
|
||||||
unread.__Rewire__("num_unread_for_person", (user_ids_string) => {
|
override(unread, "num_unread_for_person", (user_ids_string) => {
|
||||||
if (user_ids_string === "unk") {
|
if (user_ids_string === "unk") {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ run_test("get_next_unread_pm_string", () => {
|
|||||||
assert.equal(tg.get_next_unread_pm_string("read"), "2,3");
|
assert.equal(tg.get_next_unread_pm_string("read"), "2,3");
|
||||||
assert.equal(tg.get_next_unread_pm_string("2,3"), "4");
|
assert.equal(tg.get_next_unread_pm_string("2,3"), "4");
|
||||||
|
|
||||||
unread.__Rewire__("num_unread_for_person", () => 0);
|
override(unread, "num_unread_for_person", () => 0);
|
||||||
|
|
||||||
assert.equal(tg.get_next_unread_pm_string("2,3"), undefined);
|
assert.equal(tg.get_next_unread_pm_string("2,3"), undefined);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ run_test("transmit_message_ajax_reload_pending", () => {
|
|||||||
assert(reload_initiated);
|
assert(reload_initiated);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("reply_message_stream", () => {
|
run_test("reply_message_stream", (override) => {
|
||||||
const stream_message = {
|
const stream_message = {
|
||||||
type: "stream",
|
type: "stream",
|
||||||
stream: "social",
|
stream: "social",
|
||||||
@@ -110,7 +110,7 @@ run_test("reply_message_stream", () => {
|
|||||||
|
|
||||||
let send_message_args;
|
let send_message_args;
|
||||||
|
|
||||||
transmit.__Rewire__("send_message", (args) => {
|
override(transmit, "send_message", (args) => {
|
||||||
send_message_args = args;
|
send_message_args = args;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ run_test("reply_message_stream", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("reply_message_private", () => {
|
run_test("reply_message_private", (override) => {
|
||||||
const fred = {
|
const fred = {
|
||||||
user_id: 3,
|
user_id: 3,
|
||||||
email: "fred@example.com",
|
email: "fred@example.com",
|
||||||
@@ -153,7 +153,7 @@ run_test("reply_message_private", () => {
|
|||||||
|
|
||||||
let send_message_args;
|
let send_message_args;
|
||||||
|
|
||||||
transmit.__Rewire__("send_message", (args) => {
|
override(transmit, "send_message", (args) => {
|
||||||
send_message_args = args;
|
send_message_args = args;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ stream_data.create_streams([
|
|||||||
{name: "Linux", subscribed: true, color: "red", stream_id: 2},
|
{name: "Linux", subscribed: true, color: "red", stream_id: 2},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
run_test("sort_streams", () => {
|
run_test("sort_streams", (override) => {
|
||||||
let test_streams = [
|
let test_streams = [
|
||||||
{
|
{
|
||||||
stream_id: 101,
|
stream_id: 101,
|
||||||
@@ -83,7 +83,7 @@ run_test("sort_streams", () => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
stream_data.__Rewire__("is_active", (sub) => sub.name !== "dead");
|
override(stream_data, "is_active", (sub) => sub.name !== "dead");
|
||||||
|
|
||||||
test_streams = th.sort_streams(test_streams, "d");
|
test_streams = th.sort_streams(test_streams, "d");
|
||||||
assert.deepEqual(test_streams[0].name, "Denmark"); // Pinned streams first
|
assert.deepEqual(test_streams[0].name, "Denmark"); // Pinned streams first
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ function returns_time(secs) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test("basics", () => {
|
run_test("basics", (override) => {
|
||||||
// invalid conversation basically does nothing
|
// invalid conversation basically does nothing
|
||||||
let worker = {};
|
let worker = {};
|
||||||
typing_status.update(worker, null);
|
typing_status.update(worker, null);
|
||||||
@@ -263,7 +263,7 @@ run_test("basics", () => {
|
|||||||
// test that we correctly detect if worker.get_recipient
|
// test that we correctly detect if worker.get_recipient
|
||||||
// and typing_status.state.current_recipient are the same
|
// and typing_status.state.current_recipient are the same
|
||||||
|
|
||||||
compose_pm_pill.__Rewire__("get_user_ids_string", () => "1,2,3");
|
override(compose_pm_pill, "get_user_ids_string", () => "1,2,3");
|
||||||
typing_status.state.current_recipient = typing.get_recipient();
|
typing_status.state.current_recipient = typing.get_recipient();
|
||||||
|
|
||||||
const call_count = {
|
const call_count = {
|
||||||
@@ -275,7 +275,7 @@ run_test("basics", () => {
|
|||||||
|
|
||||||
// stub functions to see how may time they are called
|
// stub functions to see how may time they are called
|
||||||
for (const method of Object.keys(call_count)) {
|
for (const method of Object.keys(call_count)) {
|
||||||
typing_status.__Rewire__(method, () => {
|
override(typing_status, method, () => {
|
||||||
call_count[method] += 1;
|
call_count[method] += 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -294,14 +294,14 @@ run_test("basics", () => {
|
|||||||
|
|
||||||
// change in recipient and new_recipient should make us
|
// change in recipient and new_recipient should make us
|
||||||
// call typing_status.stop_last_notification
|
// call typing_status.stop_last_notification
|
||||||
compose_pm_pill.__Rewire__("get_user_ids_string", () => "2,3,4");
|
override(compose_pm_pill, "get_user_ids_string", () => "2,3,4");
|
||||||
typing_status.update(worker, typing.get_recipient());
|
typing_status.update(worker, typing.get_recipient());
|
||||||
assert.deepEqual(call_count.maybe_ping_server, 2);
|
assert.deepEqual(call_count.maybe_ping_server, 2);
|
||||||
assert.deepEqual(call_count.start_or_extend_idle_timer, 3);
|
assert.deepEqual(call_count.start_or_extend_idle_timer, 3);
|
||||||
assert.deepEqual(call_count.stop_last_notification, 1);
|
assert.deepEqual(call_count.stop_last_notification, 1);
|
||||||
|
|
||||||
// Stream messages are represented as get_user_ids_string being empty
|
// Stream messages are represented as get_user_ids_string being empty
|
||||||
compose_pm_pill.__Rewire__("get_user_ids_string", () => "");
|
override(compose_pm_pill, "get_user_ids_string", () => "");
|
||||||
typing_status.update(worker, typing.get_recipient());
|
typing_status.update(worker, typing.get_recipient());
|
||||||
assert.deepEqual(call_count.maybe_ping_server, 2);
|
assert.deepEqual(call_count.maybe_ping_server, 2);
|
||||||
assert.deepEqual(call_count.start_or_extend_idle_timer, 3);
|
assert.deepEqual(call_count.start_or_extend_idle_timer, 3);
|
||||||
|
|||||||
@@ -249,14 +249,14 @@ run_test("muting", () => {
|
|||||||
assert.equal(unread.num_unread_for_stream(unknown_stream_id), 0);
|
assert.equal(unread.num_unread_for_stream(unknown_stream_id), 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("num_unread_for_topic", () => {
|
run_test("num_unread_for_topic", (override) => {
|
||||||
// Test the num_unread_for_topic() function using many
|
// Test the num_unread_for_topic() function using many
|
||||||
// messages.
|
// messages.
|
||||||
unread.declare_bankruptcy();
|
unread.declare_bankruptcy();
|
||||||
|
|
||||||
const stream_id = 301;
|
const stream_id = 301;
|
||||||
|
|
||||||
stream_data.__Rewire__("get_sub_by_id", (arg) => {
|
override(stream_data, "get_sub_by_id", (arg) => {
|
||||||
if (arg === stream_id) {
|
if (arg === stream_id) {
|
||||||
return {name: "Some Stream"};
|
return {name: "Some Stream"};
|
||||||
}
|
}
|
||||||
@@ -324,13 +324,13 @@ run_test("num_unread_for_topic", () => {
|
|||||||
assert.deepEqual(msg_ids, []);
|
assert.deepEqual(msg_ids, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("home_messages", () => {
|
run_test("home_messages", (override) => {
|
||||||
stream_data.__Rewire__("is_subscribed", () => true);
|
override(stream_data, "is_subscribed", () => true);
|
||||||
stream_data.__Rewire__("is_muted", () => false);
|
override(stream_data, "is_muted", () => false);
|
||||||
|
|
||||||
const stream_id = 401;
|
const stream_id = 401;
|
||||||
|
|
||||||
stream_data.__Rewire__("get_sub_by_id", () => ({
|
override(stream_data, "get_sub_by_id", () => ({
|
||||||
name: "whatever",
|
name: "whatever",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -363,13 +363,13 @@ run_test("home_messages", () => {
|
|||||||
test_notifiable_count(counts.home_unread_messages, 0);
|
test_notifiable_count(counts.home_unread_messages, 0);
|
||||||
|
|
||||||
// Now unsubscribe all our streams.
|
// Now unsubscribe all our streams.
|
||||||
stream_data.__Rewire__("is_subscribed", () => false);
|
override(stream_data, "is_subscribed", () => false);
|
||||||
counts = unread.get_counts();
|
counts = unread.get_counts();
|
||||||
assert.equal(counts.home_unread_messages, 0);
|
assert.equal(counts.home_unread_messages, 0);
|
||||||
test_notifiable_count(counts.home_unread_messages, 0);
|
test_notifiable_count(counts.home_unread_messages, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("phantom_messages", () => {
|
run_test("phantom_messages", (override) => {
|
||||||
const message = {
|
const message = {
|
||||||
id: 999,
|
id: 999,
|
||||||
type: "stream",
|
type: "stream",
|
||||||
@@ -377,7 +377,7 @@ run_test("phantom_messages", () => {
|
|||||||
topic: "phantom",
|
topic: "phantom",
|
||||||
};
|
};
|
||||||
|
|
||||||
stream_data.__Rewire__("get_sub_by_id", () => {});
|
override(stream_data, "get_sub_by_id", () => {});
|
||||||
|
|
||||||
unread.mark_as_read(message.id);
|
unread.mark_as_read(message.id);
|
||||||
const counts = unread.get_counts();
|
const counts = unread.get_counts();
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ set_global("page_params", {
|
|||||||
|
|
||||||
const helpers = zrequire("../js/billing/helpers");
|
const helpers = zrequire("../js/billing/helpers");
|
||||||
|
|
||||||
run_test("initialize", () => {
|
run_test("initialize", (override) => {
|
||||||
let token_func;
|
let token_func;
|
||||||
helpers.__Rewire__("set_tab", (page_name) => {
|
override(helpers, "set_tab", (page_name) => {
|
||||||
assert.equal(page_name, "upgrade");
|
assert.equal(page_name, "upgrade");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -82,11 +82,11 @@ run_test("initialize", () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.__Rewire__("show_license_section", (section) => {
|
override(helpers, "show_license_section", (section) => {
|
||||||
assert.equal(section, "automatic");
|
assert.equal(section, "automatic");
|
||||||
});
|
});
|
||||||
|
|
||||||
helpers.__Rewire__("update_charged_amount", (prices, schedule) => {
|
override(helpers, "update_charged_amount", (prices, schedule) => {
|
||||||
assert.equal(prices.annual, 6400);
|
assert.equal(prices.annual, 6400);
|
||||||
assert.equal(prices.monthly, 640);
|
assert.equal(prices.monthly, 640);
|
||||||
assert.equal(schedule, "monthly");
|
assert.equal(schedule, "monthly");
|
||||||
@@ -111,7 +111,7 @@ run_test("initialize", () => {
|
|||||||
const invoice_click_handler = $("#invoice-button").get_on_handler("click");
|
const invoice_click_handler = $("#invoice-button").get_on_handler("click");
|
||||||
const request_sponsorship_click_handler = $("#sponsorship-button").get_on_handler("click");
|
const request_sponsorship_click_handler = $("#sponsorship-button").get_on_handler("click");
|
||||||
|
|
||||||
helpers.__Rewire__("is_valid_input", () => true);
|
override(helpers, "is_valid_input", () => true);
|
||||||
add_card_click_handler(e);
|
add_card_click_handler(e);
|
||||||
assert.equal(create_ajax_request_form_call_count, 1);
|
assert.equal(create_ajax_request_form_call_count, 1);
|
||||||
invoice_click_handler(e);
|
invoice_click_handler(e);
|
||||||
@@ -119,13 +119,13 @@ run_test("initialize", () => {
|
|||||||
request_sponsorship_click_handler(e);
|
request_sponsorship_click_handler(e);
|
||||||
assert.equal(create_ajax_request_form_call_count, 3);
|
assert.equal(create_ajax_request_form_call_count, 3);
|
||||||
|
|
||||||
helpers.__Rewire__("is_valid_input", () => false);
|
override(helpers, "is_valid_input", () => false);
|
||||||
add_card_click_handler(e);
|
add_card_click_handler(e);
|
||||||
invoice_click_handler(e);
|
invoice_click_handler(e);
|
||||||
request_sponsorship_click_handler(e);
|
request_sponsorship_click_handler(e);
|
||||||
assert.equal(create_ajax_request_form_call_count, 3);
|
assert.equal(create_ajax_request_form_call_count, 3);
|
||||||
|
|
||||||
helpers.__Rewire__("show_license_section", (section) => {
|
override(helpers, "show_license_section", (section) => {
|
||||||
assert.equal(section, "manual");
|
assert.equal(section, "manual");
|
||||||
});
|
});
|
||||||
const license_change_handler = $("input[type=radio][name=license_management]").get_on_handler(
|
const license_change_handler = $("input[type=radio][name=license_management]").get_on_handler(
|
||||||
@@ -133,7 +133,7 @@ run_test("initialize", () => {
|
|||||||
);
|
);
|
||||||
license_change_handler.call({value: "manual"});
|
license_change_handler.call({value: "manual"});
|
||||||
|
|
||||||
helpers.__Rewire__("update_charged_amount", (prices, schedule) => {
|
override(helpers, "update_charged_amount", (prices, schedule) => {
|
||||||
assert.equal(prices.annual, 6400);
|
assert.equal(prices.annual, 6400);
|
||||||
assert.equal(prices.monthly, 640);
|
assert.equal(prices.monthly, 640);
|
||||||
assert.equal(schedule, "monthly");
|
assert.equal(schedule, "monthly");
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ run_test("show_error_message", () => {
|
|||||||
assert.equal($("#compose-error-msg").text(), "translated: An unknown error occurred.");
|
assert.equal($("#compose-error-msg").text(), "translated: An unknown error occurred.");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("upload_files", () => {
|
run_test("upload_files", (override) => {
|
||||||
let uppy_cancel_all_called = false;
|
let uppy_cancel_all_called = false;
|
||||||
let files = [
|
let files = [
|
||||||
{
|
{
|
||||||
@@ -218,7 +218,7 @@ run_test("upload_files", () => {
|
|||||||
getFiles: () => [...files],
|
getFiles: () => [...files],
|
||||||
};
|
};
|
||||||
let hide_upload_status_called = false;
|
let hide_upload_status_called = false;
|
||||||
upload.__Rewire__("hide_upload_status", (config) => {
|
override(upload, "hide_upload_status", (config) => {
|
||||||
hide_upload_status_called = true;
|
hide_upload_status_called = true;
|
||||||
assert(config.mode, "compose");
|
assert(config.mode, "compose");
|
||||||
});
|
});
|
||||||
@@ -229,7 +229,7 @@ run_test("upload_files", () => {
|
|||||||
|
|
||||||
page_params.max_file_upload_size_mib = 0;
|
page_params.max_file_upload_size_mib = 0;
|
||||||
let show_error_message_called = false;
|
let show_error_message_called = false;
|
||||||
upload.__Rewire__("show_error_message", (config, message) => {
|
override(upload, "show_error_message", (config, message) => {
|
||||||
show_error_message_called = true;
|
show_error_message_called = true;
|
||||||
assert.equal(config.mode, "compose");
|
assert.equal(config.mode, "compose");
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@@ -247,13 +247,13 @@ run_test("upload_files", () => {
|
|||||||
on_click_close_button_callback = callback;
|
on_click_close_button_callback = callback;
|
||||||
};
|
};
|
||||||
let compose_ui_insert_syntax_and_focus_called = false;
|
let compose_ui_insert_syntax_and_focus_called = false;
|
||||||
compose_ui.__Rewire__("insert_syntax_and_focus", (syntax, textarea) => {
|
override(compose_ui, "insert_syntax_and_focus", (syntax, textarea) => {
|
||||||
assert.equal(syntax, "[translated: Uploading budapest.png…]()");
|
assert.equal(syntax, "[translated: Uploading budapest.png…]()");
|
||||||
assert.equal(textarea, $("#compose-textarea"));
|
assert.equal(textarea, $("#compose-textarea"));
|
||||||
compose_ui_insert_syntax_and_focus_called = true;
|
compose_ui_insert_syntax_and_focus_called = true;
|
||||||
});
|
});
|
||||||
let compose_ui_autosize_textarea_called = false;
|
let compose_ui_autosize_textarea_called = false;
|
||||||
compose_ui.__Rewire__("autosize_textarea", () => {
|
override(compose_ui, "autosize_textarea", () => {
|
||||||
compose_ui_autosize_textarea_called = true;
|
compose_ui_autosize_textarea_called = true;
|
||||||
});
|
});
|
||||||
let markdown_preview_hide_button_clicked = false;
|
let markdown_preview_hide_button_clicked = false;
|
||||||
@@ -304,7 +304,7 @@ run_test("upload_files", () => {
|
|||||||
type: "image/png",
|
type: "image/png",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
compose_ui.__Rewire__("replace_syntax", (old_syntax, new_syntax, textarea) => {
|
override(compose_ui, "replace_syntax", (old_syntax, new_syntax, textarea) => {
|
||||||
compose_ui_replace_syntax_called = true;
|
compose_ui_replace_syntax_called = true;
|
||||||
assert.equal(old_syntax, "[translated: Uploading budapest.png…]()");
|
assert.equal(old_syntax, "[translated: Uploading budapest.png…]()");
|
||||||
assert.equal(new_syntax, "");
|
assert.equal(new_syntax, "");
|
||||||
@@ -376,7 +376,7 @@ run_test("uppy_config", () => {
|
|||||||
assert.equal(uppy_used_progressbar, true);
|
assert.equal(uppy_used_progressbar, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("file_input", () => {
|
run_test("file_input", (override) => {
|
||||||
upload.setup_upload({mode: "compose"});
|
upload.setup_upload({mode: "compose"});
|
||||||
|
|
||||||
const change_handler = $("body").get_on_handler("change", "#file_input");
|
const change_handler = $("body").get_on_handler("change", "#file_input");
|
||||||
@@ -388,7 +388,7 @@ run_test("file_input", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
let upload_files_called = false;
|
let upload_files_called = false;
|
||||||
upload.__Rewire__("upload_files", (uppy, config, files) => {
|
override(upload, "upload_files", (uppy, config, files) => {
|
||||||
assert.equal(config.mode, "compose");
|
assert.equal(config.mode, "compose");
|
||||||
assert.equal(files, files);
|
assert.equal(files, files);
|
||||||
upload_files_called = true;
|
upload_files_called = true;
|
||||||
@@ -397,7 +397,7 @@ run_test("file_input", () => {
|
|||||||
assert(upload_files_called);
|
assert(upload_files_called);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("file_drop", () => {
|
run_test("file_drop", (override) => {
|
||||||
upload.setup_upload({mode: "compose"});
|
upload.setup_upload({mode: "compose"});
|
||||||
|
|
||||||
let prevent_default_counter = 0;
|
let prevent_default_counter = 0;
|
||||||
@@ -427,7 +427,7 @@ run_test("file_drop", () => {
|
|||||||
};
|
};
|
||||||
const drop_handler = $("#compose").get_on_handler("drop");
|
const drop_handler = $("#compose").get_on_handler("drop");
|
||||||
let upload_files_called = false;
|
let upload_files_called = false;
|
||||||
upload.__Rewire__("upload_files", () => {
|
override(upload, "upload_files", () => {
|
||||||
upload_files_called = true;
|
upload_files_called = true;
|
||||||
});
|
});
|
||||||
drop_handler(drop_event);
|
drop_handler(drop_event);
|
||||||
@@ -435,7 +435,7 @@ run_test("file_drop", () => {
|
|||||||
assert.equal(upload_files_called, true);
|
assert.equal(upload_files_called, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("copy_paste", () => {
|
run_test("copy_paste", (override) => {
|
||||||
upload.setup_upload({mode: "compose"});
|
upload.setup_upload({mode: "compose"});
|
||||||
|
|
||||||
const paste_handler = $("#compose").get_on_handler("paste");
|
const paste_handler = $("#compose").get_on_handler("paste");
|
||||||
@@ -458,7 +458,7 @@ run_test("copy_paste", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
let upload_files_called = false;
|
let upload_files_called = false;
|
||||||
upload.__Rewire__("upload_files", () => {
|
override(upload, "upload_files", () => {
|
||||||
upload_files_called = true;
|
upload_files_called = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -474,7 +474,7 @@ run_test("copy_paste", () => {
|
|||||||
assert.equal(upload_files_called, false);
|
assert.equal(upload_files_called, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("uppy_events", () => {
|
run_test("uppy_events", (override) => {
|
||||||
const callbacks = {};
|
const callbacks = {};
|
||||||
let uppy_cancel_all_called = false;
|
let uppy_cancel_all_called = false;
|
||||||
let state = {};
|
let state = {};
|
||||||
@@ -518,11 +518,11 @@ run_test("uppy_events", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
let compose_actions_start_called = false;
|
let compose_actions_start_called = false;
|
||||||
compose_actions.__Rewire__("start", () => {
|
override(compose_actions, "start", () => {
|
||||||
compose_actions_start_called = true;
|
compose_actions_start_called = true;
|
||||||
});
|
});
|
||||||
let compose_ui_replace_syntax_called = false;
|
let compose_ui_replace_syntax_called = false;
|
||||||
compose_ui.__Rewire__("replace_syntax", (old_syntax, new_syntax, textarea) => {
|
override(compose_ui, "replace_syntax", (old_syntax, new_syntax, textarea) => {
|
||||||
compose_ui_replace_syntax_called = true;
|
compose_ui_replace_syntax_called = true;
|
||||||
assert.equal(old_syntax, "[translated: Uploading copenhagen.png…]()");
|
assert.equal(old_syntax, "[translated: Uploading copenhagen.png…]()");
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@@ -532,7 +532,7 @@ run_test("uppy_events", () => {
|
|||||||
assert.equal(textarea, $("#compose-textarea"));
|
assert.equal(textarea, $("#compose-textarea"));
|
||||||
});
|
});
|
||||||
let compose_ui_autosize_textarea_called = false;
|
let compose_ui_autosize_textarea_called = false;
|
||||||
compose_ui.__Rewire__("autosize_textarea", () => {
|
override(compose_ui, "autosize_textarea", () => {
|
||||||
compose_ui_autosize_textarea_called = true;
|
compose_ui_autosize_textarea_called = true;
|
||||||
});
|
});
|
||||||
on_upload_success_callback(file, response);
|
on_upload_success_callback(file, response);
|
||||||
@@ -558,7 +558,7 @@ run_test("uppy_events", () => {
|
|||||||
func();
|
func();
|
||||||
});
|
});
|
||||||
let hide_upload_status_called = false;
|
let hide_upload_status_called = false;
|
||||||
upload.__Rewire__("hide_upload_status", () => {
|
override(upload, "hide_upload_status", () => {
|
||||||
hide_upload_status_called = true;
|
hide_upload_status_called = true;
|
||||||
});
|
});
|
||||||
$("#compose-send-status").removeClass("alert-error");
|
$("#compose-send-status").removeClass("alert-error");
|
||||||
@@ -615,7 +615,7 @@ run_test("uppy_events", () => {
|
|||||||
uppy_cancel_all_called = false;
|
uppy_cancel_all_called = false;
|
||||||
compose_ui_replace_syntax_called = false;
|
compose_ui_replace_syntax_called = false;
|
||||||
const on_restriction_failed_callback = callbacks["restriction-failed"];
|
const on_restriction_failed_callback = callbacks["restriction-failed"];
|
||||||
upload.__Rewire__("show_error_message", (config, message) => {
|
override(upload, "show_error_message", (config, message) => {
|
||||||
show_error_message_called = true;
|
show_error_message_called = true;
|
||||||
assert.equal(config.mode, "compose");
|
assert.equal(config.mode, "compose");
|
||||||
assert.equal(message, "Some error message");
|
assert.equal(message, "Some error message");
|
||||||
@@ -623,7 +623,7 @@ run_test("uppy_events", () => {
|
|||||||
on_info_visible_callback();
|
on_info_visible_callback();
|
||||||
assert(uppy_cancel_all_called);
|
assert(uppy_cancel_all_called);
|
||||||
assert(show_error_message_called);
|
assert(show_error_message_called);
|
||||||
compose_ui.__Rewire__("replace_syntax", (old_syntax, new_syntax, textarea) => {
|
override(compose_ui, "replace_syntax", (old_syntax, new_syntax, textarea) => {
|
||||||
compose_ui_replace_syntax_called = true;
|
compose_ui_replace_syntax_called = true;
|
||||||
assert.equal(old_syntax, "[translated: Uploading copenhagen.png…]()");
|
assert.equal(old_syntax, "[translated: Uploading copenhagen.png…]()");
|
||||||
assert.equal(new_syntax, "");
|
assert.equal(new_syntax, "");
|
||||||
@@ -654,7 +654,7 @@ run_test("uppy_events", () => {
|
|||||||
const on_upload_error_callback = callbacks["upload-error"];
|
const on_upload_error_callback = callbacks["upload-error"];
|
||||||
show_error_message_called = false;
|
show_error_message_called = false;
|
||||||
compose_ui_replace_syntax_called = false;
|
compose_ui_replace_syntax_called = false;
|
||||||
upload.__Rewire__("show_error_message", (config, message) => {
|
override(upload, "show_error_message", (config, message) => {
|
||||||
show_error_message_called = true;
|
show_error_message_called = true;
|
||||||
assert.equal(config.mode, "compose");
|
assert.equal(config.mode, "compose");
|
||||||
assert.equal(message, "Response message");
|
assert.equal(message, "Response message");
|
||||||
@@ -671,7 +671,7 @@ run_test("uppy_events", () => {
|
|||||||
assert(compose_ui_replace_syntax_called);
|
assert(compose_ui_replace_syntax_called);
|
||||||
|
|
||||||
compose_ui_replace_syntax_called = false;
|
compose_ui_replace_syntax_called = false;
|
||||||
upload.__Rewire__("show_error_message", (config, message) => {
|
override(upload, "show_error_message", (config, message) => {
|
||||||
show_error_message_called = true;
|
show_error_message_called = true;
|
||||||
assert.equal(config.mode, "compose");
|
assert.equal(config.mode, "compose");
|
||||||
assert.equal(message, null);
|
assert.equal(message, null);
|
||||||
|
|||||||
Reference in New Issue
Block a user