2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-04-13 06:51:54 +02:00
|
|
|
const {$t} = require("../zjsunit/i18n");
|
2021-06-16 15:58:34 +02:00
|
|
|
const {mock_esm, set_global, with_field, zrequire, mock_template} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-02-21 15:38:51 +01:00
|
|
|
const $ = require("../zjsunit/zjquery");
|
2021-03-25 22:35:45 +01:00
|
|
|
const {page_params} = require("../zjsunit/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
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
const rows = mock_esm("../../static/js/rows");
|
|
|
|
const stream_data = mock_esm("../../static/js/stream_data");
|
|
|
|
mock_esm("../../static/js/emoji_picker", {
|
2018-04-12 17:43:43 +02:00
|
|
|
hide_emoji_popover: noop,
|
|
|
|
});
|
2021-03-31 07:48:11 +02:00
|
|
|
mock_esm("../../static/js/giphy", {
|
|
|
|
hide_giphy_popover: noop,
|
|
|
|
});
|
2021-03-30 02:21:21 +02:00
|
|
|
const message_lists = mock_esm("../../static/js/message_lists", {
|
2021-05-20 11:37:57 +02:00
|
|
|
current: {
|
|
|
|
view: {
|
|
|
|
message_containers: {},
|
|
|
|
},
|
|
|
|
},
|
2021-03-30 02:21:21 +02:00
|
|
|
});
|
2021-03-10 06:10:32 +01:00
|
|
|
mock_esm("../../static/js/message_viewport", {
|
2021-03-06 17:37:51 +01:00
|
|
|
height: () => 500,
|
|
|
|
});
|
2021-03-10 06:10:32 +01:00
|
|
|
mock_esm("../../static/js/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-06-14 10:40:34 +02:00
|
|
|
const render_actions_popover_content = mock_template("actions_popover_content.hbs");
|
|
|
|
const render_user_info_popover_content = mock_template("user_info_popover_content.hbs");
|
|
|
|
const render_user_info_popover_title = mock_template("user_info_popover_title.hbs");
|
|
|
|
const render_no_arrow_popover = mock_template("no_arrow_popover.hbs");
|
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const people = zrequire("people");
|
|
|
|
const user_status = zrequire("user_status");
|
|
|
|
const message_edit = zrequire("message_edit");
|
2021-02-22 13:55:34 +01:00
|
|
|
|
|
|
|
// Bypass some scary code that runs when we import the module.
|
2021-02-24 22:31:50 +01:00
|
|
|
const popovers = with_field($.fn, "popover", noop, () => 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",
|
|
|
|
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,
|
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
|
|
|
|
|
|
|
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],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-02-21 12:44:39 +01:00
|
|
|
function test_ui(label, f) {
|
2021-06-16 14:38:37 +02:00
|
|
|
run_test(label, ({override}) => {
|
2021-04-03 19:07:13 +02:00
|
|
|
page_params.is_admin = false;
|
|
|
|
page_params.realm_email_address_visibility = 3;
|
|
|
|
page_params.custom_profile_fields = [];
|
2021-03-06 20:28:43 +01:00
|
|
|
override(popovers, "clipboard_enable", noop);
|
2021-03-16 11:31:40 +01:00
|
|
|
popovers.clear_for_testing();
|
2021-02-21 12:44:39 +01:00
|
|
|
popovers.register_click_handlers();
|
2021-06-16 14:38:37 +02:00
|
|
|
f({override});
|
2021-02-21 12:44:39 +01:00
|
|
|
});
|
|
|
|
}
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test_ui("sender_hover", ({override}) => {
|
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
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2021-02-21 12:44:39 +01:00
|
|
|
const target = $.create("click target");
|
|
|
|
|
2018-04-12 17:43:43 +02: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-14 10:40:34 +02:00
|
|
|
override(render_no_arrow_popover, "f", (opts) => {
|
|
|
|
assert.deepEqual(opts, {
|
|
|
|
class: "message-info-popover",
|
|
|
|
});
|
|
|
|
return "popover-html";
|
|
|
|
});
|
|
|
|
|
|
|
|
override(render_user_info_popover_title, "f", (opts) => {
|
|
|
|
assert.deepEqual(opts, {
|
|
|
|
user_avatar: "avatar/alice@example.com",
|
|
|
|
user_is_guest: false,
|
|
|
|
});
|
|
|
|
return "title-html";
|
|
|
|
});
|
|
|
|
|
|
|
|
override(render_user_info_popover_content, "f", (opts) => {
|
|
|
|
assert.deepEqual(opts, {
|
|
|
|
can_set_away: false,
|
|
|
|
can_revoke_away: false,
|
|
|
|
can_mute: true,
|
|
|
|
can_unmute: false,
|
|
|
|
user_full_name: "Alice Smith",
|
|
|
|
user_email: "alice@example.com",
|
|
|
|
user_id: 42,
|
|
|
|
user_time: undefined,
|
|
|
|
user_type: $t({defaultMessage: "Member"}),
|
|
|
|
user_circle_class: "user_circle_empty",
|
|
|
|
user_last_seen_time_status:
|
|
|
|
"translated: Last active: 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,
|
|
|
|
has_message_context: true,
|
|
|
|
status_text: "on the beach",
|
|
|
|
user_mention_syntax: "@**Alice Smith**",
|
|
|
|
});
|
|
|
|
return "content-html";
|
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
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test_ui("actions_popover", ({override}) => {
|
2021-02-22 13:55:34 +01:00
|
|
|
override($.fn, "popover", noop);
|
|
|
|
|
2021-02-21 12:44:39 +01:00
|
|
|
const target = $.create("click target");
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.get = (msg_id) => {
|
2019-06-15 06:31:57 +02:00
|
|
|
assert.equal(msg_id, message.id);
|
|
|
|
return message;
|
|
|
|
};
|
|
|
|
|
2021-05-20 11:37:57 +02:00
|
|
|
message_lists.current.view.message_containers.get = (msg_id) => {
|
|
|
|
assert.equal(msg_id, message.id);
|
|
|
|
return {
|
|
|
|
is_hidden: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-03-07 17:01:11 +01:00
|
|
|
override(message_edit, "get_editability", () => 4);
|
2019-06-15 06:31:57 +02:00
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-14 10:40:34 +02:00
|
|
|
override(render_actions_popover_content, "f", (opts) => {
|
2019-06-15 06:31:57 +02:00
|
|
|
// TODO: Test all the properties of the popover
|
2021-06-14 10:40:34 +02:00
|
|
|
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";
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2019-06-15 06:31:57 +02:00
|
|
|
|
|
|
|
handler.call(target, e);
|
|
|
|
});
|