diff --git a/frontend_tests/node_tests/top_left_corner.js b/frontend_tests/node_tests/top_left_corner.js index 07fcbc794a..d21c715870 100644 --- a/frontend_tests/node_tests/top_left_corner.js +++ b/frontend_tests/node_tests/top_left_corner.js @@ -29,8 +29,15 @@ run_test('narrowing', () => { user_id: 1, full_name: 'Alice Smith', }; - people.add(alice); + const bob = { + email: 'bob@example.com', + user_id: 2, + full_name: 'Bob Patel', + }; + people.add_in_realm(alice); + people.add_in_realm(bob); + pm_expanded = false; filter = new Filter([ {operator: 'pm-with', operand: 'alice@example.com'}, @@ -38,6 +45,13 @@ run_test('narrowing', () => { top_left_corner.handle_narrow_activated(filter); assert(pm_expanded); + pm_expanded = false; + filter = new Filter([ + {operator: 'pm-with', operand: 'bob@example.com,alice@example.com'}, + ]); + top_left_corner.handle_narrow_activated(filter); + assert(pm_expanded); + pm_expanded = false; filter = new Filter([ {operator: 'pm-with', operand: 'not@valid.com'}, diff --git a/static/js/top_left_corner.js b/static/js/top_left_corner.js index c785480e0d..5dddca8f7f 100644 --- a/static/js/top_left_corner.js +++ b/static/js/top_left_corner.js @@ -73,19 +73,35 @@ exports.handle_narrow_activated = function (filter) { } } - var op_is = filter.operands('is'); - var op_pm = filter.operands('pm-with'); - if (op_is.length >= 1 && _.contains(op_is, "private") || op_pm.length >= 1) { - if (!people.is_valid_bulk_emails_for_compose(op_pm)) { - // Don't go into the else statement and close the pm_list. - return; - } + if (exports.should_expand_pm_list(filter)) { + var op_pm = filter.operands('pm-with'); pm_list.expand(op_pm); } else { pm_list.close(); } }; +exports.should_expand_pm_list = function (filter) { + var op_is = filter.operands('is'); + + if (op_is.length >= 1 && _.contains(op_is, "private")) { + return true; + } + + var op_pm = filter.operands('pm-with'); + + if (op_pm.length !== 1) { + return false; + } + + var emails_strings = op_pm[0]; + var emails = emails_strings.split(','); + + var has_valid_emails = people.is_valid_bulk_emails_for_compose(emails); + + return has_valid_emails; +}; + exports.handle_narrow_deactivated = function () { deselect_top_left_corner_items(); pm_list.close();