"use strict"; const {strict: assert} = require("assert"); const {mock_esm, zrequire} = require("./lib/namespace"); const {run_test} = require("./lib/test"); const $ = require("./lib/zjquery"); const {page_params, realm, current_user} = require("./lib/zpage_params"); const {Filter} = zrequire("filter"); const {MessageList} = zrequire("message_list"); const message_lists = zrequire("message_lists"); 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 noop = function () {}; // Define MessageList stuff function MessageListView() { return { maybe_rerender: noop, append: noop, prepend: noop, clear_rendering_state: noop, get_row: () => ({ find: () => ({ is: () => false, }), }), message_containers: new Map(), }; } mock_esm("../src/message_list_view", { MessageListView, }); mock_esm("../src/ui_util", { listener_for_preferred_color_scheme_change: noop, }); mock_esm("../src/hash_util", { by_conversation_and_time_url: () => "conversation_and_time_url", }); mock_esm("../src/stream_data", { is_subscribed: () => true, }); mock_esm("../src/group_permission_settings", { get_group_permission_setting_config() { return { allow_everyone_group: false, }; }, }); // Define test users const mike = { user_id: 1000, full_name: "Test Mike", email: "mike@example.com", is_admin: false, is_guest: false, }; const bob = { user_id: 2000, full_name: "Test Bob", email: "bob@example.com", is_admin: false, is_guest: false, }; const me = { user_id: 999, full_name: "Test Myself", email: "me@example.com", is_admin: false, is_guest: false, }; const everyone = { name: "role:everyone", id: 2, members: new Set([999, 1000, 2000]), is_system_group: true, direct_subgroup_ids: new Set([]), }; user_groups.initialize({realm_user_groups: [everyone]}); // Helper functions: function add_initialize_users() { // Initialize people people.init(); // Add users people.add_active_user(mike); people.add_active_user(bob); people.add_active_user(me); // Initialize current user people.initialize_current_user(me.user_id); } function init_message_list() { const filter = new Filter([]); const list = new MessageList({ filter, }); assert.equal(list.empty(), true); return list; } // Append message to message_list, also add container to message_lists function add_message_with_view(list, messages) { list.append(messages, true); for (const message of messages) { message_lists.current.view.message_containers.set(message.id, { is_hidden: message.is_hidden, }); } } // Function sets page parameters with no time constraints on editing the message. // User is assumed to not be an admin. function set_page_params_no_edit_restrictions() { page_params.is_spectator = false; realm.realm_allow_message_editing = true; realm.realm_message_content_edit_limit_seconds = null; realm.realm_allow_edit_history = true; realm.realm_message_content_delete_limit_seconds = null; realm.realm_enable_read_receipts = true; realm.realm_edit_topic_policy = 5; realm.realm_move_messages_within_stream_limit_seconds = null; } // Test init function function test(label, f) { run_test(label, (helpers) => { // Stubs for calculate_timestamp_widths() $("