2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-02-28 00:39:51 +01:00
|
|
|
const rewiremock = require("rewiremock/node");
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-02-28 00:57:20 +01:00
|
|
|
rewiremock("../../static/js/resize").with({
|
2020-04-13 18:53:07 +02:00
|
|
|
resize_stream_filters_container: () => {},
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
|
2021-02-28 00:39:51 +01:00
|
|
|
const channel = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/channel").with(channel);
|
2021-02-28 00:51:57 +01:00
|
|
|
const compose = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/compose").with(compose);
|
2021-02-11 01:42:59 +01:00
|
|
|
const compose_actions = set_global("compose_actions", {});
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("current_msg_list", {});
|
2021-02-28 01:07:47 +01:00
|
|
|
const hashchange = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/hashchange").with(hashchange);
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("home_msg_list", {});
|
2021-02-10 04:53:22 +01:00
|
|
|
const message_fetch = set_global("message_fetch", {});
|
|
|
|
const message_list = set_global("message_list", {
|
2020-07-20 22:18:43 +02:00
|
|
|
set_narrowed(value) {
|
2020-07-15 00:34:28 +02:00
|
|
|
this.narrowed = value;
|
|
|
|
},
|
2018-08-04 08:30:52 +02:00
|
|
|
});
|
2021-02-28 00:59:17 +01:00
|
|
|
const message_scroll = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/message_scroll").with(message_scroll);
|
2021-02-28 01:10:31 +01:00
|
|
|
rewiremock("../../static/js/message_util").with({});
|
2021-02-28 01:06:34 +01:00
|
|
|
const notifications = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/notifications").with(notifications);
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("page_params", {});
|
2021-02-28 01:04:58 +01:00
|
|
|
const search = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/search").with(search);
|
2021-02-11 01:42:59 +01:00
|
|
|
const stream_list = set_global("stream_list", {});
|
|
|
|
const message_view_header = set_global("message_view_header", {});
|
2021-02-28 00:44:57 +01:00
|
|
|
const top_left_corner = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/top_left_corner").with(top_left_corner);
|
2021-02-11 01:42:59 +01:00
|
|
|
const typing_events = set_global("typing_events", {});
|
2021-02-28 01:00:36 +01:00
|
|
|
const ui_util = {__esModule: true};
|
|
|
|
rewiremock("../../static/js/ui_util").with(ui_util);
|
2021-02-11 01:42:59 +01:00
|
|
|
const unread_ops = set_global("unread_ops", {});
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("search_pill_widget", {
|
2018-07-23 02:20:57 +02:00
|
|
|
widget: {
|
2020-07-20 22:18:43 +02:00
|
|
|
clear() {
|
2020-07-15 00:34:28 +02:00
|
|
|
return true;
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
appendValue() {
|
2020-07-15 00:34:28 +02:00
|
|
|
return true;
|
|
|
|
},
|
2018-07-14 16:10:00 +02:00
|
|
|
},
|
|
|
|
});
|
2020-09-24 19:39:58 +02:00
|
|
|
set_global("recent_topics", {
|
|
|
|
hide: () => {},
|
|
|
|
is_visible: () => {},
|
|
|
|
});
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// We have strange hacks in narrow.activate to sleep 0
|
|
|
|
// 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();
|
|
|
|
});
|
|
|
|
|
2021-02-28 00:41:04 +01:00
|
|
|
rewiremock("../../static/js/muting").with({
|
2018-05-14 19:57:46 +02:00
|
|
|
is_topic_muted: () => false,
|
|
|
|
});
|
|
|
|
|
2021-02-28 00:39:51 +01:00
|
|
|
rewiremock.enable();
|
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const util = zrequire("util");
|
|
|
|
const narrow_state = zrequire("narrow_state");
|
|
|
|
const stream_data = zrequire("stream_data");
|
|
|
|
zrequire("unread");
|
|
|
|
const narrow = zrequire("narrow");
|
|
|
|
|
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
|
|
|
|
|
|
|
function test_helper() {
|
2019-11-02 00:06:25 +01:00
|
|
|
let events = [];
|
2018-04-11 22:16:30 +02:00
|
|
|
|
2021-02-11 01:42:59 +01:00
|
|
|
function stub(module, func_name) {
|
|
|
|
module[func_name] = () => {
|
|
|
|
events.push([module, func_name]);
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-02-11 01:42:59 +01:00
|
|
|
stub(compose_actions, "on_narrow");
|
|
|
|
stub(hashchange, "save_narrow");
|
|
|
|
stub(message_scroll, "hide_indicators");
|
|
|
|
stub(message_scroll, "show_loading_older");
|
|
|
|
stub(message_scroll, "hide_top_of_narrow_notices");
|
|
|
|
stub(notifications, "clear_compose_notifications");
|
|
|
|
stub(notifications, "redraw_title");
|
|
|
|
stub(search, "update_button_visibility");
|
|
|
|
stub(stream_list, "handle_narrow_activated");
|
|
|
|
stub(message_view_header, "initialize");
|
|
|
|
stub(top_left_corner, "handle_narrow_activated");
|
|
|
|
stub(typing_events, "render_notifications_for_narrow");
|
|
|
|
stub(ui_util, "change_tab_to");
|
|
|
|
stub(unread_ops, "process_visible");
|
|
|
|
stub(compose, "update_closed_compose_buttons_for_stream");
|
|
|
|
stub(compose, "update_closed_compose_buttons_for_private");
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
clear: () => {
|
|
|
|
events = [];
|
|
|
|
},
|
|
|
|
push_event: (event) => {
|
|
|
|
events.push(event);
|
|
|
|
},
|
|
|
|
assert_events: (expected_events) => {
|
|
|
|
assert.deepEqual(expected_events, events);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function stub_message_list() {
|
2018-05-14 15:46:25 +02:00
|
|
|
message_list.MessageList = function (opts) {
|
2018-05-14 19:57:46 +02:00
|
|
|
this.data = opts.data;
|
2018-05-03 04:33:06 +02:00
|
|
|
this.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
|
|
|
},
|
|
|
|
};
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
message_list.MessageList.prototype = {
|
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);
|
2018-04-11 22:16:30 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
empty() {
|
2018-05-14 19:57:46 +02:00
|
|
|
return this.data.empty();
|
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;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("basics", () => {
|
2018-04-11 22:16:30 +02:00
|
|
|
stub_message_list();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const helper = test_helper();
|
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,
|
2020-07-02 01:41:40 +02:00
|
|
|
offset: () => ({top: 25}),
|
2018-05-03 04:33:06 +02:00
|
|
|
};
|
|
|
|
|
2020-07-02 01:41:40 +02:00
|
|
|
current_msg_list.selected_id = () => -1;
|
|
|
|
current_msg_list.get_row = () => row;
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
message_list.all = {
|
2020-07-02 01:41:40 +02:00
|
|
|
all_messages: () => messages,
|
2018-04-11 22:16:30 +02:00
|
|
|
get: (msg_id) => {
|
2018-05-03 04:33:06 +02:00
|
|
|
assert.equal(msg_id, selected_id);
|
2018-04-11 22:16:30 +02:00
|
|
|
return selected_message;
|
|
|
|
},
|
2020-05-30 09:45:12 +02:00
|
|
|
data: {
|
|
|
|
fetch_status: {
|
|
|
|
has_found_newest: () => true,
|
|
|
|
},
|
2018-06-01 01:07:45 +02:00
|
|
|
},
|
|
|
|
empty: () => false,
|
2020-07-02 01:41:40 +02:00
|
|
|
first: () => ({id: 900}),
|
|
|
|
last: () => ({id: 1100}),
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let cont;
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
message_fetch.load_messages_for_narrow = (opts) => {
|
|
|
|
cont = opts.cont;
|
|
|
|
|
|
|
|
assert.deepEqual(opts, {
|
|
|
|
cont: opts.cont,
|
2020-01-28 06:57:07 +01:00
|
|
|
anchor: 1000,
|
2018-04-11 22:16:30 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-05-03 04:33:06 +02:00
|
|
|
narrow.activate(terms, {
|
|
|
|
then_select_id: selected_id,
|
|
|
|
});
|
2018-04-11 22:16:30 +02:00
|
|
|
|
|
|
|
assert.equal(message_list.narrowed.selected_id, selected_id);
|
2018-05-03 04:33:06 +02:00
|
|
|
assert.equal(message_list.narrowed.view.offset, 25);
|
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([
|
2021-02-11 01:42:59 +01:00
|
|
|
[notifications, "clear_compose_notifications"],
|
|
|
|
[notifications, "redraw_title"],
|
|
|
|
[message_scroll, "hide_top_of_narrow_notices"],
|
|
|
|
[message_scroll, "hide_indicators"],
|
|
|
|
[ui_util, "change_tab_to"],
|
|
|
|
[unread_ops, "process_visible"],
|
|
|
|
[hashchange, "save_narrow"],
|
|
|
|
[compose, "update_closed_compose_buttons_for_stream"],
|
|
|
|
[search, "update_button_visibility"],
|
|
|
|
[compose_actions, "on_narrow"],
|
|
|
|
[top_left_corner, "handle_narrow_activated"],
|
|
|
|
[stream_list, "handle_narrow_activated"],
|
|
|
|
[typing_events, "render_notifications_for_narrow"],
|
|
|
|
[message_view_header, "initialize"],
|
2018-04-11 22:16:30 +02:00
|
|
|
]);
|
|
|
|
|
2020-07-02 01:41:40 +02:00
|
|
|
current_msg_list.selected_id = () => -1;
|
|
|
|
current_msg_list.get_row = () => row;
|
|
|
|
util.sorted_ids = () => [];
|
2018-08-13 23:17:45 +02:00
|
|
|
|
2020-07-16 22:40:18 +02:00
|
|
|
narrow.activate([{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);
|
|
|
|
|
2018-04-11 22:16:30 +02:00
|
|
|
channel.post = (opts) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(opts.url, "/json/report/narrow_times");
|
|
|
|
helper.push_event("report narrow times");
|
2018-04-11 22:16:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
helper.clear();
|
|
|
|
cont();
|
2020-07-15 00:34:28 +02:00
|
|
|
helper.assert_events(["report narrow times"]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2021-02-28 00:39:51 +01:00
|
|
|
rewiremock.disable();
|