2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2023-02-22 23:04:10 +01:00
|
|
|
const $ = require("./lib/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2024-04-30 16:28:32 +02:00
|
|
|
set_global("history", {});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/resize", {
|
2022-11-17 23:33:43 +01:00
|
|
|
resize_stream_filters_container() {},
|
2020-04-13 18:53:07 +02:00
|
|
|
});
|
2024-02-13 03:44:04 +01:00
|
|
|
const {Filter} = zrequire("../src/filter");
|
2023-02-22 23:04:10 +01:00
|
|
|
const all_messages_data = mock_esm("../src/all_messages_data");
|
2023-10-07 01:08:53 +02:00
|
|
|
const browser_history = mock_esm("../src/browser_history", {
|
|
|
|
state: {changing_hash: false},
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const compose_actions = mock_esm("../src/compose_actions");
|
|
|
|
const compose_banner = mock_esm("../src/compose_banner");
|
|
|
|
const compose_closed_ui = mock_esm("../src/compose_closed_ui");
|
2023-08-04 23:40:48 +02:00
|
|
|
const compose_recipient = mock_esm("../src/compose_recipient");
|
2023-02-22 23:04:10 +01:00
|
|
|
const message_fetch = mock_esm("../src/message_fetch");
|
|
|
|
const message_list = mock_esm("../src/message_list");
|
|
|
|
const message_lists = mock_esm("../src/message_lists", {
|
2024-01-17 07:53:40 +01:00
|
|
|
current: {
|
|
|
|
view: {
|
|
|
|
$list: {
|
|
|
|
remove: noop,
|
|
|
|
removeClass: noop,
|
|
|
|
addClass: noop,
|
|
|
|
},
|
|
|
|
},
|
2024-02-13 03:44:04 +01:00
|
|
|
data: {
|
|
|
|
filter: new Filter([{operator: "in", operand: "all"}]),
|
|
|
|
},
|
2024-01-17 07:53:40 +01:00
|
|
|
},
|
2024-02-05 12:59:04 +01:00
|
|
|
update_current_message_list(msg_list) {
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current = msg_list;
|
|
|
|
},
|
2024-04-21 05:31:35 +02:00
|
|
|
all_rendered_message_lists() {
|
|
|
|
return [message_lists.current];
|
|
|
|
},
|
2021-03-30 02:21:21 +02:00
|
|
|
});
|
2023-06-01 01:57:47 +02:00
|
|
|
const message_feed_top_notices = mock_esm("../src/message_feed_top_notices");
|
2023-05-10 18:06:57 +02:00
|
|
|
const message_feed_loading = mock_esm("../src/message_feed_loading");
|
2023-02-22 23:04:10 +01:00
|
|
|
const message_view_header = mock_esm("../src/message_view_header");
|
2023-10-07 01:08:53 +02:00
|
|
|
const message_viewport = mock_esm("../src/message_viewport");
|
2023-08-08 23:59:25 +02:00
|
|
|
const narrow_history = mock_esm("../src/narrow_history");
|
2023-10-05 23:18:00 +02:00
|
|
|
const narrow_title = mock_esm("../src/narrow_title");
|
2024-04-30 16:28:32 +02:00
|
|
|
const stream_list = mock_esm("../src/stream_list", {is_zoomed_in: () => false});
|
2023-06-15 17:07:10 +02:00
|
|
|
const left_sidebar_navigation_area = mock_esm("../src/left_sidebar_navigation_area");
|
2023-02-22 23:04:10 +01:00
|
|
|
const typing_events = mock_esm("../src/typing_events");
|
|
|
|
const unread_ops = mock_esm("../src/unread_ops");
|
2022-12-21 06:39:20 +01:00
|
|
|
mock_esm("../src/pm_list", {
|
|
|
|
handle_narrow_activated() {},
|
|
|
|
});
|
2023-04-19 07:00:47 +02:00
|
|
|
mock_esm("../src/unread_ui", {
|
|
|
|
reset_unread_banner() {},
|
|
|
|
update_unread_banner() {},
|
|
|
|
});
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
//
|
2024-06-05 10:51:22 +02:00
|
|
|
// We have strange hacks in message_view.show to sleep 0
|
2018-04-11 22:16:30 +02:00
|
|
|
// seconds.
|
2020-12-01 00:02:16 +01:00
|
|
|
set_global("setTimeout", (f, t) => {
|
2018-04-11 22:16:30 +02:00
|
|
|
assert.equal(t, 0);
|
|
|
|
f();
|
|
|
|
});
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/user_topics", {
|
2018-05-14 19:57:46 +02:00
|
|
|
is_topic_muted: () => false,
|
|
|
|
});
|
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
const {buddy_list} = zrequire("buddy_list");
|
|
|
|
const activity_ui = zrequire("activity_ui");
|
2020-12-01 23:21:38 +01:00
|
|
|
const narrow_state = zrequire("narrow_state");
|
|
|
|
const stream_data = zrequire("stream_data");
|
2024-06-05 10:51:22 +02:00
|
|
|
const message_view = zrequire("message_view");
|
2023-08-23 02:18:53 +02:00
|
|
|
const people = zrequire("people");
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const denmark = {
|
2018-04-11 22:16:30 +02:00
|
|
|
subscribed: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
color: "blue",
|
|
|
|
name: "Denmark",
|
2018-04-11 22:16:30 +02:00
|
|
|
stream_id: 1,
|
2019-05-15 08:54:25 +02:00
|
|
|
is_muted: true,
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(denmark);
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2023-08-04 23:40:48 +02:00
|
|
|
function test_helper({override}) {
|
2023-04-12 19:12:57 +02:00
|
|
|
const events = [];
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2021-02-11 01:42:59 +01:00
|
|
|
function stub(module, func_name) {
|
2023-08-04 23:40:48 +02:00
|
|
|
override(module, func_name, () => {
|
2021-02-11 01:42:59 +01:00
|
|
|
events.push([module, func_name]);
|
2023-08-04 23:40:48 +02:00
|
|
|
});
|
2018-04-11 22:16:30 +02:00
|
|
|
}
|
|
|
|
|
2023-10-07 01:08:53 +02:00
|
|
|
stub(browser_history, "set_hash");
|
2023-02-02 03:38:52 +01:00
|
|
|
stub(compose_banner, "clear_message_sent_banners");
|
2021-02-11 01:42:59 +01:00
|
|
|
stub(compose_actions, "on_narrow");
|
2021-05-10 17:21:20 +02:00
|
|
|
stub(compose_closed_ui, "update_reply_recipient_label");
|
2023-10-07 07:29:41 +02:00
|
|
|
stub(compose_recipient, "handle_middle_pane_transition");
|
2023-08-08 23:59:25 +02:00
|
|
|
stub(narrow_history, "save_narrow_state_and_flush");
|
2023-05-10 18:06:57 +02:00
|
|
|
stub(message_feed_loading, "hide_indicators");
|
2023-06-01 01:57:47 +02:00
|
|
|
stub(message_feed_top_notices, "hide_top_of_narrow_notices");
|
2023-10-05 23:18:00 +02:00
|
|
|
stub(narrow_title, "update_narrow_title");
|
2021-02-11 01:42:59 +01:00
|
|
|
stub(stream_list, "handle_narrow_activated");
|
2023-06-21 04:26:37 +02:00
|
|
|
stub(message_view_header, "render_title_area");
|
2023-10-07 01:08:53 +02:00
|
|
|
stub(message_viewport, "stop_auto_scrolling");
|
2023-06-15 17:07:10 +02:00
|
|
|
stub(left_sidebar_navigation_area, "handle_narrow_activated");
|
2021-02-11 01:42:59 +01:00
|
|
|
stub(typing_events, "render_notifications_for_narrow");
|
|
|
|
stub(unread_ops, "process_visible");
|
2023-10-04 18:36:15 +02:00
|
|
|
stub(compose_closed_ui, "update_buttons_for_stream_views");
|
2021-05-11 22:04:35 +02:00
|
|
|
stub(compose_closed_ui, "update_buttons_for_private");
|
2022-03-29 21:50:43 +02:00
|
|
|
// We don't test the css calls; we just skip over them.
|
2023-12-14 23:51:33 +01:00
|
|
|
$("#mark_read_on_scroll_state_banner").toggleClass = noop;
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
return {
|
2022-11-17 23:33:43 +01:00
|
|
|
assert_events(expected_events) {
|
2021-11-26 15:07:07 +01:00
|
|
|
assert.deepEqual(events, expected_events);
|
2018-04-11 22:16:30 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function stub_message_list() {
|
2022-04-19 02:45:44 +02:00
|
|
|
message_list.MessageList = class MessageList {
|
|
|
|
constructor(opts) {
|
|
|
|
this.data = opts.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
view = {
|
2020-07-20 22:18:43 +02:00
|
|
|
set_message_offset(offset) {
|
2021-01-23 02:52:49 +01:00
|
|
|
this.offset = offset;
|
2018-05-03 04:33:06 +02:00
|
|
|
},
|
2024-01-17 07:53:40 +01:00
|
|
|
|
|
|
|
$list: {
|
|
|
|
remove: noop,
|
|
|
|
removeClass: noop,
|
|
|
|
addClass: noop,
|
|
|
|
},
|
2018-05-03 04:33:06 +02:00
|
|
|
};
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
get(msg_id) {
|
2018-05-14 19:57:46 +02:00
|
|
|
return this.data.get(msg_id);
|
2022-04-19 02:45:44 +02:00
|
|
|
}
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2023-05-02 04:04:46 +02:00
|
|
|
visibly_empty() {
|
|
|
|
return this.data.visibly_empty();
|
2022-04-19 02:45:44 +02:00
|
|
|
}
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
select_id(msg_id) {
|
2018-04-11 22:16:30 +02:00
|
|
|
this.selected_id = msg_id;
|
2022-04-19 02:45:44 +02:00
|
|
|
}
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-08-04 23:40:48 +02:00
|
|
|
run_test("basics", ({override}) => {
|
2018-04-11 22:16:30 +02:00
|
|
|
stub_message_list();
|
2023-08-23 02:18:53 +02:00
|
|
|
activity_ui.set_cursor_and_filter();
|
|
|
|
|
|
|
|
const me = {
|
|
|
|
email: "me@zulip.com",
|
|
|
|
user_id: 999,
|
|
|
|
full_name: "Me Myself",
|
|
|
|
};
|
|
|
|
people.add_active_user(me);
|
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
override(buddy_list, "populate", noop);
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2023-08-04 23:40:48 +02:00
|
|
|
const helper = test_helper({override});
|
2020-07-15 00:34:28 +02:00
|
|
|
const terms = [{operator: "stream", operand: "Denmark"}];
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const selected_id = 1000;
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const selected_message = {
|
2018-04-11 22:16:30 +02:00
|
|
|
id: selected_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2018-04-11 22:16:30 +02:00
|
|
|
stream_id: denmark.stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "whatever",
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const messages = [selected_message];
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const row = {
|
2018-05-03 04:33:06 +02:00
|
|
|
length: 1,
|
2023-05-20 16:30:21 +02:00
|
|
|
get_offset_to_window: () => ({top: 25}),
|
2018-05-03 04:33:06 +02:00
|
|
|
};
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.selected_id = () => -1;
|
|
|
|
message_lists.current.get_row = () => row;
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2021-03-30 06:23:09 +02:00
|
|
|
all_messages_data.all_messages_data = {
|
2020-07-02 01:41:40 +02:00
|
|
|
all_messages: () => messages,
|
2023-05-02 04:04:46 +02:00
|
|
|
visibly_empty: () => false,
|
2020-07-02 01:41:40 +02:00
|
|
|
first: () => ({id: 900}),
|
|
|
|
last: () => ({id: 1100}),
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
|
2023-11-09 09:33:30 +01:00
|
|
|
$("#navbar-fixed-container").set_height(40);
|
|
|
|
$("#compose").get_offset_to_window = () => ({top: 200});
|
|
|
|
|
2018-04-11 22:16:30 +02:00
|
|
|
message_fetch.load_messages_for_narrow = (opts) => {
|
2022-12-09 20:33:10 +01:00
|
|
|
// Only validates the anchor and set of fields
|
2018-04-11 22:16:30 +02:00
|
|
|
assert.deepEqual(opts, {
|
|
|
|
cont: opts.cont,
|
2022-12-09 20:33:10 +01:00
|
|
|
msg_list: opts.msg_list,
|
2020-01-28 06:57:07 +01:00
|
|
|
anchor: 1000,
|
2018-04-11 22:16:30 +02:00
|
|
|
});
|
2023-04-12 19:12:57 +02:00
|
|
|
|
|
|
|
opts.cont();
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
|
2024-06-05 10:51:22 +02:00
|
|
|
message_view.show(terms, {
|
2018-05-03 04:33:06 +02:00
|
|
|
then_select_id: selected_id,
|
|
|
|
});
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2022-09-07 09:06:25 +02:00
|
|
|
assert.equal(message_lists.current.selected_id, selected_id);
|
2023-11-09 09:33:30 +01:00
|
|
|
// 25 was the offset of the selected message but it is low for the
|
|
|
|
// message top to be visible, so we use set offset to navbar height + header height.
|
|
|
|
assert.equal(message_lists.current.view.offset, 80);
|
2018-08-13 23:17:45 +02:00
|
|
|
assert.equal(narrow_state.narrowed_to_pms(), false);
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
helper.assert_events([
|
2023-06-01 01:57:47 +02:00
|
|
|
[message_feed_top_notices, "hide_top_of_narrow_notices"],
|
2023-05-10 18:06:57 +02:00
|
|
|
[message_feed_loading, "hide_indicators"],
|
2023-02-02 03:38:52 +01:00
|
|
|
[compose_banner, "clear_message_sent_banners"],
|
2024-05-09 07:55:11 +02:00
|
|
|
[message_viewport, "stop_auto_scrolling"],
|
|
|
|
[browser_history, "set_hash"],
|
2024-01-31 18:50:51 +01:00
|
|
|
[compose_actions, "on_narrow"],
|
2021-02-11 01:42:59 +01:00
|
|
|
[unread_ops, "process_visible"],
|
2023-08-08 23:59:25 +02:00
|
|
|
[narrow_history, "save_narrow_state_and_flush"],
|
2023-10-04 02:49:37 +02:00
|
|
|
[typing_events, "render_notifications_for_narrow"],
|
2023-10-04 18:36:15 +02:00
|
|
|
[compose_closed_ui, "update_buttons_for_stream_views"],
|
2021-05-10 17:21:20 +02:00
|
|
|
[compose_closed_ui, "update_reply_recipient_label"],
|
2023-10-04 02:49:37 +02:00
|
|
|
[message_view_header, "render_title_area"],
|
2023-10-05 23:18:00 +02:00
|
|
|
[narrow_title, "update_narrow_title"],
|
2023-06-15 17:07:10 +02:00
|
|
|
[left_sidebar_navigation_area, "handle_narrow_activated"],
|
2021-02-11 01:42:59 +01:00
|
|
|
[stream_list, "handle_narrow_activated"],
|
2023-10-07 07:29:41 +02:00
|
|
|
[compose_recipient, "handle_middle_pane_transition"],
|
2018-04-11 22:16:30 +02:00
|
|
|
]);
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.selected_id = () => -1;
|
|
|
|
message_lists.current.get_row = () => row;
|
2018-08-13 23:17:45 +02:00
|
|
|
|
2024-06-05 10:51:22 +02:00
|
|
|
message_view.show([{operator: "is", operand: "private"}], {
|
2018-08-13 23:17:45 +02:00
|
|
|
then_select_id: selected_id,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(narrow_state.narrowed_to_pms(), true);
|
2023-11-09 09:33:30 +01:00
|
|
|
|
|
|
|
message_lists.current.selected_id = () => -1;
|
|
|
|
// Row offset is between navbar and compose, so we keep it in the same position.
|
|
|
|
row.get_offset_to_window = () => ({top: 100, bottom: 150});
|
|
|
|
message_lists.current.get_row = () => row;
|
|
|
|
|
2024-06-05 10:51:22 +02:00
|
|
|
message_view.show(terms, {
|
2023-11-09 09:33:30 +01:00
|
|
|
then_select_id: selected_id,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(message_lists.current.view.offset, 100);
|
|
|
|
|
|
|
|
message_lists.current.selected_id = () => -1;
|
|
|
|
// Row is below navbar and row bottom is below compose but since the message is
|
|
|
|
// visible enough, we don't scroll the message to a new position.
|
|
|
|
row.get_offset_to_window = () => ({top: 150, bottom: 250});
|
|
|
|
message_lists.current.get_row = () => row;
|
|
|
|
|
2024-06-05 10:51:22 +02:00
|
|
|
message_view.show(terms, {
|
2023-11-09 09:33:30 +01:00
|
|
|
then_select_id: selected_id,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(message_lists.current.view.offset, 150);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|