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, 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");
|
|
|
|
const {page_params} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2022-04-01 20:46:02 +02:00
|
|
|
const test_url = () => "https://www.example.com";
|
2020-08-20 21:24:06 +02:00
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
// We assign this in our test() wrapper.
|
|
|
|
let messages;
|
2021-03-06 17:37:51 +01:00
|
|
|
|
2023-03-13 05:24:16 +01:00
|
|
|
const private_messages = [];
|
|
|
|
|
2021-03-07 13:57:14 +01:00
|
|
|
// sender1 == current user
|
|
|
|
// sender2 == any other user
|
|
|
|
const sender1 = 1;
|
|
|
|
const sender2 = 2;
|
|
|
|
|
|
|
|
// New stream
|
|
|
|
const stream1 = 1;
|
|
|
|
const stream2 = 2;
|
|
|
|
const stream3 = 3;
|
|
|
|
const stream4 = 4;
|
|
|
|
const stream5 = 5; // Deleted stream
|
2023-10-01 11:18:56 +02:00
|
|
|
const stream6 = 6; // Muted stream
|
2021-03-07 13:57:14 +01:00
|
|
|
|
|
|
|
// Topics in the stream, all unread except topic1 & stream1.
|
2021-05-10 07:02:14 +02:00
|
|
|
const topic1 = "topic-1"; // No other sender & read.
|
2021-03-07 13:57:14 +01:00
|
|
|
const topic2 = "topic-2"; // Other sender
|
|
|
|
const topic3 = "topic-3"; // User not present
|
|
|
|
const topic4 = "topic-4"; // User not present
|
|
|
|
const topic5 = "topic-5"; // other sender
|
|
|
|
const topic6 = "topic-6"; // other sender
|
|
|
|
const topic7 = "topic-7"; // muted topic
|
|
|
|
const topic8 = "topic-8";
|
|
|
|
const topic9 = "topic-9";
|
|
|
|
const topic10 = "topic-10";
|
2023-10-01 11:18:56 +02:00
|
|
|
const topic11 = "topic-11"; // unmuted topic
|
|
|
|
const topic12 = "topic-12"; // followed topic
|
2021-03-07 13:57:14 +01:00
|
|
|
|
2023-07-27 14:57:55 +02:00
|
|
|
const all_visibility_policies = {
|
|
|
|
INHERIT: 0,
|
|
|
|
MUTED: 1,
|
|
|
|
UNMUTED: 2,
|
|
|
|
FOLLOWED: 3,
|
|
|
|
};
|
|
|
|
|
2021-05-12 17:49:58 +02:00
|
|
|
let expected_data_to_replace_in_list_widget;
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const ListWidget = mock_esm("../src/list_widget", {
|
2023-09-16 00:03:52 +02:00
|
|
|
modifier_html: noop,
|
2023-05-03 07:06:19 +02:00
|
|
|
generic_sort_functions: noop,
|
2023-06-29 21:59:08 +02:00
|
|
|
create(_container, mapped_topic_values, opts) {
|
2020-06-01 17:17:41 +02:00
|
|
|
const formatted_topics = [];
|
2023-09-16 00:03:52 +02:00
|
|
|
ListWidget.modifier_html = opts.modifier_html;
|
2020-06-01 17:17:41 +02:00
|
|
|
for (const item of mapped_topic_values) {
|
2023-09-16 00:03:52 +02:00
|
|
|
formatted_topics.push(opts.modifier_html(item));
|
2020-06-01 17:17:41 +02:00
|
|
|
opts.filter.predicate(item);
|
|
|
|
}
|
2020-06-01 13:24:29 +02:00
|
|
|
// Just for coverage, the mechanisms
|
2023-02-22 23:04:10 +01:00
|
|
|
// are tested in list_widget.test.js
|
2020-06-01 13:24:29 +02:00
|
|
|
if (mapped_topic_values.length >= 2) {
|
|
|
|
opts.sort_fields.stream_sort(mapped_topic_values[0], mapped_topic_values[1]);
|
|
|
|
opts.sort_fields.stream_sort(mapped_topic_values[1], mapped_topic_values[0]);
|
|
|
|
opts.sort_fields.stream_sort(mapped_topic_values[0], mapped_topic_values[0]);
|
|
|
|
opts.sort_fields.topic_sort(mapped_topic_values[0], mapped_topic_values[1]);
|
|
|
|
opts.sort_fields.topic_sort(mapped_topic_values[1], mapped_topic_values[0]);
|
|
|
|
opts.sort_fields.topic_sort(mapped_topic_values[0], mapped_topic_values[0]);
|
|
|
|
}
|
2021-01-29 10:27:56 +01:00
|
|
|
return ListWidget;
|
2020-06-01 17:17:41 +02:00
|
|
|
},
|
2021-02-28 00:57:45 +01:00
|
|
|
|
2020-06-01 17:17:41 +02:00
|
|
|
hard_redraw: noop,
|
2022-10-29 15:55:36 +02:00
|
|
|
filter_and_sort: noop,
|
2022-11-17 23:33:43 +01:00
|
|
|
replace_list_data(data) {
|
2022-04-09 23:44:38 +02:00
|
|
|
assert.notEqual(
|
|
|
|
expected_data_to_replace_in_list_widget,
|
|
|
|
undefined,
|
|
|
|
"You must set expected_data_to_replace_in_list_widget",
|
|
|
|
);
|
2021-05-12 17:49:58 +02:00
|
|
|
assert.deepEqual(data, expected_data_to_replace_in_list_widget);
|
|
|
|
expected_data_to_replace_in_list_widget = undefined;
|
|
|
|
},
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/compose_closed_ui", {
|
2021-05-11 22:04:35 +02:00
|
|
|
set_standard_text_for_reply_button: noop,
|
2024-02-25 21:54:42 +01:00
|
|
|
update_buttons_for_non_specific_views: noop,
|
2020-07-05 12:19:09 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/hash_util", {
|
2022-04-01 20:46:02 +02:00
|
|
|
by_stream_url: test_url,
|
|
|
|
by_stream_topic_url: test_url,
|
|
|
|
by_conversation_and_time_url: test_url,
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/message_list_data", {
|
2021-04-16 17:44:46 +02:00
|
|
|
MessageListData: class {},
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/message_store", {
|
2023-03-13 05:24:16 +01:00
|
|
|
get(msg_id) {
|
2023-10-01 11:18:56 +02:00
|
|
|
if (msg_id < 15) {
|
2023-03-13 05:24:16 +01:00
|
|
|
return messages[msg_id - 1];
|
|
|
|
}
|
2023-10-01 11:18:56 +02:00
|
|
|
return private_messages[msg_id - 15];
|
2023-03-13 05:24:16 +01:00
|
|
|
},
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/message_view_header", {
|
2021-03-07 13:57:14 +01:00
|
|
|
render_title_area: noop,
|
2020-09-21 01:43:18 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/user_topics", {
|
2022-11-17 23:33:43 +01:00
|
|
|
is_topic_muted(stream_id, topic) {
|
2020-03-21 14:42:10 +01:00
|
|
|
if (stream_id === stream1 && topic === topic7) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2023-10-01 11:18:56 +02:00
|
|
|
is_topic_unmuted_or_followed(stream_id, topic) {
|
|
|
|
if (stream_id === stream6 && (topic === topic11 || topic === topic12)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2023-07-27 14:57:55 +02:00
|
|
|
get_topic_visibility_policy(stream_id, topic) {
|
2023-10-01 11:18:56 +02:00
|
|
|
if (stream_id === stream1 && topic === topic7) {
|
2023-07-27 14:57:55 +02:00
|
|
|
return all_visibility_policies.MUTED;
|
2023-10-01 11:18:56 +02:00
|
|
|
} else if (stream_id === stream6 && topic === topic11) {
|
|
|
|
return all_visibility_policies.UNMUTED;
|
|
|
|
} else if (stream_id === stream6 && topic === topic12) {
|
|
|
|
return all_visibility_policies.FOLLOWED;
|
2023-07-27 14:57:55 +02:00
|
|
|
}
|
|
|
|
return all_visibility_policies.INHERIT;
|
|
|
|
},
|
|
|
|
all_visibility_policies,
|
2020-03-21 14:42:10 +01:00
|
|
|
});
|
2023-10-05 23:18:00 +02:00
|
|
|
mock_esm("../src/narrow_title", {
|
|
|
|
update_narrow_title() {},
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/pm_list", {
|
2022-10-04 23:33:51 +02:00
|
|
|
update_private_messages: noop,
|
2023-10-04 03:05:27 +02:00
|
|
|
handle_message_view_deactivated: noop,
|
2022-10-04 23:33:51 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/recent_senders", {
|
2022-11-24 07:37:21 +01:00
|
|
|
get_topic_recent_senders: () => [2, 1],
|
2023-03-13 05:24:16 +01:00
|
|
|
get_pm_recent_senders(user_ids_string) {
|
|
|
|
return {
|
|
|
|
participants: user_ids_string.split(",").map((user_id) => Number.parseInt(user_id, 10)),
|
|
|
|
};
|
|
|
|
},
|
2020-05-22 08:16:08 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/stream_data", {
|
2023-10-01 11:18:56 +02:00
|
|
|
is_muted(stream_id) {
|
|
|
|
return stream_id === stream6;
|
|
|
|
},
|
2023-07-26 22:07:21 +02:00
|
|
|
get_stream_name_from_id: () => "stream_name",
|
2020-07-12 16:45:42 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/stream_list", {
|
2023-10-04 02:57:25 +02:00
|
|
|
handle_message_view_deactivated: noop,
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/timerender", {
|
2023-04-08 02:13:36 +02:00
|
|
|
relative_time_string_from_date: () => "Just now",
|
2023-05-01 07:02:10 +02:00
|
|
|
get_full_datetime_clarification: () => "date at time",
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-06-15 17:07:10 +02:00
|
|
|
mock_esm("../src/left_sidebar_navigation_area", {
|
2023-09-08 07:51:34 +02:00
|
|
|
highlight_recent_view: noop,
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/unread", {
|
2022-11-17 23:33:43 +01:00
|
|
|
num_unread_for_topic(stream_id, topic) {
|
2021-03-09 14:51:01 +01:00
|
|
|
if (stream_id === 1 && topic === "topic-1") {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2021-03-07 13:57:14 +01:00
|
|
|
},
|
2023-03-13 05:24:16 +01:00
|
|
|
num_unread_for_user_ids_string() {
|
|
|
|
return 0;
|
|
|
|
},
|
2022-10-14 17:37:47 +02:00
|
|
|
topic_has_any_unread_mentions: () => false,
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-05-29 20:59:27 +02:00
|
|
|
mock_esm("../src/resize", {
|
2023-09-06 23:24:16 +02:00
|
|
|
update_recent_view_filters_height: noop,
|
2023-05-29 20:59:27 +02:00
|
|
|
});
|
2024-02-20 01:25:16 +01:00
|
|
|
const dropdown_widget = mock_esm("../src/dropdown_widget", {
|
2024-02-19 14:22:38 +01:00
|
|
|
DataTypes: {NUMBER: "number", STRING: "string"},
|
2024-02-20 01:25:16 +01:00
|
|
|
});
|
2023-11-23 06:35:15 +01:00
|
|
|
dropdown_widget.DropdownWidget = function DropdownWidget() {
|
|
|
|
this.setup = noop;
|
|
|
|
this.render = noop;
|
|
|
|
};
|
2021-03-07 13:57:14 +01:00
|
|
|
|
2021-04-16 17:44:46 +02:00
|
|
|
const {all_messages_data} = zrequire("all_messages_data");
|
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 people = zrequire("people");
|
2023-09-06 23:14:37 +02:00
|
|
|
const rt = zrequire("recent_view_ui");
|
2023-09-06 23:21:13 +02:00
|
|
|
const recent_view_util = zrequire("recent_view_util");
|
2023-09-06 23:22:20 +02:00
|
|
|
const rt_data = zrequire("recent_view_data");
|
2023-03-13 05:24:16 +01:00
|
|
|
const muted_users = zrequire("muted_users");
|
2023-10-04 23:18:48 +02:00
|
|
|
const sub_store = zrequire("sub_store");
|
|
|
|
|
|
|
|
for (const stream_id of [stream1, stream2, stream3, stream4, stream6]) {
|
|
|
|
sub_store.add_hydrated_sub(stream_id, {
|
|
|
|
color: "",
|
|
|
|
invite_only: false,
|
|
|
|
is_web_public: true,
|
|
|
|
subscribed: true,
|
|
|
|
});
|
|
|
|
}
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2023-03-22 10:12:58 +01:00
|
|
|
people.add_active_user({
|
|
|
|
email: "alice@zulip.com",
|
|
|
|
user_id: 1,
|
|
|
|
full_name: "Alice Smith",
|
|
|
|
});
|
|
|
|
people.add_active_user({
|
|
|
|
email: "fred@zulip.com",
|
|
|
|
user_id: 2,
|
|
|
|
full_name: "Fred Flintstone",
|
|
|
|
});
|
2023-03-13 05:24:16 +01:00
|
|
|
people.add_active_user({
|
|
|
|
email: "spike@zulip.com",
|
|
|
|
user_id: 3,
|
|
|
|
full_name: "Spike Spiegel",
|
|
|
|
});
|
2023-03-15 22:19:06 +01:00
|
|
|
people.add_active_user({
|
|
|
|
email: "eren@zulip.com",
|
|
|
|
user_id: 4,
|
|
|
|
full_name: "Eren Yeager",
|
|
|
|
});
|
2023-03-13 05:24:16 +01:00
|
|
|
|
2023-03-22 10:12:58 +01:00
|
|
|
people.initialize_current_user(1);
|
2023-03-13 05:24:16 +01:00
|
|
|
muted_users.add_muted_user(2, 17947949);
|
2023-03-15 22:19:06 +01:00
|
|
|
muted_users.add_muted_user(4, 17947949);
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2020-03-21 14:42:10 +01:00
|
|
|
let id = 0;
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
const sample_messages = [];
|
|
|
|
sample_messages[0] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic1,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[1] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic2,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[2] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic2,
|
|
|
|
sender_id: sender2,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[3] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic3,
|
|
|
|
sender_id: sender2,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[4] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic4,
|
|
|
|
sender_id: sender2,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[5] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic5,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[6] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic5,
|
|
|
|
sender_id: sender2,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[7] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic6,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[8] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic6,
|
|
|
|
sender_id: sender2,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[9] = {
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic7,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
};
|
|
|
|
|
2020-06-01 13:24:29 +02:00
|
|
|
// a message of stream4
|
2021-03-16 18:36:49 +01:00
|
|
|
sample_messages[10] = {
|
2020-06-01 13:24:29 +02:00
|
|
|
stream_id: stream4,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-06-01 13:24:29 +02:00
|
|
|
topic: topic10,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-06-01 13:24:29 +02:00
|
|
|
};
|
|
|
|
|
2023-10-01 11:18:56 +02:00
|
|
|
// normal topic in muted stream
|
|
|
|
sample_messages[11] = {
|
|
|
|
stream_id: stream6,
|
|
|
|
id: (id += 1),
|
|
|
|
topic: topic8,
|
|
|
|
sender_id: sender1,
|
|
|
|
type: "stream",
|
|
|
|
};
|
|
|
|
|
|
|
|
// unmuted topic in muted stream
|
|
|
|
sample_messages[12] = {
|
|
|
|
stream_id: stream6,
|
|
|
|
id: (id += 1),
|
|
|
|
topic: topic11,
|
|
|
|
sender_id: sender1,
|
|
|
|
type: "stream",
|
|
|
|
};
|
|
|
|
|
|
|
|
// followed topic in muted stream
|
|
|
|
sample_messages[13] = {
|
|
|
|
stream_id: stream6,
|
|
|
|
id: (id += 1),
|
|
|
|
topic: topic12,
|
|
|
|
sender_id: sender1,
|
|
|
|
type: "stream",
|
|
|
|
};
|
|
|
|
|
2023-03-13 05:24:16 +01:00
|
|
|
private_messages[0] = {
|
|
|
|
id: (id += 1),
|
|
|
|
sender_id: sender1,
|
|
|
|
to_user_ids: "2,3",
|
|
|
|
type: "private",
|
|
|
|
display_recipient: [{id: 1}, {id: 2}, {id: 3}],
|
|
|
|
pm_with_url: test_url(),
|
|
|
|
};
|
2023-03-15 22:19:06 +01:00
|
|
|
private_messages[1] = {
|
|
|
|
id: (id += 1),
|
|
|
|
sender_id: sender1,
|
|
|
|
to_user_ids: "2,4",
|
|
|
|
type: "private",
|
|
|
|
display_recipient: [{id: 1}, {id: 2}, {id: 4}],
|
|
|
|
pm_with_url: test_url(),
|
|
|
|
};
|
|
|
|
private_messages[2] = {
|
|
|
|
id: (id += 1),
|
|
|
|
sender_id: sender1,
|
|
|
|
to_user_ids: "3",
|
|
|
|
type: "private",
|
|
|
|
display_recipient: [{id: 1}, {id: 3}],
|
|
|
|
pm_with_url: test_url(),
|
|
|
|
};
|
2023-03-13 05:24:16 +01:00
|
|
|
|
2020-06-12 12:46:30 +02:00
|
|
|
function get_topic_key(stream_id, topic) {
|
|
|
|
return stream_id + ":" + topic.toLowerCase();
|
|
|
|
}
|
|
|
|
|
2020-05-28 17:04:32 +02:00
|
|
|
function generate_topic_data(topic_info_array) {
|
|
|
|
// Since most of the fields are common, this function helps generate fixtures
|
2022-04-28 05:15:11 +02:00
|
|
|
// with non-common fields.
|
2020-05-29 11:56:19 +02:00
|
|
|
$.clear_all_elements();
|
2020-05-28 17:04:32 +02:00
|
|
|
const data = [];
|
2020-05-29 12:03:22 +02:00
|
|
|
|
2023-10-01 11:18:56 +02:00
|
|
|
for (const [stream_id, topic, unread_count, visibility_policy] of topic_info_array) {
|
2020-05-28 17:04:32 +02:00
|
|
|
data.push({
|
2020-06-12 12:07:48 +02:00
|
|
|
other_senders_count: 0,
|
2022-03-02 00:02:20 +01:00
|
|
|
other_sender_names_html: "",
|
2020-05-26 10:33:35 +02:00
|
|
|
invite_only: false,
|
|
|
|
is_web_public: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
is_private: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
last_msg_time: "Just now",
|
2022-04-01 20:46:02 +02:00
|
|
|
last_msg_url: "https://www.example.com",
|
2021-07-03 08:53:32 +02:00
|
|
|
full_last_msg_date_time: "date at time",
|
2023-09-06 23:25:36 +02:00
|
|
|
senders: people.sender_info_for_recent_view_row([1, 2]),
|
2023-07-26 22:07:21 +02:00
|
|
|
stream_name: "stream_name",
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_color: "",
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
stream_url: "https://www.example.com",
|
2020-07-20 22:18:43 +02:00
|
|
|
topic,
|
2022-04-24 06:13:19 +02:00
|
|
|
conversation_key: get_topic_key(stream_id, topic),
|
2020-07-15 01:29:15 +02:00
|
|
|
topic_url: "https://www.example.com",
|
2020-07-20 22:18:43 +02:00
|
|
|
unread_count,
|
2022-10-14 17:37:47 +02:00
|
|
|
mention_in_unread: false,
|
2023-10-01 11:18:56 +02:00
|
|
|
visibility_policy,
|
2023-07-27 14:57:55 +02:00
|
|
|
all_visibility_policies,
|
2023-11-30 03:07:35 +01:00
|
|
|
is_spectator: page_params.is_spectator,
|
2020-05-28 17:04:32 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
function verify_topic_data(all_topics, stream, topic, last_msg_id, participated) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const topic_data = all_topics.get(stream + ":" + topic);
|
2020-03-21 14:42:10 +01:00
|
|
|
assert.equal(topic_data.last_msg_id, last_msg_id);
|
|
|
|
assert.equal(topic_data.participated, participated);
|
|
|
|
}
|
|
|
|
|
2020-09-23 09:40:59 +02:00
|
|
|
rt.set_default_focus();
|
node_tests: Don't remove require cache of module in zrequire.
There is good reason to do this (explanation is bit long!). With the
TypeScript migration, and the require and ES6 migrations that come
with it, we use require instead of set_global which loads the entire
module. Suppose we have a util module, which is used by some other
module, say message_store, and util is being required in message_store
since it is removed from window. Then, if a test zrequires
message_store first, and then zrequires the util module qand mocks one
of its methods, it will not be mocked for the message_store
module. The reason is:
1. zrequire('message_store') leads to require('util').
2. zrequire('util') removes the util module from cache and it is
reloaded. Now the util module in message_store and the one in
the test will be different and any updates to it in tests won't
be reflected in the actual code.
Which can lead to confusion for folks writing tests. I'll mention this
can be avoided doing zrequire('util') first but...that is not ideal.
And, since there was one outlier test that relied on this behavior,
we add the namespace.reset_module function.
2020-08-19 17:35:27 +02:00
|
|
|
|
2021-02-21 17:00:49 +01:00
|
|
|
function stub_out_filter_buttons() {
|
|
|
|
// TODO: We probably want more direct tests that make sure
|
|
|
|
// the widgets get updated correctly, but the stubs here
|
|
|
|
// should accurately simulate toggling the filters.
|
|
|
|
//
|
|
|
|
// See show_selected_filters() and set_filter() in the
|
|
|
|
// implementation.
|
2023-11-19 07:43:24 +01:00
|
|
|
for (const filter of ["unread", "muted", "participated", "include_private"]) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stub = $.create(`filter-${filter}-stub`);
|
2021-02-21 17:00:49 +01:00
|
|
|
const selector = `[data-filter="${filter}"]`;
|
2023-09-06 23:41:43 +02:00
|
|
|
$("#recent_view_filter_buttons").set_find_results(selector, $stub);
|
2021-02-21 17:00:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 18:28:29 +01:00
|
|
|
function test(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
$(".header").css = noop;
|
2023-07-27 14:57:55 +02:00
|
|
|
page_params.development_environment = true;
|
2021-06-04 19:27:45 +02:00
|
|
|
|
2021-03-16 18:36:49 +01:00
|
|
|
messages = sample_messages.map((message) => ({...message}));
|
2022-07-10 01:06:33 +02:00
|
|
|
f(helpers);
|
2021-03-16 18:28:29 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
test("test_recent_view_show", ({override, mock_template}) => {
|
2020-05-22 08:16:08 +02:00
|
|
|
// Note: unread count and urls are fake,
|
|
|
|
// since they are generated in external libraries
|
|
|
|
// and are not to be tested here.
|
2022-04-14 05:02:53 +02:00
|
|
|
page_params.is_spectator = false;
|
2020-05-22 08:16:08 +02:00
|
|
|
const expected = {
|
2023-11-27 14:20:35 +01:00
|
|
|
filter_unread: false,
|
2020-06-13 14:03:34 +02:00
|
|
|
filter_participated: false,
|
2020-05-29 17:22:53 +02:00
|
|
|
filter_muted: false,
|
2022-04-24 06:13:19 +02:00
|
|
|
filter_pm: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
search_val: "",
|
2022-04-14 05:02:53 +02:00
|
|
|
is_spectator: false,
|
2020-05-22 08:16:08 +02:00
|
|
|
};
|
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
activity_ui.set_cursor_and_filter();
|
|
|
|
|
2023-09-06 23:35:51 +02:00
|
|
|
mock_template("recent_view_table.hbs", false, (data) => {
|
2021-06-14 15:33:00 +02:00
|
|
|
assert.deepEqual(data, expected);
|
2023-09-06 23:35:51 +02:00
|
|
|
return "<recent_view table stub>";
|
2020-05-22 08:16:08 +02:00
|
|
|
});
|
2020-03-21 14:42:10 +01:00
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
mock_template("recent_view_row.hbs", false, noop);
|
2021-06-14 15:33:00 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
let buddy_list_populated = false;
|
|
|
|
override(buddy_list, "populate", () => {
|
|
|
|
buddy_list_populated = true;
|
|
|
|
});
|
|
|
|
|
2021-02-21 17:00:49 +01:00
|
|
|
stub_out_filter_buttons();
|
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;
|
2021-02-21 17:00:49 +01:00
|
|
|
|
2021-03-01 21:08:50 +01:00
|
|
|
rt.clear_for_tests();
|
2024-05-03 20:53:01 +02:00
|
|
|
rt.set_filters_for_tests();
|
2020-05-22 08:16:08 +02:00
|
|
|
rt.process_messages(messages);
|
|
|
|
|
2020-07-05 12:19:09 +02:00
|
|
|
rt.show();
|
2020-05-22 08:16:08 +02:00
|
|
|
|
2023-08-23 02:18:53 +02:00
|
|
|
assert.ok(buddy_list_populated);
|
|
|
|
|
2020-05-22 08:16:08 +02:00
|
|
|
// incorrect topic_key
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(rt.inplace_rerender("stream_unknown:topic_unknown"), false);
|
2020-05-22 08:16:08 +02:00
|
|
|
});
|
|
|
|
|
2023-10-01 06:49:03 +02:00
|
|
|
test("test_filter_is_spectator", ({mock_template}) => {
|
|
|
|
page_params.is_spectator = true;
|
|
|
|
const expected = {
|
2023-11-27 14:20:35 +01:00
|
|
|
filter_unread: false,
|
2023-10-01 06:49:03 +02:00
|
|
|
filter_participated: false,
|
|
|
|
filter_muted: false,
|
|
|
|
filter_pm: false,
|
|
|
|
search_val: "",
|
|
|
|
is_spectator: true,
|
|
|
|
};
|
|
|
|
let row_data;
|
|
|
|
let i;
|
|
|
|
|
|
|
|
mock_template("recent_view_table.hbs", false, (data) => {
|
|
|
|
assert.deepEqual(data, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
mock_template("recent_view_row.hbs", false, (data) => {
|
|
|
|
i -= 1;
|
|
|
|
assert.deepEqual(data, row_data[i]);
|
|
|
|
return "<recent_view row stub>";
|
|
|
|
});
|
|
|
|
|
2023-10-01 11:18:56 +02:00
|
|
|
row_data = generate_topic_data([[1, "topic-1", 0, all_visibility_policies.INHERIT]]);
|
2023-10-01 06:49:03 +02:00
|
|
|
i = row_data.length;
|
|
|
|
rt.clear_for_tests();
|
2024-05-03 20:53:01 +02:00
|
|
|
rt.set_filters_for_tests();
|
2023-10-01 06:49:03 +02:00
|
|
|
stub_out_filter_buttons();
|
|
|
|
recent_view_util.set_visible(true);
|
|
|
|
rt.process_messages([messages[0]]);
|
|
|
|
});
|
|
|
|
|
2023-11-19 07:43:24 +01:00
|
|
|
test("test_no_filter", ({mock_template}) => {
|
2020-05-23 09:04:51 +02:00
|
|
|
// Just tests inplace rerender of a message
|
|
|
|
// in All topics filter.
|
2023-10-01 06:49:03 +02:00
|
|
|
page_params.is_spectator = false;
|
2020-06-01 17:17:41 +02:00
|
|
|
const expected = {
|
2023-11-27 14:20:35 +01:00
|
|
|
filter_unread: false,
|
2020-06-01 17:17:41 +02:00
|
|
|
filter_participated: false,
|
|
|
|
filter_muted: false,
|
2022-04-24 06:13:19 +02:00
|
|
|
filter_pm: false,
|
2020-06-01 17:17:41 +02:00
|
|
|
search_val: "",
|
2023-10-01 06:49:03 +02:00
|
|
|
is_spectator: false,
|
2020-06-01 17:17:41 +02:00
|
|
|
};
|
|
|
|
let row_data;
|
|
|
|
let i;
|
2021-06-14 15:33:00 +02:00
|
|
|
|
2023-09-06 23:35:51 +02:00
|
|
|
mock_template("recent_view_table.hbs", false, (data) => {
|
2021-06-14 15:33:00 +02:00
|
|
|
assert.deepEqual(data, expected);
|
|
|
|
});
|
|
|
|
|
2023-09-06 23:35:51 +02:00
|
|
|
mock_template("recent_view_row.hbs", false, (data) => {
|
2021-06-14 15:33:00 +02:00
|
|
|
i -= 1;
|
|
|
|
assert.deepEqual(data, row_data[i]);
|
2023-09-06 23:35:51 +02:00
|
|
|
return "<recent_view row stub>";
|
2020-05-23 09:04:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// topic is not muted
|
2023-10-01 11:18:56 +02:00
|
|
|
row_data = generate_topic_data([[1, "topic-1", 0, all_visibility_policies.INHERIT]]);
|
2020-06-01 17:17:41 +02:00
|
|
|
i = row_data.length;
|
2021-03-01 21:08:50 +01:00
|
|
|
rt.clear_for_tests();
|
2024-05-03 20:53:01 +02:00
|
|
|
rt.set_filters_for_tests();
|
2021-02-21 17:00:49 +01:00
|
|
|
stub_out_filter_buttons();
|
2023-09-06 23:21:13 +02:00
|
|
|
recent_view_util.set_visible(true);
|
2020-05-23 09:04:51 +02:00
|
|
|
rt.process_messages([messages[0]]);
|
2023-10-01 11:18:56 +02:00
|
|
|
assert.equal(
|
|
|
|
rt.filters_should_hide_topic({last_msg_id: 1, participated: true, type: "stream"}),
|
|
|
|
false,
|
|
|
|
);
|
2020-05-23 09:04:51 +02:00
|
|
|
|
2023-11-23 06:35:15 +01:00
|
|
|
// TODO: Modify this test to work with dropdown widget.
|
|
|
|
// expected_data_to_replace_in_list_widget = [
|
|
|
|
// {last_msg_id: 10, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 1, participated: true, type: "stream"},
|
|
|
|
// ];
|
|
|
|
|
|
|
|
// // topic is muted
|
|
|
|
// row_data = [
|
|
|
|
// ...row_data,
|
|
|
|
// ...generate_topic_data([[1, "topic-7", 1, all_visibility_policies.MUTED]]),
|
|
|
|
// ];
|
|
|
|
// i = row_data.length;
|
|
|
|
// stub_out_filter_buttons();
|
|
|
|
// rt.process_messages([messages[9]]);
|
|
|
|
// assert.equal(
|
|
|
|
// rt.filters_should_hide_topic({last_msg_id: 10, participated: true, type: "stream"}),
|
|
|
|
// true,
|
|
|
|
// );
|
|
|
|
|
|
|
|
// expected_data_to_replace_in_list_widget = [
|
|
|
|
// {last_msg_id: 12, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 10, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 1, participated: true, type: "stream"},
|
|
|
|
// ];
|
|
|
|
// // normal topic in muted stream
|
|
|
|
// row_data = [
|
|
|
|
// ...row_data,
|
|
|
|
// ...generate_topic_data([[6, "topic-8", 1, all_visibility_policies.INHERIT]]),
|
|
|
|
// ];
|
|
|
|
// i = row_data.length;
|
|
|
|
// stub_out_filter_buttons();
|
|
|
|
// rt.process_messages([messages[11]]);
|
|
|
|
// assert.equal(
|
|
|
|
// rt.filters_should_hide_topic({last_msg_id: 12, participated: true, type: "stream"}),
|
|
|
|
// true,
|
|
|
|
// );
|
|
|
|
|
|
|
|
// expected_data_to_replace_in_list_widget = [
|
|
|
|
// {last_msg_id: 13, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 12, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 10, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 1, participated: true, type: "stream"},
|
|
|
|
// ];
|
|
|
|
// // unmuted topic in muted stream
|
|
|
|
// row_data = [
|
|
|
|
// ...row_data,
|
|
|
|
// ...generate_topic_data([[6, "topic-11", 1, all_visibility_policies.UNMUTED]]),
|
|
|
|
// ];
|
|
|
|
// i = row_data.length;
|
|
|
|
// stub_out_filter_buttons();
|
|
|
|
// rt.process_messages([messages[12]]);
|
|
|
|
// assert.equal(
|
|
|
|
// rt.filters_should_hide_topic({last_msg_id: 13, participated: true, type: "stream"}),
|
|
|
|
// false,
|
|
|
|
// );
|
|
|
|
|
|
|
|
// expected_data_to_replace_in_list_widget = [
|
|
|
|
// {last_msg_id: 14, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 13, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 12, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 10, participated: true, type: "stream"},
|
|
|
|
// {last_msg_id: 1, participated: true, type: "stream"},
|
|
|
|
// ];
|
|
|
|
// // followed topic in muted stream
|
|
|
|
// row_data = [
|
|
|
|
// ...row_data,
|
|
|
|
// ...generate_topic_data([[6, "topic-12", 1, all_visibility_policies.FOLLOWED]]),
|
|
|
|
// ];
|
|
|
|
// i = row_data.length;
|
|
|
|
// stub_out_filter_buttons();
|
|
|
|
// rt.process_messages([messages[13]]);
|
|
|
|
// assert.equal(
|
|
|
|
// rt.filters_should_hide_topic({last_msg_id: 14, participated: true, type: "stream"}),
|
|
|
|
// false,
|
|
|
|
// );
|
2020-06-01 17:17:41 +02:00
|
|
|
|
|
|
|
// Test search
|
|
|
|
expected.search_val = "topic-1";
|
2023-10-01 11:18:56 +02:00
|
|
|
row_data = generate_topic_data([[1, "topic-1", 0, all_visibility_policies.INHERIT]]);
|
2020-06-01 17:17:41 +02:00
|
|
|
i = row_data.length;
|
2020-09-23 09:40:59 +02:00
|
|
|
rt.set_default_focus();
|
2022-07-10 01:06:33 +02:00
|
|
|
$(".home-page-input").trigger("focus");
|
2022-10-29 15:55:36 +02:00
|
|
|
assert.equal(
|
|
|
|
rt.filters_should_hide_topic({last_msg_id: 1, participated: true, type: "stream"}),
|
|
|
|
false,
|
|
|
|
);
|
2020-05-23 09:04:51 +02:00
|
|
|
});
|
|
|
|
|
2023-03-13 05:24:16 +01:00
|
|
|
test("test_filter_pm", ({mock_template}) => {
|
|
|
|
page_params.is_spectator = false;
|
|
|
|
const expected = {
|
2023-11-27 14:20:35 +01:00
|
|
|
filter_unread: false,
|
2023-03-13 05:24:16 +01:00
|
|
|
filter_participated: false,
|
|
|
|
filter_muted: false,
|
|
|
|
filter_pm: true,
|
|
|
|
search_val: "",
|
|
|
|
is_spectator: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected_user_with_icon = [
|
|
|
|
{name: "translated: Muted user", status_emoji_info: undefined},
|
|
|
|
{name: "Spike Spiegel", status_emoji_info: undefined},
|
|
|
|
];
|
|
|
|
let i = 0;
|
|
|
|
|
2023-09-06 23:35:51 +02:00
|
|
|
mock_template("recent_view_table.hbs", false, (data) => {
|
2023-03-13 05:24:16 +01:00
|
|
|
assert.deepEqual(data, expected);
|
|
|
|
});
|
|
|
|
|
2023-08-04 23:01:11 +02:00
|
|
|
mock_template("user_with_status_icon.hbs", false, (data) => {
|
2023-03-13 05:24:16 +01:00
|
|
|
assert.deepEqual(data, expected_user_with_icon[i]);
|
|
|
|
i += 1;
|
|
|
|
});
|
|
|
|
|
2023-09-06 23:35:51 +02:00
|
|
|
mock_template("recent_view_row.hbs", true, (_data, html) => {
|
2023-03-13 05:24:16 +01:00
|
|
|
assert.ok(html.startsWith('<tr id="recent_conversation'));
|
|
|
|
});
|
|
|
|
|
|
|
|
rt.clear_for_tests();
|
2024-05-03 20:53:01 +02:00
|
|
|
rt.set_filters_for_tests();
|
2023-03-13 05:24:16 +01:00
|
|
|
stub_out_filter_buttons();
|
2023-09-06 23:21:13 +02:00
|
|
|
recent_view_util.set_visible(true);
|
2023-03-13 05:24:16 +01:00
|
|
|
rt.set_filter("include_private");
|
|
|
|
|
|
|
|
expected_data_to_replace_in_list_widget = [
|
2023-10-01 11:18:56 +02:00
|
|
|
{last_msg_id: 15, participated: true, type: "private"},
|
2023-03-13 05:24:16 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
rt.process_messages([private_messages[0]]);
|
2023-03-15 22:19:06 +01:00
|
|
|
|
2023-10-01 11:18:56 +02:00
|
|
|
assert.deepEqual(rt.filters_should_hide_topic({type: "private", last_msg_id: 15}), false);
|
|
|
|
assert.deepEqual(rt.filters_should_hide_topic({type: "private", last_msg_id: 16}), true);
|
|
|
|
assert.deepEqual(rt.filters_should_hide_topic({type: "private", last_msg_id: 17}), false);
|
2023-03-13 05:24:16 +01:00
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("test_filter_participated", ({mock_template}) => {
|
2021-06-14 15:33:00 +02:00
|
|
|
let expected_filter_participated;
|
|
|
|
|
2022-04-14 05:02:53 +02:00
|
|
|
page_params.is_spectator = false;
|
2023-09-06 23:35:51 +02:00
|
|
|
mock_template("recent_view_table.hbs", false, (data) => {
|
2021-06-14 15:33:00 +02:00
|
|
|
assert.deepEqual(data, {
|
2023-11-27 14:20:35 +01:00
|
|
|
filter_unread: false,
|
2021-06-14 15:33:00 +02:00
|
|
|
filter_participated: expected_filter_participated,
|
|
|
|
filter_muted: false,
|
2022-04-24 06:13:19 +02:00
|
|
|
filter_pm: false,
|
2021-06-14 15:33:00 +02:00
|
|
|
search_val: "",
|
2022-04-14 05:02:53 +02:00
|
|
|
is_spectator: false,
|
2021-06-14 15:33:00 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-09-06 23:35:51 +02:00
|
|
|
mock_template("recent_view_filters.hbs", false, (data) => {
|
2021-06-14 15:33:00 +02:00
|
|
|
assert.equal(data.filter_participated, expected_filter_participated);
|
2023-09-06 23:35:51 +02:00
|
|
|
return "<recent_view table stub>";
|
2021-06-14 15:33:00 +02:00
|
|
|
});
|
2020-05-23 09:04:51 +02:00
|
|
|
|
2020-06-01 17:17:41 +02:00
|
|
|
const row_data = generate_topic_data([
|
2023-10-01 11:18:56 +02:00
|
|
|
// stream_id, topic, unread_count, visibility_policy
|
|
|
|
[6, "topic-12", 1, all_visibility_policies.FOLLOWED],
|
|
|
|
[6, "topic-11", 1, all_visibility_policies.UNMUTED],
|
|
|
|
[6, "topic-8", 1, all_visibility_policies.INHERIT],
|
|
|
|
[4, "topic-10", 1, all_visibility_policies.INHERIT],
|
|
|
|
[1, "topic-7", 1, all_visibility_policies.MUTED],
|
|
|
|
[1, "topic-6", 1, all_visibility_policies.INHERIT],
|
|
|
|
[1, "topic-5", 1, all_visibility_policies.INHERIT],
|
|
|
|
[1, "topic-4", 1, all_visibility_policies.INHERIT],
|
|
|
|
[1, "topic-3", 1, all_visibility_policies.INHERIT],
|
|
|
|
[1, "topic-2", 1, all_visibility_policies.INHERIT],
|
|
|
|
[1, "topic-1", 0, all_visibility_policies.INHERIT],
|
2020-06-01 17:17:41 +02:00
|
|
|
]);
|
|
|
|
let i = 0;
|
|
|
|
|
2023-09-06 23:35:51 +02:00
|
|
|
mock_template("recent_view_row.hbs", false, (data) => {
|
2021-06-14 15:33:00 +02:00
|
|
|
// All the row will be processed.
|
|
|
|
if (row_data[i]) {
|
|
|
|
assert.deepEqual(data, row_data[i]);
|
|
|
|
i += 1;
|
|
|
|
}
|
2023-09-06 23:35:51 +02:00
|
|
|
return "<recent_view row stub>";
|
2021-06-14 15:33:00 +02:00
|
|
|
});
|
|
|
|
|
2021-03-01 21:08:50 +01:00
|
|
|
rt.clear_for_tests();
|
2024-05-03 20:53:01 +02:00
|
|
|
rt.set_filters_for_tests();
|
2023-09-06 23:21:13 +02:00
|
|
|
recent_view_util.set_visible(true);
|
2020-09-23 09:40:59 +02:00
|
|
|
rt.set_default_focus();
|
2021-02-21 17:00:49 +01:00
|
|
|
stub_out_filter_buttons();
|
2021-06-14 15:33:00 +02:00
|
|
|
expected_filter_participated = false;
|
2020-05-23 09:04:51 +02:00
|
|
|
rt.process_messages(messages);
|
2020-07-05 12:19:09 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
$(".home-page-input").trigger("focus");
|
2022-10-29 15:55:36 +02:00
|
|
|
assert.equal(
|
|
|
|
rt.filters_should_hide_topic({last_msg_id: 4, participated: true, type: "stream"}),
|
|
|
|
false,
|
|
|
|
);
|
2020-06-01 17:17:41 +02:00
|
|
|
|
|
|
|
// Set muted filter
|
2020-07-15 01:29:15 +02:00
|
|
|
rt.set_filter("muted");
|
2022-10-29 15:55:36 +02:00
|
|
|
assert.equal(
|
|
|
|
rt.filters_should_hide_topic({last_msg_id: 7, participated: true, type: "stream"}),
|
|
|
|
false,
|
|
|
|
);
|
2020-06-01 17:17:41 +02:00
|
|
|
|
|
|
|
// remove muted filter
|
2020-07-15 01:29:15 +02:00
|
|
|
rt.set_filter("muted");
|
2020-05-23 09:04:51 +02:00
|
|
|
|
2023-09-06 23:41:43 +02:00
|
|
|
$("#recent_view_filter_buttons").removeClass("btn-recent-selected");
|
2021-06-14 15:33:00 +02:00
|
|
|
|
|
|
|
expected_filter_participated = true;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
rt.set_filter("participated");
|
2020-05-29 12:03:22 +02:00
|
|
|
rt.update_filters_view();
|
2020-06-01 17:17:41 +02:00
|
|
|
|
2021-06-14 15:33:00 +02:00
|
|
|
assert.equal(i, row_data.length);
|
|
|
|
|
2021-05-12 17:49:58 +02:00
|
|
|
expected_data_to_replace_in_list_widget = [
|
|
|
|
{
|
|
|
|
last_msg_id: 11,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 10,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 9,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 7,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 5,
|
|
|
|
participated: false,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 4,
|
|
|
|
participated: false,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 3,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 1,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-05-29 12:03:22 +02:00
|
|
|
rt.process_messages([messages[4]]);
|
2020-05-23 09:04:51 +02:00
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("test_update_unread_count", () => {
|
2023-09-06 23:21:13 +02:00
|
|
|
recent_view_util.set_visible(false);
|
2021-03-01 21:08:50 +01:00
|
|
|
rt.clear_for_tests();
|
2021-02-23 12:11:56 +01:00
|
|
|
stub_out_filter_buttons();
|
2020-05-29 12:03:22 +02:00
|
|
|
rt.process_messages(messages);
|
|
|
|
|
|
|
|
// update a message
|
2023-10-01 11:18:56 +02:00
|
|
|
generate_topic_data([[1, "topic-7", 1, all_visibility_policies.INHERIT]]);
|
2020-06-12 12:46:30 +02:00
|
|
|
rt.update_topic_unread_count(messages[9]);
|
2020-05-29 12:03:22 +02:00
|
|
|
});
|
|
|
|
|
2022-10-29 15:55:36 +02:00
|
|
|
test("basic assertions", ({mock_template, override_rewire}) => {
|
|
|
|
override_rewire(rt, "inplace_rerender", noop);
|
2021-03-01 21:08:50 +01:00
|
|
|
rt.clear_for_tests();
|
2024-05-03 20:53:01 +02:00
|
|
|
rt.set_filters_for_tests();
|
2021-06-14 15:33:00 +02:00
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
mock_template("recent_view_table.hbs", false, noop);
|
2023-09-06 23:35:51 +02:00
|
|
|
mock_template("recent_view_row.hbs", true, (_data, html) => {
|
2022-04-24 06:13:19 +02:00
|
|
|
assert.ok(html.startsWith('<tr id="recent_conversation'));
|
2021-06-15 14:54:53 +02:00
|
|
|
});
|
2021-03-16 18:47:45 +01:00
|
|
|
|
2021-02-21 17:00:49 +01:00
|
|
|
stub_out_filter_buttons();
|
2023-09-06 23:21:13 +02:00
|
|
|
recent_view_util.set_visible(true);
|
2020-09-23 09:40:59 +02:00
|
|
|
rt.set_default_focus();
|
2020-03-21 14:42:10 +01:00
|
|
|
rt.process_messages(messages);
|
2023-10-31 04:25:47 +01:00
|
|
|
let all_topics = rt_data.get_conversations();
|
2020-03-21 14:42:10 +01:00
|
|
|
|
2020-05-22 08:16:08 +02:00
|
|
|
// update a message
|
2023-10-01 11:18:56 +02:00
|
|
|
generate_topic_data([[1, "topic-7", 1, all_visibility_policies.INHERIT]]);
|
2021-02-21 17:00:49 +01:00
|
|
|
stub_out_filter_buttons();
|
2021-05-12 17:49:58 +02:00
|
|
|
expected_data_to_replace_in_list_widget = [
|
|
|
|
{
|
|
|
|
last_msg_id: 11,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 10,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 9,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 7,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 5,
|
|
|
|
participated: false,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 4,
|
|
|
|
participated: false,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 3,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
last_msg_id: 1,
|
|
|
|
participated: true,
|
2022-04-24 06:13:19 +02:00
|
|
|
type: "stream",
|
2021-05-12 17:49:58 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-05-22 08:16:08 +02:00
|
|
|
rt.process_messages([messages[9]]);
|
2020-03-21 14:42:10 +01:00
|
|
|
// Check for expected lengths.
|
2020-06-01 13:24:29 +02:00
|
|
|
// total 8 topics, 1 muted
|
2023-10-01 11:18:56 +02:00
|
|
|
assert.equal(all_topics.size, 11);
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2023-03-02 01:58:25 +01:00
|
|
|
[...all_topics.keys()].toString(),
|
2023-10-01 11:18:56 +02:00
|
|
|
"6:topic-12,6:topic-11,6:topic-8,4:topic-10,1:topic-7,1:topic-6,1:topic-5,1:topic-4,1:topic-3,1:topic-2,1:topic-1",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-03-21 14:42:10 +01:00
|
|
|
|
2023-06-16 17:37:19 +02:00
|
|
|
// Process direct message
|
2021-06-10 14:18:46 +02:00
|
|
|
rt_data.process_message({
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2022-04-24 06:13:19 +02:00
|
|
|
to_user_ids: "6,7,8",
|
2020-03-21 14:42:10 +01:00
|
|
|
});
|
2023-10-31 04:25:47 +01:00
|
|
|
all_topics = rt_data.get_conversations();
|
2023-10-01 11:18:56 +02:00
|
|
|
assert.equal(all_topics.size, 12);
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2023-03-02 01:58:25 +01:00
|
|
|
[...all_topics.keys()].toString(),
|
2023-10-01 11:18:56 +02:00
|
|
|
"6:topic-12,6:topic-11,6:topic-8,4:topic-10,1:topic-7,1:topic-6,1:topic-5,1:topic-4,1:topic-3,1:topic-2,1:topic-1,6,7,8",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-03-21 14:42:10 +01:00
|
|
|
|
2020-05-28 13:41:29 +02:00
|
|
|
// participated
|
|
|
|
verify_topic_data(all_topics, stream1, topic1, messages[0].id, true);
|
2020-03-21 14:42:10 +01:00
|
|
|
|
|
|
|
// No message was sent by us.
|
2020-05-28 13:41:29 +02:00
|
|
|
verify_topic_data(all_topics, stream1, topic3, messages[3].id, false);
|
2020-03-21 14:42:10 +01:00
|
|
|
|
2020-05-28 13:41:29 +02:00
|
|
|
// Not participated
|
|
|
|
verify_topic_data(all_topics, stream1, topic4, messages[4].id, false);
|
2020-03-21 14:42:10 +01:00
|
|
|
|
|
|
|
// topic3 now participated
|
2021-06-10 14:18:46 +02:00
|
|
|
rt_data.process_message({
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic3,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
});
|
|
|
|
|
2023-10-31 04:25:47 +01:00
|
|
|
all_topics = rt_data.get_conversations();
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2023-03-02 01:58:25 +01:00
|
|
|
[...all_topics.keys()].toString(),
|
2023-10-01 11:18:56 +02:00
|
|
|
"1:topic-3,6:topic-12,6:topic-11,6:topic-8,4:topic-10,1:topic-7,1:topic-6,1:topic-5,1:topic-4,1:topic-2,1:topic-1,6,7,8",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-05-28 13:41:29 +02:00
|
|
|
verify_topic_data(all_topics, stream1, topic3, id, true);
|
2020-03-21 14:42:10 +01:00
|
|
|
|
|
|
|
// Send new message to topic7 (muted)
|
2020-05-22 08:16:08 +02:00
|
|
|
// The topic will be hidden when displayed
|
2021-06-10 14:18:46 +02:00
|
|
|
rt_data.process_message({
|
2020-03-21 14:42:10 +01:00
|
|
|
stream_id: stream1,
|
2020-07-15 00:34:28 +02:00
|
|
|
id: (id += 1),
|
2020-03-21 14:42:10 +01:00
|
|
|
topic: topic7,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-03-21 14:42:10 +01:00
|
|
|
});
|
|
|
|
|
2023-10-31 04:25:47 +01:00
|
|
|
all_topics = rt_data.get_conversations();
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2023-03-02 01:58:25 +01:00
|
|
|
[...all_topics.keys()].toString(),
|
2023-10-01 11:18:56 +02:00
|
|
|
"1:topic-7,1:topic-3,6:topic-12,6:topic-11,6:topic-8,4:topic-10,1:topic-6,1:topic-5,1:topic-4,1:topic-2,1:topic-1,6,7,8",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-05-15 14:27:36 +02:00
|
|
|
|
2023-04-22 01:28:00 +02:00
|
|
|
// update_topic_visibility_policy now relies on external libraries completely
|
2020-05-29 17:22:53 +02:00
|
|
|
// so we don't need to check anythere here.
|
2023-10-01 11:18:56 +02:00
|
|
|
generate_topic_data([[1, topic1, 0, all_visibility_policies.INHERIT]]);
|
2022-07-10 01:06:33 +02:00
|
|
|
$(".home-page-input").trigger("focus");
|
2023-04-22 01:28:00 +02:00
|
|
|
assert.equal(rt.update_topic_visibility_policy(stream1, topic1), true);
|
2020-05-15 14:27:36 +02:00
|
|
|
// a topic gets muted which we are not tracking
|
2023-04-22 01:28:00 +02:00
|
|
|
assert.equal(rt.update_topic_visibility_policy(stream1, "topic-10"), false);
|
2020-03-21 14:42:10 +01:00
|
|
|
});
|
2020-04-16 20:47:18 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("test_reify_local_echo_message", ({mock_template}) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
mock_template("recent_view_table.hbs", false, noop);
|
|
|
|
mock_template("recent_view_row.hbs", false, noop);
|
2021-03-16 18:47:45 +01:00
|
|
|
|
2021-03-01 21:08:50 +01:00
|
|
|
rt.clear_for_tests();
|
2024-05-03 20:53:01 +02:00
|
|
|
rt.set_filters_for_tests();
|
2021-02-21 17:00:49 +01:00
|
|
|
stub_out_filter_buttons();
|
2023-09-06 23:21:13 +02:00
|
|
|
recent_view_util.set_visible(true);
|
2020-05-28 09:48:58 +02:00
|
|
|
rt.process_messages(messages);
|
|
|
|
|
2021-06-10 14:18:46 +02:00
|
|
|
rt_data.process_message({
|
2020-05-28 09:48:58 +02:00
|
|
|
stream_id: stream1,
|
|
|
|
id: 1000.01,
|
|
|
|
topic: topic7,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-06-12 12:05:06 +02:00
|
|
|
});
|
2020-05-28 09:48:58 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2021-06-10 14:18:46 +02:00
|
|
|
rt_data.reify_message_id_if_available({
|
2020-07-15 00:34:28 +02:00
|
|
|
old_id: 1000.01,
|
|
|
|
new_id: 1001,
|
|
|
|
}),
|
|
|
|
true,
|
|
|
|
);
|
2020-05-28 09:48:58 +02:00
|
|
|
|
2021-06-10 14:18:46 +02:00
|
|
|
rt_data.process_message({
|
2020-05-28 09:48:58 +02:00
|
|
|
stream_id: stream1,
|
|
|
|
id: 1001.01,
|
|
|
|
topic: topic7,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-06-12 12:05:06 +02:00
|
|
|
});
|
2020-05-28 09:48:58 +02:00
|
|
|
|
|
|
|
// A new message arrived in the same topic before we could reify the message_id
|
2021-06-10 14:18:46 +02:00
|
|
|
rt_data.process_message({
|
2020-05-28 09:48:58 +02:00
|
|
|
stream_id: stream1,
|
|
|
|
id: 1003,
|
|
|
|
topic: topic7,
|
|
|
|
sender_id: sender1,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-06-12 12:05:06 +02:00
|
|
|
});
|
2020-05-28 09:48:58 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2021-06-10 14:18:46 +02:00
|
|
|
rt_data.reify_message_id_if_available({
|
2020-07-15 00:34:28 +02:00
|
|
|
old_id: 1000.01,
|
|
|
|
new_id: 1001,
|
|
|
|
}),
|
|
|
|
false,
|
|
|
|
);
|
2020-05-28 09:48:58 +02:00
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("test_delete_messages", ({override}) => {
|
2023-09-06 23:21:13 +02:00
|
|
|
recent_view_util.set_visible(false);
|
2021-03-01 21:08:50 +01:00
|
|
|
rt.clear_for_tests();
|
2021-02-23 12:11:56 +01:00
|
|
|
stub_out_filter_buttons();
|
2020-07-15 09:36:03 +02:00
|
|
|
rt.process_messages(messages);
|
|
|
|
|
2021-02-28 18:48:44 +01:00
|
|
|
// messages[0] was removed.
|
|
|
|
let reduced_msgs = messages.slice(1);
|
2021-03-30 06:23:09 +02:00
|
|
|
override(all_messages_data, "all_messages", () => reduced_msgs);
|
2020-07-15 09:36:03 +02:00
|
|
|
|
2023-10-31 04:25:47 +01:00
|
|
|
let all_topics = rt_data.get_conversations();
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2023-03-02 01:58:25 +01:00
|
|
|
[...all_topics.keys()].toString(),
|
2023-10-01 11:18:56 +02:00
|
|
|
"6:topic-12,6:topic-11,6:topic-8,4:topic-10,1:topic-7,1:topic-6,1:topic-5,1:topic-4,1:topic-3,1:topic-2,1:topic-1",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-08-06 21:00:28 +02:00
|
|
|
rt.update_topics_of_deleted_message_ids([messages[0].id]);
|
2020-07-15 09:36:03 +02:00
|
|
|
|
2023-10-31 04:25:47 +01:00
|
|
|
all_topics = rt_data.get_conversations();
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2023-03-02 01:58:25 +01:00
|
|
|
[...all_topics.keys()].toString(),
|
2023-10-01 11:18:56 +02:00
|
|
|
"6:topic-12,6:topic-11,6:topic-8,4:topic-10,1:topic-7,1:topic-6,1:topic-5,1:topic-4,1:topic-3,1:topic-2",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-07-15 09:36:03 +02:00
|
|
|
|
2021-02-28 18:48:44 +01:00
|
|
|
// messages[0], messages[1] and message[2] were removed.
|
|
|
|
reduced_msgs = messages.slice(3);
|
2020-07-15 09:36:03 +02:00
|
|
|
|
2020-08-06 21:00:28 +02:00
|
|
|
rt.update_topics_of_deleted_message_ids([messages[1].id, messages[2].id]);
|
2020-07-15 09:36:03 +02:00
|
|
|
|
2023-10-31 04:25:47 +01:00
|
|
|
all_topics = rt_data.get_conversations();
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2023-03-02 01:58:25 +01:00
|
|
|
[...all_topics.keys()].toString(),
|
2023-10-01 11:18:56 +02:00
|
|
|
"6:topic-12,6:topic-11,6:topic-8,4:topic-10,1:topic-7,1:topic-6,1:topic-5,1:topic-4,1:topic-3",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-08-07 09:16:25 +02:00
|
|
|
// test deleting a message which is not locally
|
|
|
|
// stored, doesn't raise any errors.
|
|
|
|
rt.update_topics_of_deleted_message_ids([-1]);
|
2020-07-15 09:36:03 +02:00
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("test_topic_edit", ({override}) => {
|
2021-04-16 17:44:46 +02:00
|
|
|
override(all_messages_data, "all_messages", () => messages);
|
2023-09-06 23:21:13 +02:00
|
|
|
recent_view_util.set_visible(false);
|
2021-04-16 17:44:46 +02:00
|
|
|
|
2020-05-22 08:16:08 +02:00
|
|
|
// NOTE: This test should always run in the end as it modified the messages data.
|
2021-03-01 21:08:50 +01:00
|
|
|
rt.clear_for_tests();
|
2021-02-23 12:11:56 +01:00
|
|
|
stub_out_filter_buttons();
|
2020-04-16 20:47:18 +02:00
|
|
|
rt.process_messages(messages);
|
|
|
|
|
2023-10-31 04:25:47 +01:00
|
|
|
let all_topics = rt_data.get_conversations();
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2023-03-02 01:58:25 +01:00
|
|
|
[...all_topics.keys()].toString(),
|
2023-10-01 11:18:56 +02:00
|
|
|
"6:topic-12,6:topic-11,6:topic-8,4:topic-10,1:topic-7,1:topic-6,1:topic-5,1:topic-4,1:topic-3,1:topic-2,1:topic-1",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2020-04-16 20:47:18 +02:00
|
|
|
|
2021-03-26 20:38:59 +01:00
|
|
|
// ---------------- test change topic ----------------
|
2020-05-28 13:41:29 +02:00
|
|
|
verify_topic_data(all_topics, stream1, topic6, messages[8].id, true);
|
2020-06-12 12:46:30 +02:00
|
|
|
assert.equal(all_topics.get(get_topic_key(stream1, topic8)), undefined);
|
2020-04-16 20:47:18 +02:00
|
|
|
|
|
|
|
// change topic of topic6 to topic8
|
|
|
|
messages[7].topic = topic8;
|
|
|
|
messages[8].topic = topic8;
|
|
|
|
rt.process_topic_edit(stream1, topic6, topic8);
|
2023-10-31 04:25:47 +01:00
|
|
|
all_topics = rt_data.get_conversations();
|
2020-04-16 20:47:18 +02:00
|
|
|
|
2020-05-28 13:41:29 +02:00
|
|
|
verify_topic_data(all_topics, stream1, topic8, messages[8].id, true);
|
2020-06-12 12:46:30 +02:00
|
|
|
assert.equal(all_topics.get(get_topic_key(stream1, topic6)), undefined);
|
2020-04-16 20:47:18 +02:00
|
|
|
|
2021-03-26 20:38:59 +01:00
|
|
|
// ---------------- test stream change ----------------
|
2020-05-28 13:41:29 +02:00
|
|
|
verify_topic_data(all_topics, stream1, topic1, messages[0].id, true);
|
2020-06-12 12:46:30 +02:00
|
|
|
assert.equal(all_topics.get(get_topic_key(stream2, topic1)), undefined);
|
2020-04-16 20:47:18 +02:00
|
|
|
|
|
|
|
messages[0].stream_id = stream2;
|
|
|
|
rt.process_topic_edit(stream1, topic1, topic1, stream2);
|
2023-10-31 04:25:47 +01:00
|
|
|
all_topics = rt_data.get_conversations();
|
2020-04-16 20:47:18 +02:00
|
|
|
|
2020-06-12 12:46:30 +02:00
|
|
|
assert.equal(all_topics.get(get_topic_key(stream1, topic1)), undefined);
|
2020-05-28 13:41:29 +02:00
|
|
|
verify_topic_data(all_topics, stream2, topic1, messages[0].id, true);
|
2020-04-16 20:47:18 +02:00
|
|
|
|
2021-03-26 20:38:59 +01:00
|
|
|
// ---------------- test stream & topic change ----------------
|
2020-05-28 13:41:29 +02:00
|
|
|
verify_topic_data(all_topics, stream2, topic1, messages[0].id, true);
|
2020-06-12 12:46:30 +02:00
|
|
|
assert.equal(all_topics.get(get_topic_key(stream3, topic9)), undefined);
|
2020-04-16 20:47:18 +02:00
|
|
|
|
|
|
|
messages[0].stream_id = stream3;
|
|
|
|
messages[0].topic = topic9;
|
|
|
|
rt.process_topic_edit(stream2, topic1, topic9, stream3);
|
2023-10-31 04:25:47 +01:00
|
|
|
all_topics = rt_data.get_conversations();
|
2020-04-16 20:47:18 +02:00
|
|
|
|
2020-06-12 12:46:30 +02:00
|
|
|
assert.equal(all_topics.get(get_topic_key(stream2, topic1)), undefined);
|
2020-05-28 13:41:29 +02:00
|
|
|
verify_topic_data(all_topics, stream3, topic9, messages[0].id, true);
|
2020-07-12 16:45:42 +02:00
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
// Message was moved to a deleted stream, hence hidden regardless of filter.
|
2020-07-12 16:45:42 +02:00
|
|
|
messages[0].stream_id = stream5;
|
|
|
|
messages[0].topic = topic8;
|
|
|
|
rt.process_topic_edit(stream3, topic9, topic8, stream5);
|
2023-10-31 04:25:47 +01:00
|
|
|
all_topics = rt_data.get_conversations();
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(rt.filters_should_hide_topic(all_topics.get("5:topic-8")), true);
|
2020-04-16 20:47:18 +02:00
|
|
|
});
|
2020-06-26 08:42:35 +02:00
|
|
|
|
2021-03-16 18:28:29 +01:00
|
|
|
test("test_search", () => {
|
2021-03-01 21:08:50 +01:00
|
|
|
rt.clear_for_tests();
|
2021-05-10 07:02:14 +02:00
|
|
|
assert.equal(rt.topic_in_search_results("t", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("T", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("to", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("top", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("ToP", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("Topi", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("tOpi", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("toPic", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("Topic", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("topic", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("recent", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("RECENT", "general", "Recent topic"), true);
|
2020-06-29 11:15:48 +02:00
|
|
|
|
typeahead: Add option for word order not mattering for query matching.
Uptil now, the `query_matches_string_in_order` function would respect
the order of words in the query string when matching a source string.
This meant that for query "two one", the source string "one two three"
would not be matched.
For more flexibility, a new function, `query_matches_string_in_any_order`,
has been added., which returns true if each word in the query string matches
the prefix of a distinct word in the source string, else it returns false.
The algorithm for computing this is quadratic in terms of the source word
count so can be a little expensive, but it is only currently used for
searching topics in Recent Conversations, where the strings' length is
limited by the max stream / topic name length allowed, so this should be
performant enough for this use case.
2023-03-03 14:40:19 +01:00
|
|
|
// Match (by prefix) in any order of words.
|
2021-05-10 07:02:14 +02:00
|
|
|
assert.equal(rt.topic_in_search_results("topic recent", "general", "Recent topic"), true);
|
typeahead: Add option for word order not mattering for query matching.
Uptil now, the `query_matches_string_in_order` function would respect
the order of words in the query string when matching a source string.
This meant that for query "two one", the source string "one two three"
would not be matched.
For more flexibility, a new function, `query_matches_string_in_any_order`,
has been added., which returns true if each word in the query string matches
the prefix of a distinct word in the source string, else it returns false.
The algorithm for computing this is quadratic in terms of the source word
count so can be a little expensive, but it is only currently used for
searching topics in Recent Conversations, where the strings' length is
limited by the max stream / topic name length allowed, so this should be
performant enough for this use case.
2023-03-03 14:40:19 +01:00
|
|
|
assert.equal(rt.topic_in_search_results("o", "general", "Recent topic"), false);
|
|
|
|
assert.equal(rt.topic_in_search_results("to recen", "general", "Recent topic"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("ner opic", "general", "Recent topic"), false);
|
|
|
|
assert.equal(rt.topic_in_search_results("pr pro", "general", "pro PRs"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("pr pro pr pro", "general", "pro PRs"), false);
|
|
|
|
assert.equal(rt.topic_in_search_results("co cows", "general", "one cow 2 cows"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("cows cows", "general", "one cow 2 cows"), false);
|
2020-06-29 11:15:48 +02:00
|
|
|
|
2021-05-10 07:02:14 +02:00
|
|
|
assert.equal(rt.topic_in_search_results("?", "general", "Recent topic"), false);
|
2020-06-26 08:42:35 +02:00
|
|
|
|
|
|
|
// Test special character match
|
2021-05-10 07:02:14 +02:00
|
|
|
assert.equal(rt.topic_in_search_results(".*+?^${}()[]\\", "general", "Recent topic"), false);
|
typeahead: Add option for word order not mattering for query matching.
Uptil now, the `query_matches_string_in_order` function would respect
the order of words in the query string when matching a source string.
This meant that for query "two one", the source string "one two three"
would not be matched.
For more flexibility, a new function, `query_matches_string_in_any_order`,
has been added., which returns true if each word in the query string matches
the prefix of a distinct word in the source string, else it returns false.
The algorithm for computing this is quadratic in terms of the source word
count so can be a little expensive, but it is only currently used for
searching topics in Recent Conversations, where the strings' length is
limited by the max stream / topic name length allowed, so this should be
performant enough for this use case.
2023-03-03 14:40:19 +01:00
|
|
|
assert.equal(rt.topic_in_search_results("?", "general", "?at-start"), true);
|
2020-06-26 08:42:35 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(rt.topic_in_search_results("?", "general", "?"), true);
|
typeahead: Add option for word order not mattering for query matching.
Uptil now, the `query_matches_string_in_order` function would respect
the order of words in the query string when matching a source string.
This meant that for query "two one", the source string "one two three"
would not be matched.
For more flexibility, a new function, `query_matches_string_in_any_order`,
has been added., which returns true if each word in the query string matches
the prefix of a distinct word in the source string, else it returns false.
The algorithm for computing this is quadratic in terms of the source word
count so can be a little expensive, but it is only currently used for
searching topics in Recent Conversations, where the strings' length is
limited by the max stream / topic name length allowed, so this should be
performant enough for this use case.
2023-03-03 14:40:19 +01:00
|
|
|
assert.equal(rt.topic_in_search_results("?", "general", "\\?"), false);
|
2020-06-26 08:42:35 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(rt.topic_in_search_results("\\", "general", "\\"), true);
|
|
|
|
assert.equal(rt.topic_in_search_results("\\", "general", "\\\\"), true);
|
2020-06-26 08:42:35 +02:00
|
|
|
});
|