Skip to content

Commit

Permalink
reactions.js: Extract open_reactions_popover().
Browse files Browse the repository at this point in the history
Added tests for open_reactions_popover() also.
  • Loading branch information
lonerz authored and timabbott committed Sep 20, 2017
1 parent 67064a4 commit d387291
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion frontend_tests/node_tests/hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function stubbing(func_name_to_stub, test_function) {
assert_mapping('u', 'popovers.show_sender_info');
assert_mapping('v', 'lightbox.show_from_selected_message');
assert_mapping('i', 'popovers.open_message_menu');
assert_mapping(':', 'emoji_picker.toggle_emoji_popover', true);
assert_mapping(':', 'reactions.open_reactions_popover', true);
assert_mapping('G', 'navigate.to_end');
assert_mapping('M', 'muting_ui.toggle_mute');

Expand Down
39 changes: 39 additions & 0 deletions frontend_tests/node_tests/reactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,45 @@ set_global('message_store', {
},
});

set_global('current_msg_list', {
selected_message: function () {
return { sent_by_me: true };
},
selected_row: function () {
return $('.selected-row');
},
selected_id: function () {
return 42;
},
});

(function test_open_reactions_popover() {
$('.selected-row').set_find_results('.actions_hover', $('.target-action'));
$('.selected-row').set_find_results('.reaction_button', $('.target-reaction'));

var called = false;
emoji_picker.toggle_emoji_popover = function (target, id) {
called = true;
assert.equal(id, 42);
assert.equal(target, $('.target-reaction')[0]);
};

assert(reactions.open_reactions_popover());
assert(called);

current_msg_list.selected_message = function () { return { sent_by_me: false }; };

called = false;
emoji_picker.toggle_emoji_popover = function (target, id) {
called = true;
assert.equal(id, 42);
assert.equal(target, $('.target-action')[0]);
};

assert(reactions.open_reactions_popover());
assert(called);
}());

(function test_basics() {
var result = reactions.get_message_reactions(message);

Expand Down
12 changes: 1 addition & 11 deletions static/js/hotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ function do_narrow_action(action) {
return true;
}

function open_reactions() {
var message = current_msg_list.selected_message();
var target = $(current_msg_list.selected_row()).find(".actions_hover")[0];
if (!message.sent_by_me) {
target = $(current_msg_list.selected_row()).find(".reaction_button")[0];
}
emoji_picker.toggle_emoji_popover(target, current_msg_list.selected_id());
return true;
}

var actions_dropdown_hotkeys = [
'down_arrow',
'up_arrow',
Expand Down Expand Up @@ -680,7 +670,7 @@ exports.process_hotkey = function (e, hotkey) {
popovers.show_sender_info();
return true;
case 'open_reactions': // ':': open reactions to message
open_reactions();
reactions.open_reactions_popover();
return true;
case 'thumbs_up_emoji': // '+': reacts with thumbs up emoji on selected message
reactions.toggle_emoji_reaction(msg.id, '+1');
Expand Down
10 changes: 10 additions & 0 deletions static/js/reactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ var exports = {};

exports.view = {}; // function namespace

exports.open_reactions_popover = function () {
var message = current_msg_list.selected_message();
var target = $(current_msg_list.selected_row()).find(".actions_hover")[0];
if (!message.sent_by_me) {
target = $(current_msg_list.selected_row()).find(".reaction_button")[0];
}
emoji_picker.toggle_emoji_popover(target, current_msg_list.selected_id());
return true;
};

function send_reaction_ajax(message_id, emoji_name, operation) {
if (!emoji.emojis_by_name[emoji_name] && !emoji.active_realm_emojis[emoji_name]) {
// Emoji doesn't exist
Expand Down

0 comments on commit d387291

Please sign in to comment.