reactions: Simplify code to choose popover target.

We now only assign target once, rather than
assigning it then overwriting it for the
not-sent-by-me use case.

I tried to extract a "selector" here but the linter
complained.

Splitting up the tests here ensures we don't
needlessly do extra work here.  (In the prior
clumsy implementation, the second test that
I split out here would fail due to the lack
of us setting up the jquery stub.)
This commit is contained in:
Steve Howell 2021-02-24 15:50:30 +00:00 committed by Steve Howell
parent da1cd57d5f
commit 0ab3649182
2 changed files with 13 additions and 5 deletions

View File

@ -126,9 +126,9 @@ set_global("current_msg_list", {
},
});
run_test("open_reactions_popover", () => {
run_test("open_reactions_popover (sent by me)", () => {
current_msg_list.selected_message = () => ({sent_by_me: true});
$(".selected-row").set_find_results(".actions_hover", ["action-stub"]);
$(".selected-row").set_find_results(".reaction_button", ["reaction-stub"]);
let called = false;
emoji_picker.toggle_emoji_popover = (target, id) => {
@ -139,10 +139,13 @@ run_test("open_reactions_popover", () => {
assert(reactions.open_reactions_popover());
assert(called);
});
run_test("open_reactions_popover (not sent by me)", () => {
current_msg_list.selected_message = () => ({sent_by_me: false});
$(".selected-row").set_find_results(".reaction_button", ["reaction-stub"]);
called = false;
let called = false;
emoji_picker.toggle_emoji_popover = (target, id) => {
called = true;
assert.equal(id, 42);

View File

@ -15,10 +15,15 @@ exports.get_local_reaction_id = function (reaction_info) {
exports.open_reactions_popover = function () {
const message = current_msg_list.selected_message();
let target = $(current_msg_list.selected_row()).find(".actions_hover")[0];
if (!message.sent_by_me) {
let target;
// Use verbose style to ensure we test both sides of the condition.
if (message.sent_by_me) {
target = $(current_msg_list.selected_row()).find(".actions_hover")[0];
} else {
target = $(current_msg_list.selected_row()).find(".reaction_button")[0];
}
emoji_picker.toggle_emoji_popover(target, current_msg_list.selected_id());
return true;
};