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 {$t} = require("./lib/i18n");
|
|
|
|
const {mock_cjs, mock_esm, set_global, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
|
|
|
const {page_params} = require("./lib/zpage_params");
|
2020-07-15 01:29:15 +02:00
|
|
|
|
2020-07-16 23:29:01 +02:00
|
|
|
const noop = function () {};
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
class Clipboard {
|
|
|
|
on() {}
|
|
|
|
}
|
|
|
|
mock_cjs("clipboard", Clipboard);
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const rows = mock_esm("../src/rows");
|
|
|
|
mock_esm("../src/emoji_picker", {
|
2018-04-12 17:43:43 +02:00
|
|
|
hide_emoji_popover: noop,
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
const message_lists = mock_esm("../src/message_lists", {
|
2021-05-20 11:37:57 +02:00
|
|
|
current: {
|
|
|
|
view: {
|
|
|
|
message_containers: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-30 02:21:21 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/stream_popover", {
|
2018-04-12 17:43:43 +02:00
|
|
|
hide_stream_popover: noop,
|
|
|
|
hide_topic_popover: noop,
|
2021-11-25 17:02:19 +01:00
|
|
|
hide_drafts_popover: noop,
|
2019-07-10 02:54:23 +02:00
|
|
|
hide_streamlist_sidebar: noop,
|
2018-04-12 17:43:43 +02:00
|
|
|
});
|
|
|
|
|
2023-05-27 08:30:54 +02:00
|
|
|
set_global("document", {
|
|
|
|
to_$: () => $("document-stub"),
|
|
|
|
});
|
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const people = zrequire("people");
|
|
|
|
const user_status = zrequire("user_status");
|
2022-07-09 23:25:05 +02:00
|
|
|
const popovers = zrequire("popovers");
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@example.com",
|
2021-10-26 15:43:39 +02:00
|
|
|
delivery_email: "alice-delivery@example.com",
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice Smith",
|
2018-04-12 17:43:43 +02:00
|
|
|
user_id: 42,
|
2020-04-07 20:09:30 +02:00
|
|
|
avatar_version: 5,
|
2018-12-17 02:25:00 +01:00
|
|
|
is_guest: false,
|
2019-04-20 18:08:29 +02:00
|
|
|
is_admin: false,
|
2021-04-29 15:49:01 +02:00
|
|
|
role: 400,
|
2021-11-02 08:36:31 +01:00
|
|
|
date_joined: "2021-11-01T16:32:16.458735+00:00",
|
2018-04-12 17:43:43 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "me@example.com",
|
2018-04-12 17:43:43 +02:00
|
|
|
user_id: 30,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Me Myself",
|
2020-10-27 01:41:00 +01:00
|
|
|
timezone: "America/Los_Angeles",
|
2018-04-12 17:43:43 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const e = {
|
2019-06-15 06:31:57 +02:00
|
|
|
stopPropagation: noop,
|
|
|
|
};
|
|
|
|
|
2018-04-12 17:43:43 +02:00
|
|
|
function initialize_people() {
|
|
|
|
people.init();
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(me);
|
|
|
|
people.add_active_user(alice);
|
2018-04-12 17:43:43 +02:00
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize_people();
|
|
|
|
|
|
|
|
function make_image_stubber() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const images = [];
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2022-04-19 02:45:44 +02:00
|
|
|
class Image {
|
|
|
|
constructor() {
|
|
|
|
images.push(this);
|
|
|
|
}
|
|
|
|
to_$() {
|
|
|
|
return {
|
|
|
|
on: (name, f) => {
|
|
|
|
assert.equal(name, "load");
|
|
|
|
this.load_f = f;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2018-04-12 17:43:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-19 02:45:44 +02:00
|
|
|
set_global("Image", Image);
|
2018-04-12 17:43:43 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
get: (i) => images[i],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-02-21 12:44:39 +01:00
|
|
|
function test_ui(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (handlers) => {
|
2021-04-03 19:07:13 +02:00
|
|
|
page_params.is_admin = false;
|
|
|
|
page_params.custom_profile_fields = [];
|
2021-03-16 11:31:40 +01:00
|
|
|
popovers.clear_for_testing();
|
2021-02-21 12:44:39 +01:00
|
|
|
popovers.register_click_handlers();
|
2022-07-10 01:06:33 +02:00
|
|
|
f(handlers);
|
2021-02-21 12:44:39 +01:00
|
|
|
});
|
|
|
|
}
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
test_ui("sender_hover", ({override, mock_template}) => {
|
2021-11-02 08:36:31 +01:00
|
|
|
page_params.is_spectator = false;
|
2021-02-22 13:55:34 +01:00
|
|
|
override($.fn, "popover", noop);
|
2020-07-26 16:38:46 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const selection = ".sender_name, .sender_name-in-status, .inline_profile_picture";
|
2020-07-15 01:29:15 +02:00
|
|
|
const handler = $("#main_div").get_on_handler("click", selection);
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const message = {
|
2018-04-12 17:43:43 +02:00
|
|
|
id: 999,
|
|
|
|
sender_id: alice.user_id,
|
|
|
|
};
|
|
|
|
|
2019-02-01 02:33:01 +01:00
|
|
|
user_status.set_status_text({
|
|
|
|
user_id: alice.user_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
status_text: "on the beach",
|
2019-02-01 02:33:01 +01:00
|
|
|
});
|
|
|
|
|
2021-06-29 17:21:30 +02:00
|
|
|
const status_emoji_info = {
|
|
|
|
emoji_name: "car",
|
|
|
|
emoji_code: "1f697",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_alt_code: false,
|
|
|
|
};
|
|
|
|
user_status.set_status_emoji({user_id: alice.user_id, ...status_emoji_info});
|
|
|
|
|
2018-04-12 17:43:43 +02:00
|
|
|
rows.id = () => message.id;
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.get = (msg_id) => {
|
2018-04-12 17:43:43 +02:00
|
|
|
assert.equal(msg_id, message.id);
|
|
|
|
return message;
|
|
|
|
};
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.select_id = (msg_id) => {
|
2018-04-12 17:43:43 +02:00
|
|
|
assert.equal(msg_id, message.id);
|
|
|
|
};
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $target = $.create("click target");
|
2021-02-21 12:44:39 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$target.closest = (sel) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(sel, ".message_row");
|
2018-04-12 17:43:43 +02:00
|
|
|
return {};
|
|
|
|
};
|
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("no_arrow_popover.hbs", false, (opts) => {
|
2021-06-14 10:40:34 +02:00
|
|
|
assert.deepEqual(opts, {
|
|
|
|
class: "message-info-popover",
|
|
|
|
});
|
|
|
|
return "popover-html";
|
|
|
|
});
|
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("user_info_popover_title.hbs", false, (opts) => {
|
2021-06-14 10:40:34 +02:00
|
|
|
assert.deepEqual(opts, {
|
2021-11-02 08:41:52 +01:00
|
|
|
user_avatar: "http://zulip.zulipdev.com/avatar/42?s=50",
|
2021-06-14 10:40:34 +02:00
|
|
|
user_is_guest: false,
|
|
|
|
});
|
|
|
|
return "title-html";
|
|
|
|
});
|
2022-10-03 13:29:59 +02:00
|
|
|
const $popover_content = $.create("content-html");
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("user_info_popover_content.hbs", false, (opts) => {
|
2021-06-14 10:40:34 +02:00
|
|
|
assert.deepEqual(opts, {
|
2022-09-21 15:49:36 +02:00
|
|
|
invisible_mode: false,
|
2022-04-22 20:32:41 +02:00
|
|
|
can_send_private_message: true,
|
2022-07-12 21:25:02 +02:00
|
|
|
display_profile_fields: [],
|
2021-06-14 10:40:34 +02:00
|
|
|
user_full_name: "Alice Smith",
|
2021-10-26 15:43:39 +02:00
|
|
|
user_email: "alice-delivery@example.com",
|
2021-06-14 10:40:34 +02:00
|
|
|
user_id: 42,
|
|
|
|
user_time: undefined,
|
|
|
|
user_type: $t({defaultMessage: "Member"}),
|
|
|
|
user_circle_class: "user_circle_empty",
|
2023-04-07 18:24:15 +02:00
|
|
|
user_last_seen_time_status: "translated: Active more than 2 weeks ago",
|
2023-04-11 21:04:33 +02:00
|
|
|
pm_with_url: "#narrow/dm/42-Alice-Smith",
|
2023-04-09 05:22:23 +02:00
|
|
|
sent_by_url: "#narrow/sender/42-Alice-Smith",
|
2021-06-14 10:40:34 +02:00
|
|
|
private_message_class: "respond_personal_button",
|
2022-10-03 13:29:59 +02:00
|
|
|
show_manage_menu: true,
|
2021-06-14 10:40:34 +02:00
|
|
|
is_me: false,
|
|
|
|
is_active: true,
|
|
|
|
is_bot: undefined,
|
|
|
|
is_sender_popover: true,
|
|
|
|
has_message_context: true,
|
2021-06-29 17:21:30 +02:00
|
|
|
status_content_available: true,
|
2021-06-14 10:40:34 +02:00
|
|
|
status_text: "on the beach",
|
2021-06-29 17:21:30 +02:00
|
|
|
status_emoji_info,
|
2021-06-14 10:40:34 +02:00
|
|
|
user_mention_syntax: "@**Alice Smith**",
|
2021-11-02 08:36:31 +01:00
|
|
|
date_joined: undefined,
|
|
|
|
spectator_view: false,
|
2021-06-14 10:40:34 +02:00
|
|
|
});
|
2022-10-03 13:29:59 +02:00
|
|
|
return $popover_content;
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2021-02-08 15:48:50 +01:00
|
|
|
$.create(".user_popover_email", {children: []});
|
2023-05-20 16:30:21 +02:00
|
|
|
$("#userlist-title").get_offset_to_window = () => 10;
|
2022-10-03 13:29:59 +02:00
|
|
|
$popover_content.get = () => {};
|
|
|
|
const $user_name_element = $.create("user_full_name");
|
2022-10-19 13:03:10 +02:00
|
|
|
const $bot_owner_element = $.create("bot_owner");
|
2022-10-03 13:29:59 +02:00
|
|
|
$popover_content.set_find_results(".user_full_name", $user_name_element);
|
2022-10-19 13:03:10 +02:00
|
|
|
$popover_content.set_find_results(".bot_owner", $bot_owner_element);
|
2022-10-03 13:29:59 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const image_stubber = make_image_stubber();
|
2022-01-25 11:36:19 +01:00
|
|
|
handler.call($target, e);
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const avatar_img = image_stubber.get(0);
|
2023-05-17 17:20:59 +02:00
|
|
|
assert.equal(avatar_img.src.toString(), "/avatar/42/medium?version=5");
|
2018-04-12 17:43:43 +02:00
|
|
|
|
|
|
|
// todo: load image
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|