From 76a602842d9942d09f35481240727a9461f1a41c Mon Sep 17 00:00:00 2001 From: evykassirer Date: Tue, 24 Sep 2024 16:28:50 -0700 Subject: [PATCH] message_list: Make data required in the constructor. --- web/src/message_list.ts | 31 +++++-------------- web/tests/compose_closed_ui.test.js | 6 +++- web/tests/message_list.test.js | 46 ++++++++++++++++++++++------ web/tests/message_list_view.test.js | 11 +++++-- web/tests/popover_menus_data.test.js | 6 +++- 5 files changed, 63 insertions(+), 37 deletions(-) diff --git a/web/src/message_list.ts b/web/src/message_list.ts index 0840ba5f01..96787bca96 100644 --- a/web/src/message_list.ts +++ b/web/src/message_list.ts @@ -4,8 +4,7 @@ import assert from "minimalistic-assert"; import * as blueslip from "./blueslip"; import * as compose_tooltips from "./compose_tooltips"; -import type {Filter} from "./filter"; -import {MessageListData} from "./message_list_data"; +import type {MessageListData} from "./message_list_data"; import * as message_list_tooltips from "./message_list_tooltips"; import {MessageListView} from "./message_list_view"; import type {Message} from "./message_store"; @@ -71,30 +70,14 @@ export class MessageList { last_message_historical?: boolean; should_trigger_message_selected_event?: boolean; - constructor( - opts: ( - | { - data: MessageListData; - } - | { - data?: undefined; - filter: Filter; - } - ) & {excludes_muted_topics?: boolean; is_node_test?: boolean}, - ) { + constructor(opts: { + data: MessageListData; + excludes_muted_topics?: boolean; + is_node_test?: boolean; + }) { MessageList.id_counter += 1; this.id = MessageList.id_counter; - if (opts.data) { - this.data = opts.data; - } else { - const filter = opts.filter; - - this.data = new MessageListData({ - excludes_muted_topics: opts.excludes_muted_topics ?? false, - filter, - }); - } - + this.data = opts.data; this.data.set_rendered_message_list_id(this.id); // TODO: This property should likely just be inlined into diff --git a/web/tests/compose_closed_ui.test.js b/web/tests/compose_closed_ui.test.js index bd94801879..e9803b3151 100644 --- a/web/tests/compose_closed_ui.test.js +++ b/web/tests/compose_closed_ui.test.js @@ -26,6 +26,7 @@ const stream_data = zrequire("stream_data"); const compose_closed_ui = zrequire("compose_closed_ui"); const {Filter} = zrequire("filter"); const {MessageList} = zrequire("message_list"); +const {MessageListData} = zrequire("message_list_data"); // Helper test function function test_reply_label(expected_label) { @@ -43,7 +44,10 @@ run_test("reply_label", () => { // Mocking up a test message list const filter = new Filter([]); const list = new MessageList({ - filter, + data: new MessageListData({ + excludes_muted_topics: false, + filter, + }), }); message_lists.current = list; const stream_one = { diff --git a/web/tests/message_list.test.js b/web/tests/message_list.test.js index 2c22aa20ee..b791e0e38d 100644 --- a/web/tests/message_list.test.js +++ b/web/tests/message_list.test.js @@ -27,6 +27,7 @@ const narrow_state = mock_esm("../src/narrow_state"); const stream_data = mock_esm("../src/stream_data"); const {MessageList} = zrequire("message_list"); +const {MessageListData} = zrequire("message_list_data"); function MessageListView() { return { maybe_rerender: noop, @@ -45,7 +46,10 @@ run_test("basics", ({override}) => { const filter = new Filter([]); const list = new MessageList({ - filter, + data: new MessageListData({ + excludes_muted_topics: false, + filter, + }), }); const messages = [ @@ -137,7 +141,10 @@ run_test("basics", ({override}) => { run_test("prev_next", () => { const list = new MessageList({ - filter: new Filter([]), + data: new MessageListData({ + excludes_muted_topics: false, + filter: new Filter([]), + }), }); assert.equal(list.prev(), undefined); @@ -178,7 +185,10 @@ run_test("prev_next", () => { run_test("message_range", () => { const list = new MessageList({ - filter: new Filter([]), + data: new MessageListData({ + excludes_muted_topics: false, + filter: new Filter([]), + }), }); const messages = [{id: 30}, {id: 40}, {id: 50}, {id: 60}]; @@ -194,7 +204,10 @@ run_test("message_range", () => { run_test("change_message_id", () => { const list = new MessageList({ - filter: new Filter([]), + data: new MessageListData({ + excludes_muted_topics: false, + filter: new Filter([]), + }), }); list.data._add_to_hash([ {id: 10.5, content: "good job"}, @@ -217,7 +230,10 @@ run_test("change_message_id", () => { run_test("last_sent_by_me", () => { const list = new MessageList({ - filter: new Filter([]), + data: new MessageListData({ + excludes_muted_topics: false, + filter: new Filter([]), + }), }); const items = [ { @@ -242,7 +258,10 @@ run_test("last_sent_by_me", () => { run_test("local_echo", () => { let list = new MessageList({ - filter: new Filter([]), + data: new MessageListData({ + excludes_muted_topics: false, + filter: new Filter([]), + }), }); list.append([ {id: 10}, @@ -274,7 +293,10 @@ run_test("local_echo", () => { assert.equal(list.closest_id(58), 60); list = new MessageList({ - filter: new Filter([]), + data: new MessageListData({ + excludes_muted_topics: false, + filter: new Filter([]), + }), }); list.append([ {id: 10}, @@ -316,7 +338,10 @@ run_test("local_echo", () => { run_test("bookend", ({override}) => { const list = new MessageList({ - filter: new Filter([]), + data: new MessageListData({ + excludes_muted_topics: false, + filter: new Filter([]), + }), }); list.view.clear_trailing_bookend = noop; @@ -411,7 +436,10 @@ run_test("bookend", ({override}) => { run_test("add_remove_rerender", () => { const filter = new Filter([]); const list = new MessageList({ - filter, + data: new MessageListData({ + excludes_muted_topics: false, + filter, + }), }); const messages = [{id: 1}, {id: 2}, {id: 3}]; diff --git a/web/tests/message_list_view.test.js b/web/tests/message_list_view.test.js index 4cdf881ab9..f93610a8c8 100644 --- a/web/tests/message_list_view.test.js +++ b/web/tests/message_list_view.test.js @@ -30,6 +30,7 @@ mock_esm("../src/people", { const {Filter} = zrequire("../src/filter"); const {MessageListView} = zrequire("../src/message_list_view"); const message_list = zrequire("message_list"); +const {MessageListData} = zrequire("message_list_data"); const muted_users = zrequire("muted_users"); let next_timestamp = 1500000000; @@ -473,7 +474,10 @@ test("merge_message_groups", ({mock_template}) => { const filter = new Filter([{operator: "stream", operand: "foo"}]); const list = new message_list.MessageList({ - filter, + data: new MessageListData({ + excludes_muted_topics: false, + filter, + }), is_node_test: true, }); @@ -734,7 +738,10 @@ test("render_windows", ({mock_template}) => { const filter = new Filter([]); const list = new message_list.MessageList({ - filter, + data: new MessageListData({ + excludes_muted_topics: false, + filter, + }), is_node_test: true, }); diff --git a/web/tests/popover_menus_data.test.js b/web/tests/popover_menus_data.test.js index 92d64d27fc..764be29285 100644 --- a/web/tests/popover_menus_data.test.js +++ b/web/tests/popover_menus_data.test.js @@ -15,6 +15,7 @@ const popover_menus_data = zrequire("popover_menus_data"); const people = zrequire("people"); const compose_state = zrequire("compose_state"); const user_groups = zrequire("user_groups"); +const {MessageListData} = zrequire("message_list_data"); const noop = function () {}; @@ -104,7 +105,10 @@ function add_initialize_users() { function init_message_list() { const filter = new Filter([]); const list = new MessageList({ - filter, + data: new MessageListData({ + excludes_muted_topics: false, + filter, + }), }); assert.equal(list.empty(), true);