tests: Replace unneeded override_rewire uses by whole-module mocks.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-03-15 13:51:16 -07:00
committed by Anders Kaseorg
parent 15db564246
commit 959e51fe58
6 changed files with 25 additions and 43 deletions

View File

@@ -32,6 +32,7 @@ set_global("navigator", {
// jQuery stuff should go away if we make an initialize() method.
set_global("document", "document-stub");
const activity_ui = mock_esm("../src/activity_ui");
const browser_history = mock_esm("../src/browser_history");
const compose_actions = mock_esm("../src/compose_actions");
const compose_reply = mock_esm("../src/compose_reply");
@@ -121,7 +122,6 @@ message_lists.current = {
},
};
const activity_ui = zrequire("activity_ui");
const emoji = zrequire("emoji");
const emoji_codes = zrequire("../../static/generated/emoji/emoji_codes.json");
const hotkey = zrequire("hotkey");
@@ -139,14 +139,6 @@ function stubbing(module, func_name_to_stub, test_function) {
});
}
function stubbing_rewire(module, func_name_to_stub, test_function) {
with_overrides(({override_rewire}) => {
const stub = make_stub();
override_rewire(module, func_name_to_stub, stub.f);
test_function(stub);
});
}
// Set up defaults for most tests.
hotkey.__Rewire__("processing_text", () => false);
@@ -263,13 +255,6 @@ function assert_mapping(c, module, func_name, shiftKey, keydown) {
});
}
function assert_mapping_rewire(c, module, func_name, shiftKey) {
stubbing_rewire(module, func_name, (stub) => {
assert.ok(process(c, shiftKey));
assert.equal(stub.num_calls, 1);
});
}
function assert_unmapped(s) {
for (const c of s) {
assert.equal(process(c), false);
@@ -327,7 +312,7 @@ run_test("streams", ({override}) => {
run_test("basic mappings", () => {
assert_mapping("?", browser_history, "go_to_location");
assert_mapping("/", search, "initiate_search");
assert_mapping_rewire("w", activity_ui, "initiate_search");
assert_mapping("w", activity_ui, "initiate_search");
assert_mapping("q", stream_list, "initiate_search");
assert_mapping("A", narrow, "stream_cycle_backward");