Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

tests: Avoid override_rewire for bootstrap_typeahead.

Anders Kaseorg45cfa4246968
diff --git a/web/tests/composebox_typeahead.test.js b/web/tests/composebox_typeahead.test.js
index 6281912a21e..c2bcad8e06c 100644
--- a/web/tests/composebox_typeahead.test.js
+++ b/web/tests/composebox_typeahead.test.js
@@ -10,6 +10,7 @@ const {current_user, realm, user_settings} = require("./lib/zpage_params");
let autosize_called;
+const bootstrap_typeahead = mock_esm("../src/bootstrap_typeahead");
const compose_ui = mock_esm("../src/compose_ui", {
autosize_textarea() {
autosize_called = true;
@@ -35,7 +36,6 @@ set_global("setTimeout", (f, time) => {
});
set_global("document", "document-stub");
-const bootstrap_typeahead = zrequire("bootstrap_typeahead");
const typeahead = zrequire("../shared/src/typeahead");
const stream_topic_history = zrequire("stream_topic_history");
const compose_state = zrequire("compose_state");
@@ -757,7 +757,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
let topic_typeahead_called = false;
let pm_recipient_typeahead_called = false;
let compose_textarea_typeahead_called = false;
- override_rewire(bootstrap_typeahead, "create", ($element, options) => {
+ override(bootstrap_typeahead, "create", ($element, options) => {
switch ($element) {
case $("input#stream_message_recipient_topic"): {
override_rewire(stream_topic_history, "get_recent_topic_names", (stream_id) => {
diff --git a/web/tests/pill_typeahead.test.js b/web/tests/pill_typeahead.test.js
index 4018876a305..b27e14f815f 100644
--- a/web/tests/pill_typeahead.test.js
+++ b/web/tests/pill_typeahead.test.js
@@ -7,11 +7,12 @@ const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
-const input_pill = zrequire("input_pill");
-const pill_typeahead = zrequire("pill_typeahead");
const noop = function () {};
-const bootstrap_typeahead = zrequire("bootstrap_typeahead");
+const bootstrap_typeahead = mock_esm("../src/bootstrap_typeahead");
+
+const input_pill = zrequire("input_pill");
+const pill_typeahead = zrequire("pill_typeahead");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
const stream_data = zrequire("stream_data");
@@ -106,7 +107,7 @@ for (const sub of subs) {
stream_data.add_sub(sub);
}
-run_test("set_up", ({mock_template, override_rewire}) => {
+run_test("set_up", ({mock_template, override}) => {
mock_template("input_pill.hbs", true, (data, html) => {
assert.equal(typeof data.display_value, "string");
assert.equal(typeof data.has_image, "boolean");
@@ -131,7 +132,7 @@ run_test("set_up", ({mock_template, override_rewire}) => {
}
let opts = {};
- override_rewire(bootstrap_typeahead, "create", ($element, config) => {
+ override(bootstrap_typeahead, "create", ($element, config) => {
assert.equal($element, $fake_input);
assert.equal(config.items, 5);
assert.ok(config.fixed);
diff --git a/web/tests/search.test.js b/web/tests/search.test.js
index 3eedc9dde03..ee4a4b983c0 100644
--- a/web/tests/search.test.js
+++ b/web/tests/search.test.js
@@ -6,6 +6,7 @@ const {mock_esm, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const $ = require("./lib/zjquery");
+const bootstrap_typeahead = mock_esm("../src/bootstrap_typeahead");
const narrow_state = mock_esm("../src/narrow_state");
const search_suggestion = mock_esm("../src/search_suggestion");
@@ -16,9 +17,8 @@ mock_esm("../src/filter", {
});
const search = zrequire("search");
-const bootstrap_typeahead = zrequire("bootstrap_typeahead");
-run_test("initialize", ({override_rewire, mock_template}) => {
+run_test("initialize", ({override, override_rewire, mock_template}) => {
const $search_query_box = $("#search_query");
const $searchbox_form = $("#searchbox_form");
@@ -36,7 +36,7 @@ run_test("initialize", ({override_rewire, mock_template}) => {
search_suggestion.max_num_of_search_results = 999;
let terms;
- override_rewire(bootstrap_typeahead, "create", ($element, opts) => {
+ override(bootstrap_typeahead, "create", ($element, opts) => {
assert.equal($element, $search_query_box);
assert.equal(opts.items, 999);
assert.equal(opts.naturalSearch, true);
@@ -306,7 +306,7 @@ run_test("initialize", ({override_rewire, mock_template}) => {
assert.ok(is_blurred);
});
-run_test("initiate_search", ({override_rewire}) => {
+run_test("initiate_search", ({override}) => {
// open typeahead and select text when navbar is open
// this implicitly expects the code to used the chained
// function calls, which is something to keep in mind if
@@ -314,7 +314,7 @@ run_test("initiate_search", ({override_rewire}) => {
narrow_state.filter = () => ({is_keyword_search: () => false});
let typeahead_forced_open = false;
let is_searchbox_text_selected = false;
- override_rewire(bootstrap_typeahead, "lookup", () => {
+ override(bootstrap_typeahead, "lookup", () => {
typeahead_forced_open = true;
});
$("#search_query").on("select", () => {