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");
|
2022-07-10 01:06:33 +02:00
|
|
|
const {mock_cjs, mock_esm, set_global, zrequire} = 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
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
class Clipboard {
|
|
|
|
on() {}
|
|
|
|
}
|
|
|
|
mock_cjs("clipboard", Clipboard);
|
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
const rows = mock_esm("../../static/js/rows");
|
|
|
|
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,
|
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
|
|
|
});
|
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const people = zrequire("people");
|
|
|
|
const user_status = zrequire("user_status");
|
|
|
|
const message_edit = zrequire("message_edit");
|
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",
|
|
|
|
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.realm_email_address_visibility = 3;
|
|
|
|
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";
|
|
|
|
});
|
|
|
|
|
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,
|
2021-06-14 10:40:34 +02:00
|
|
|
can_mute: true,
|
2022-03-18 13:03:26 +01:00
|
|
|
can_manage_user: false,
|
2022-04-22 20:32:41 +02:00
|
|
|
can_send_private_message: true,
|
2021-06-14 10:40:34 +02:00
|
|
|
can_unmute: false,
|
2022-07-12 21:25:02 +02:00
|
|
|
display_profile_fields: [],
|
2021-06-14 10:40:34 +02:00
|
|
|
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",
|
2022-03-01 19:14:26 +01:00
|
|
|
pm_with_url: "#narrow/pm-with/42-alice",
|
2021-06-14 10:40:34 +02:00
|
|
|
sent_by_uri: "#narrow/sender/42-alice",
|
|
|
|
private_message_class: "respond_personal_button",
|
|
|
|
show_email: false,
|
|
|
|
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
|
|
|
});
|
|
|
|
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();
|
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);
|
2021-11-06 07:23:26 +01:00
|
|
|
assert.equal(avatar_img.src.toString(), "/avatar/42/medium");
|
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
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test_ui("actions_popover", ({override, mock_template}) => {
|
2021-02-22 13:55:34 +01:00
|
|
|
override($.fn, "popover", noop);
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $target = $.create("click target");
|
2021-02-21 12:44:39 +01: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
|
|
|
|
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,
|
2022-07-10 01:06:33 +02:00
|
|
|
sent_by_me: true,
|
2019-06-15 06:31:57 +02:00
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
override(page_params, "realm_allow_message_editing", true);
|
2022-04-12 13:13:02 +02:00
|
|
|
override(page_params, "realm_message_content_edit_limit_seconds", null);
|
2022-07-10 01:06:33 +02:00
|
|
|
assert.equal(message_edit.get_editability(message), message_edit.editability_types.FULL);
|
2019-06-15 06:31:57 +02: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");
|
2019-06-15 06:31:57 +02:00
|
|
|
return {
|
|
|
|
toggleClass: noop,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("actions_popover_content.hbs", false, (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,
|
2022-02-28 22:04:13 +01:00
|
|
|
"http://zulip.zulipdev.com/#narrow/stream/123-unknown/topic/Actions.20.281.29/near/999",
|
2021-06-14 10:40:34 +02:00
|
|
|
);
|
|
|
|
return "actions-content";
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2019-06-15 06:31:57 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
handler.call($target, e);
|
2019-06-15 06:31:57 +02:00
|
|
|
});
|