2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-07-28 00:14:57 +02:00
|
|
|
const rewiremock = require("rewiremock/node");
|
|
|
|
|
2020-12-01 00:19:42 +01:00
|
|
|
const {stub_templates} = require("../zjsunit/handlebars");
|
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:12:33 +01:00
|
|
|
const {make_zjquery} = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2020-12-01 00:12:33 +01:00
|
|
|
set_global("$", make_zjquery());
|
2020-07-15 01:29:15 +02:00
|
|
|
|
|
|
|
zrequire("hash_util");
|
|
|
|
zrequire("narrow");
|
|
|
|
zrequire("narrow_state");
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = zrequire("people");
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("presence");
|
|
|
|
zrequire("buddy_data");
|
2021-02-10 04:53:22 +01:00
|
|
|
const user_status = zrequire("user_status");
|
|
|
|
const message_edit = zrequire("message_edit");
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2020-07-16 23:29:01 +02:00
|
|
|
const noop = function () {};
|
2018-04-12 17:43:43 +02:00
|
|
|
$.fn.popover = noop; // this will get wrapped by our code
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("current_msg_list", {});
|
|
|
|
set_global("page_params", {
|
2019-07-18 15:21:09 +02:00
|
|
|
is_admin: false,
|
|
|
|
realm_email_address_visibility: 3,
|
2018-04-24 02:24:14 +02:00
|
|
|
custom_profile_fields: [],
|
|
|
|
});
|
2021-02-10 04:53:22 +01:00
|
|
|
const rows = set_global("rows", {});
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("message_viewport", {
|
2018-04-12 17:43:43 +02:00
|
|
|
height: () => 500,
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("emoji_picker", {
|
2018-04-12 17:43:43 +02:00
|
|
|
hide_emoji_popover: noop,
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("stream_popover", {
|
2018-04-12 17:43:43 +02:00
|
|
|
hide_stream_popover: noop,
|
|
|
|
hide_topic_popover: noop,
|
|
|
|
hide_all_messages_popover: noop,
|
2019-02-22 12:28:29 +01:00
|
|
|
hide_starred_messages_popover: noop,
|
2019-07-10 02:54:23 +02:00
|
|
|
hide_streamlist_sidebar: noop,
|
2018-04-12 17:43:43 +02:00
|
|
|
});
|
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_data = set_global("stream_data", {});
|
2019-06-15 06:31:57 +02:00
|
|
|
|
2020-06-27 21:33:09 +02:00
|
|
|
const ClipboardJS = noop;
|
2020-07-28 00:14:57 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const popovers = rewiremock.proxy(() => zrequire("popovers"), {
|
2020-07-28 00:14:57 +02:00
|
|
|
clipboard: ClipboardJS,
|
|
|
|
});
|
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",
|
|
|
|
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,
|
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
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const target = $.create("click target");
|
2020-07-02 01:41:40 +02:00
|
|
|
target.offset = () => ({
|
|
|
|
top: 10,
|
|
|
|
});
|
2019-06-15 06:31:57 +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
|
|
|
|
|
|
|
function stub_image() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const image = {};
|
2020-07-02 01:41:40 +02:00
|
|
|
image.to_$ = () => ({
|
|
|
|
on: (name, f) => {
|
|
|
|
assert.equal(name, "load");
|
|
|
|
image.load_f = f;
|
|
|
|
},
|
|
|
|
});
|
2018-04-12 17:43:43 +02:00
|
|
|
images.push(image);
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("Image", stub_image);
|
2018-04-12 17:43:43 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
get: (i) => images[i],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-06-15 06:31:57 +02:00
|
|
|
popovers.register_click_handlers();
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2020-07-26 16:38:46 +02:00
|
|
|
run_test("sender_hover", (override) => {
|
2021-02-11 01:23:23 +01:00
|
|
|
override(popovers, "hide_user_profile", 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
|
|
|
});
|
|
|
|
|
2018-04-12 17:43:43 +02:00
|
|
|
rows.id = () => message.id;
|
|
|
|
|
|
|
|
current_msg_list.get = (msg_id) => {
|
|
|
|
assert.equal(msg_id, message.id);
|
|
|
|
return message;
|
|
|
|
};
|
|
|
|
|
|
|
|
current_msg_list.select_id = (msg_id) => {
|
|
|
|
assert.equal(msg_id, message.id);
|
|
|
|
};
|
|
|
|
|
|
|
|
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 {};
|
|
|
|
};
|
|
|
|
|
2020-12-01 00:19:42 +01:00
|
|
|
stub_templates((fn, opts) => {
|
2018-04-12 17:43:43 +02:00
|
|
|
switch (fn) {
|
2020-07-15 00:34:28 +02:00
|
|
|
case "no_arrow_popover":
|
|
|
|
assert.deepEqual(opts, {
|
|
|
|
class: "message-info-popover",
|
|
|
|
});
|
|
|
|
return "popover-html";
|
|
|
|
|
|
|
|
case "user_info_popover_title":
|
|
|
|
assert.deepEqual(opts, {
|
|
|
|
user_avatar: "avatar/alice@example.com",
|
|
|
|
user_is_guest: false,
|
|
|
|
});
|
|
|
|
return "title-html";
|
|
|
|
|
|
|
|
case "user_info_popover_content":
|
|
|
|
assert.deepEqual(opts, {
|
|
|
|
can_set_away: false,
|
|
|
|
can_revoke_away: false,
|
|
|
|
user_full_name: "Alice Smith",
|
|
|
|
user_email: "alice@example.com",
|
|
|
|
user_id: 42,
|
|
|
|
user_time: undefined,
|
|
|
|
user_type: i18n.t("Member"),
|
|
|
|
user_circle_class: "user_circle_empty",
|
|
|
|
user_last_seen_time_status: "translated: More than 2 weeks ago",
|
|
|
|
pm_with_uri: "#narrow/pm-with/42-alice",
|
|
|
|
sent_by_uri: "#narrow/sender/42-alice",
|
|
|
|
private_message_class: "respond_personal_button",
|
|
|
|
show_email: false,
|
|
|
|
show_user_profile: false,
|
|
|
|
is_me: false,
|
|
|
|
is_active: true,
|
|
|
|
is_bot: undefined,
|
|
|
|
is_sender_popover: true,
|
2020-06-27 21:33:09 +02:00
|
|
|
has_message_context: true,
|
2020-07-15 00:34:28 +02:00
|
|
|
status_text: "on the beach",
|
2020-06-27 21:33:09 +02:00
|
|
|
user_mention_syntax: "@**Alice Smith**",
|
2020-07-15 00:34:28 +02:00
|
|
|
});
|
|
|
|
return "content-html";
|
|
|
|
|
|
|
|
default:
|
2020-10-07 09:58:04 +02:00
|
|
|
throw new Error("unrecognized template: " + fn);
|
2018-04-12 17:43:43 +02:00
|
|
|
}
|
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: []});
|
2019-11-02 00:06:25 +01:00
|
|
|
const image_stubber = make_image_stubber();
|
2020-04-07 20:09:30 +02:00
|
|
|
window.location = {
|
2020-07-15 01:29:15 +02:00
|
|
|
href: "http://chat.zulip.org/",
|
2020-04-07 20:09:30 +02:00
|
|
|
};
|
|
|
|
const base_url = window.location.href;
|
2018-04-12 17:43:43 +02:00
|
|
|
handler.call(target, e);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const avatar_img = image_stubber.get(0);
|
2020-07-15 01:29:15 +02:00
|
|
|
const expected_url = new URL("avatar/42/medium?v=" + alice.avatar_version, base_url);
|
2020-04-07 20:09:30 +02:00
|
|
|
assert.equal(avatar_img.src.toString(), expected_url.toString());
|
2018-04-12 17:43:43 +02:00
|
|
|
|
|
|
|
// todo: load image
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2019-06-15 06:31:57 +02:00
|
|
|
|
2020-07-26 16:38:46 +02:00
|
|
|
run_test("actions_popover", (override) => {
|
2021-02-11 01:23:23 +01:00
|
|
|
override(popovers, "hide_user_profile", noop);
|
2020-07-26 16:38:46 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const handler = $("#main_div").get_on_handler("click", ".actions_hover");
|
2019-06-15 06:31:57 +02:00
|
|
|
|
|
|
|
window.location = {
|
2020-07-15 01:29:15 +02:00
|
|
|
protocol: "http:",
|
|
|
|
host: "chat.zulip.org",
|
|
|
|
pathname: "/",
|
2019-06-15 06:31:57 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const message = {
|
2019-06-15 06:31:57 +02:00
|
|
|
id: 999,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "Actions (1)",
|
|
|
|
type: "stream",
|
2019-06-15 06:31:57 +02:00
|
|
|
stream_id: 123,
|
|
|
|
};
|
|
|
|
|
|
|
|
current_msg_list.get = (msg_id) => {
|
|
|
|
assert.equal(msg_id, message.id);
|
|
|
|
return message;
|
|
|
|
};
|
|
|
|
|
|
|
|
message_edit.get_editability = () => 4;
|
|
|
|
|
|
|
|
stream_data.id_to_slug = (stream_id) => {
|
|
|
|
assert.equal(stream_id, 123);
|
2020-07-15 01:29:15 +02:00
|
|
|
return "Bracket ( stream";
|
2019-06-15 06:31:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
target.closest = (sel) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(sel, ".message_row");
|
2019-06-15 06:31:57 +02:00
|
|
|
return {
|
|
|
|
toggleClass: noop,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-12-01 00:19:42 +01:00
|
|
|
stub_templates((fn, opts) => {
|
2019-06-15 06:31:57 +02:00
|
|
|
// TODO: Test all the properties of the popover
|
|
|
|
switch (fn) {
|
2020-07-15 00:34:28 +02:00
|
|
|
case "actions_popover_content":
|
|
|
|
assert.equal(
|
|
|
|
opts.conversation_time_uri,
|
|
|
|
"http://chat.zulip.org/#narrow/stream/Bracket.20%28.20stream/topic/Actions.20%281%29/near/999",
|
|
|
|
);
|
|
|
|
return "actions-content";
|
|
|
|
default:
|
2020-10-07 09:58:04 +02:00
|
|
|
throw new Error("unrecognized template: " + fn);
|
2019-06-15 06:31:57 +02:00
|
|
|
}
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2019-06-15 06:31:57 +02:00
|
|
|
|
|
|
|
handler.call(target, e);
|
|
|
|
});
|