Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Remove topic history rewires in composebox_typeahead.test.cjs.
Tim Abbott63c13ae61ff5
diff --git a/web/src/stream_topic_history.ts b/web/src/stream_topic_history.tsindex 386a6e260b1..51a886331c3 100644--- a/web/src/stream_topic_history.ts+++ b/web/src/stream_topic_history.ts@@ -338,14 +338,10 @@ export function mark_history_fetched_for(stream_id: number): void {fetched_stream_ids.add(stream_id);}-export let get_recent_topic_names = (stream_id: number): string[] => {+export function get_recent_topic_names(stream_id: number): string[] {const history = find_or_create(stream_id);return history.get_recent_topic_names();-};--export function rewire_get_recent_topic_names(value: typeof get_recent_topic_names): void {- get_recent_topic_names = value;}export function get_max_message_id(stream_id: number): number {diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjsindex 11c35d44582..6177d051784 100644--- a/web/tests/composebox_typeahead.test.cjs+++ b/web/tests/composebox_typeahead.test.cjs@@ -713,11 +713,20 @@ function test(label, f) {});}-test("topics_seen_for", ({override, override_rewire}) => {- override_rewire(stream_topic_history, "get_recent_topic_names", (stream_id) => {- assert.equal(stream_id, denmark_stream.stream_id);- return ["With Twisted Metal", "acceptance", "civil fears"];- });+test("topics_seen_for", ({override}) => {+ // Initialize topic history with test data, using message_ids+ // to control the recency ordering.+ for (const [message_id, topic_name] of [+ [3, "With Twisted Metal"],+ [2, "acceptance"],+ [1, "civil fears"],+ ]) {+ stream_topic_history.add_message({+ stream_id: denmark_stream.stream_id,+ message_id,+ topic_name,+ });+ }override(stream_topic_history_util, "get_server_history", (stream_id) => {assert.equal(stream_id, denmark_stream.stream_id);@@ -1185,6 +1194,18 @@ const sweden_topics_to_show = ["",];+// Initialize stream_topic_history with test data so we can query+// get_recent_topic_names without rewiring. Assign message_ids in+// reverse so the recency order matches the alphabetical order of+// sweden_topics_to_show.+for (const [index, topic_name] of sweden_topics_to_show.entries()) {+ stream_topic_history.add_message({+ stream_id: sweden_stream.stream_id,+ message_id: sweden_topics_to_show.length - index,+ topic_name,+ });+}+test("initialize", ({override, override_rewire, mock_template}) => {mock_banners();@@ -1240,11 +1261,6 @@ test("initialize", ({override, override_rewire, mock_template}) => {override(bootstrap_typeahead, "Typeahead", (input_element, options) => {switch (input_element.$element) {case $("input#stream_message_recipient_topic"): {- override_rewire(stream_topic_history, "get_recent_topic_names", (stream_id) => {- assert.equal(stream_id, sweden_stream.stream_id);- return sweden_topics_to_show;- });-compose_state.set_stream_id(sweden_stream.stream_id);const lear_user_data = [{@@ -1837,10 +1853,6 @@ test("initialize", ({override, override_rewire, mock_template}) => {});test("begins_typeahead", ({override, override_rewire}) => {- override_rewire(stream_topic_history, "get_recent_topic_names", (stream_id) => {- assert.equal(stream_id, sweden_stream.stream_id);- return sweden_topics_to_show;- });override(stream_topic_history_util, "get_server_history", noop);const input_element = {