From bd7d9da668a049de13fa30d5ceb7730e6a11892d Mon Sep 17 00:00:00 2001 From: Cynthia Lin Date: Sat, 16 Sep 2017 08:30:07 -0700 Subject: [PATCH] hotkeys: Disable 'n' stream creation if user cannot create streams. Tweaked by tabbott to handle a corner case and add test coverage. --- frontend_tests/node_tests/hotkey.js | 8 +++++++- static/js/hotkey.js | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index dbdd047bf0..ec7560d214 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -17,6 +17,9 @@ set_global('activity', { set_global('drafts', { }); +set_global('page_params', { +}); + set_global('overlays', { }); @@ -194,12 +197,15 @@ function stubbing(func_name_to_stub, test_function) { hotkey.processing_text = return_false; overlays.settings_open = return_false; + page_params.can_create_streams = true; overlays.streams_open = return_true; overlays.is_active = return_true; assert_mapping('S', 'subs.keyboard_sub'); - overlays.is_active = return_false; assert_mapping('V', 'subs.view_stream'); assert_mapping('n', 'subs.new_stream_clicked'); + page_params.can_create_streams = false; + assert_unmapped('n'); + overlays.is_active = return_false; overlays.streams_open = return_false; assert_mapping('?', 'ui.maybe_show_keyboard_shortcuts'); diff --git a/static/js/hotkey.js b/static/js/hotkey.js index b7d3758460..408965c068 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -603,14 +603,18 @@ exports.process_hotkey = function (e, hotkey) { case 'view_selected_stream': if (overlays.streams_open()) { subs.view_stream(); + return true; } - return true; + break; case 'n_key': if (overlays.streams_open()) { - subs.new_stream_clicked(); - } else { - narrow.narrow_to_next_topic(); + if (page_params.can_create_streams) { + subs.new_stream_clicked(); + return true; + } + return false; } + narrow.narrow_to_next_topic(); return true; case 'open_drafts': drafts.toggle();