2018-04-12 17:43:43 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
|
|
|
zrequire('hash_util');
|
|
|
|
zrequire('narrow');
|
|
|
|
zrequire('narrow_state');
|
|
|
|
zrequire('people');
|
|
|
|
zrequire('presence');
|
2019-02-01 05:42:38 +01:00
|
|
|
zrequire('buddy_data');
|
2019-02-01 02:33:01 +01:00
|
|
|
zrequire('user_status');
|
2019-06-15 06:31:57 +02:00
|
|
|
zrequire('feature_flags');
|
|
|
|
zrequire('message_edit');
|
2018-04-12 17:43:43 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const noop = function () {};
|
2018-04-12 17:43:43 +02:00
|
|
|
$.fn.popover = noop; // this will get wrapped by our code
|
|
|
|
|
|
|
|
zrequire('popovers');
|
2018-08-15 19:34:38 +02:00
|
|
|
popovers.hide_user_profile = noop;
|
2018-04-12 17:43:43 +02:00
|
|
|
|
|
|
|
set_global('current_msg_list', {});
|
2018-04-24 02:24:14 +02:00
|
|
|
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: [],
|
|
|
|
});
|
2018-04-12 17:43:43 +02:00
|
|
|
set_global('rows', {});
|
|
|
|
|
|
|
|
|
|
|
|
set_global('message_viewport', {
|
|
|
|
height: () => 500,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('emoji_picker', {
|
|
|
|
hide_emoji_popover: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('stream_popover', {
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2019-06-15 06:31:57 +02:00
|
|
|
set_global('stream_data', {});
|
|
|
|
|
2018-04-12 17:43:43 +02:00
|
|
|
set_global('ClipboardJS', function (sel) {
|
|
|
|
assert.equal(sel, '.copy_link');
|
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2018-04-12 17:43:43 +02:00
|
|
|
email: 'alice@example.com',
|
|
|
|
full_name: 'Alice Smith',
|
|
|
|
user_id: 42,
|
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 = {
|
2018-04-12 17:43:43 +02:00
|
|
|
email: 'me@example.com',
|
|
|
|
user_id: 30,
|
|
|
|
full_name: 'Me Myself',
|
|
|
|
timezone: 'US/Pacific',
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const target = $.create('click target');
|
2019-06-15 06:31:57 +02:00
|
|
|
target.offset = () => {
|
|
|
|
return {
|
|
|
|
top: 10,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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-03-21 20:19:30 +01:00
|
|
|
people.add(me);
|
|
|
|
people.add(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 = {};
|
2018-04-12 17:43:43 +02:00
|
|
|
image.to_$ = () => {
|
|
|
|
return {
|
|
|
|
on: (name, f) => {
|
|
|
|
assert.equal(name, "load");
|
|
|
|
image.load_f = f;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
images.push(image);
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_global('Image', function () {
|
|
|
|
return stub_image();
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-06-15 06:31:57 +02:00
|
|
|
run_test('sender_hover', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const selection = ".sender_name, .sender_name-in-status, .inline_profile_picture";
|
|
|
|
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,
|
|
|
|
status_text: 'on the beach',
|
|
|
|
});
|
|
|
|
|
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) => {
|
|
|
|
assert.equal(sel, '.message_row');
|
|
|
|
return {};
|
|
|
|
};
|
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates(function (fn, opts) {
|
2018-04-12 17:43:43 +02:00
|
|
|
switch (fn) {
|
2019-02-14 15:01:39 +01:00
|
|
|
case 'no_arrow_popover':
|
2018-05-07 03:30:13 +02:00
|
|
|
assert.deepEqual(opts, {
|
|
|
|
class: 'message-info-popover',
|
|
|
|
});
|
|
|
|
return 'popover-html';
|
|
|
|
|
|
|
|
case 'user_info_popover_title':
|
|
|
|
assert.deepEqual(opts, {
|
|
|
|
user_avatar: 'avatar/alice@example.com',
|
2018-12-17 02:25:00 +01:00
|
|
|
user_is_guest: false,
|
2018-05-07 03:30:13 +02:00
|
|
|
});
|
|
|
|
return 'title-html';
|
|
|
|
|
|
|
|
case 'user_info_popover_content':
|
|
|
|
assert.deepEqual(opts, {
|
2018-12-20 15:22:30 +01:00
|
|
|
can_set_away: false,
|
|
|
|
can_revoke_away: false,
|
2018-05-07 03:30:13 +02:00
|
|
|
user_full_name: 'Alice Smith',
|
|
|
|
user_email: 'alice@example.com',
|
|
|
|
user_id: 42,
|
|
|
|
user_time: undefined,
|
2018-11-02 19:45:32 +01:00
|
|
|
user_type: i18n.t('Member'),
|
2019-02-17 02:10:42 +01:00
|
|
|
user_circle_class: 'user_circle_empty',
|
2018-08-15 20:58:12 +02:00
|
|
|
user_last_seen_time_status: 'translated: More than 2 weeks ago',
|
2018-05-07 03:30:13 +02:00
|
|
|
pm_with_uri: '#narrow/pm-with/42-alice',
|
|
|
|
sent_by_uri: '#narrow/sender/42-alice',
|
|
|
|
private_message_class: 'respond_personal_button',
|
2019-04-20 18:08:29 +02:00
|
|
|
show_email: false,
|
2018-05-07 03:30:13 +02:00
|
|
|
show_user_profile: false,
|
|
|
|
is_me: false,
|
|
|
|
is_active: true,
|
|
|
|
is_bot: undefined,
|
|
|
|
is_sender_popover: true,
|
2019-02-01 02:33:01 +01:00
|
|
|
status_text: 'on the beach',
|
2018-05-07 03:30:13 +02:00
|
|
|
});
|
|
|
|
return 'content-html';
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw 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
|
|
|
|
|
|
|
$('.user_popover_email').each = noop;
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const image_stubber = make_image_stubber();
|
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);
|
2018-04-12 17:43:43 +02:00
|
|
|
assert.equal(avatar_img.src, 'avatar/42/medium');
|
|
|
|
|
|
|
|
// todo: load image
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2019-06-15 06:31:57 +02:00
|
|
|
|
|
|
|
run_test('actions_popover', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const handler = $('#main_div').get_on_handler('click', '.actions_hover');
|
2019-06-15 06:31:57 +02:00
|
|
|
|
|
|
|
window.location = {
|
|
|
|
protocol: 'http:',
|
|
|
|
host: 'chat.zulip.org',
|
|
|
|
pathname: '/',
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const message = {
|
2019-06-15 06:31:57 +02:00
|
|
|
id: 999,
|
|
|
|
topic: 'Actions (1)',
|
|
|
|
type: 'stream',
|
|
|
|
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);
|
|
|
|
return 'Bracket ( stream';
|
|
|
|
};
|
|
|
|
|
|
|
|
target.closest = (sel) => {
|
|
|
|
assert.equal(sel, '.message_row');
|
|
|
|
return {
|
|
|
|
toggleClass: noop,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-07-11 05:06:20 +02:00
|
|
|
global.stub_templates(function (fn, opts) {
|
2019-06-15 06:31:57 +02:00
|
|
|
// TODO: Test all the properties of the popover
|
|
|
|
switch (fn) {
|
|
|
|
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:
|
|
|
|
throw Error('unrecognized template: ' + fn);
|
|
|
|
}
|
2019-07-11 05:06:20 +02:00
|
|
|
});
|
2019-06-15 06:31:57 +02:00
|
|
|
|
|
|
|
handler.call(target, e);
|
|
|
|
});
|