diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js index a467522e38..995e778142 100644 --- a/frontend_tests/node_tests/popovers.js +++ b/frontend_tests/node_tests/popovers.js @@ -9,6 +9,9 @@ zrequire('presence'); zrequire('buddy_data'); zrequire('user_status'); zrequire('settings_org'); +zrequire('feature_flags'); +zrequire('message_edit'); +zrequire('util'); var noop = function () {}; $.fn.popover = noop; // this will get wrapped by our code @@ -40,6 +43,8 @@ set_global('stream_popover', { restore_stream_list_size: noop, }); +set_global('stream_data', {}); + set_global('ClipboardJS', function (sel) { assert.equal(sel, '.copy_link'); }); @@ -59,6 +64,17 @@ var me = { timezone: 'US/Pacific', }; +var target = $.create('click target'); +target.offset = () => { + return { + top: 10, + }; +}; + +var e = { + stopPropagation: noop, +}; + function initialize_people() { people.init(); people.add_in_realm(me); @@ -94,14 +110,11 @@ function make_image_stubber() { }; } -run_test('sender_hover', () => { - popovers.register_click_handlers(); +popovers.register_click_handlers(); +run_test('sender_hover', () => { var selection = ".sender_name, .sender_name-in-status, .inline_profile_picture"; var handler = $('#main_div').get_on_handler('click', selection); - var e = { - stopPropagation: noop, - }; var message = { id: 999, @@ -113,14 +126,6 @@ run_test('sender_hover', () => { status_text: 'on the beach', }); - var target = $.create('click target'); - - target.offset = () => { - return { - top: 10, - }; - }; - rows.id = () => message.id; current_msg_list.get = (msg_id) => { @@ -192,3 +197,54 @@ run_test('sender_hover', () => { // todo: load image }); + +run_test('actions_popover', () => { + var handler = $('#main_div').get_on_handler('click', '.actions_hover'); + + window.location = { + protocol: 'http:', + host: 'chat.zulip.org', + pathname: '/', + }; + + var message = { + 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, + }; + }; + + templates.render = function (fn, opts) { + // 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); + } + }; + + handler.call(target, e); +}); diff --git a/static/js/popovers.js b/static/js/popovers.js index f4ac5c058e..9f25a081d2 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -431,6 +431,10 @@ exports.toggle_actions_popover = function (element, id) { editability === message_edit.editability_types.TOPIC_ONLY; var should_display_quote_and_reply = message.content !== '

(deleted)

'; + var conversation_time_uri = hash_util.by_conversation_and_time_uri(message) + .replace(/\(/g, '%28') + .replace(/\)/g, '%29'); + var should_display_delete_option = message_edit.get_deletability(message); var args = { message_id: message.id, @@ -445,7 +449,7 @@ exports.toggle_actions_popover = function (element, id) { should_display_uncollapse: should_display_uncollapse, should_display_add_reaction_option: message.sent_by_me, should_display_edit_history_option: should_display_edit_history_option, - conversation_time_uri: hash_util.by_conversation_and_time_uri(message), + conversation_time_uri: conversation_time_uri, narrowed: narrow_state.active(), should_display_delete_option: should_display_delete_option, should_display_reminder_option: feature_flags.reminders_in_message_action_menu, diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 925134a9bc..e4ac1b5522 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -41,6 +41,7 @@ enforce_fully_covered = { # 'static/js/composebox_typeahead.js', 'static/js/dict.ts', 'static/js/emoji.js', + 'static/js/feature_flags.js', 'static/js/fenced_code.js', 'static/js/fetch_status.js', 'static/js/filter.js',