Skip to content

Commit

Permalink
views: Amend trigger sequence for view_in_browser().
Browse files Browse the repository at this point in the history
This makes MsgInfoView handle VIEW_IN_BROWSER keypress in order to avoid
too many/unintended triggers.

Tests amended and added.
  • Loading branch information
preetmishra committed Apr 4, 2021
1 parent fa82f8a commit 7c0c9fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 13 additions & 3 deletions tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,17 @@ def test_keypress_exit_popup(self, key, widget_size):
self.msg_info_view.keypress(size, key)
assert self.controller.exit_popup.called

@pytest.mark.parametrize('key', keys_for_command('VIEW_IN_BROWSER'))
def test_keypress_view_in_browser(self, widget_size, message_fixture, key):
size = widget_size(self.msg_info_view)

self.msg_info_view.keypress(size, key)

(self.controller.view_in_browser.
assert_called_once_with(message_fixture['id']))

def test_height_noreactions(self):
expected_height = 3
expected_height = 4
assert self.msg_info_view.height == expected_height

# FIXME This is the same parametrize as MessageBox:test_reactions_view
Expand Down Expand Up @@ -553,8 +562,9 @@ def test_height_reactions(self, message_fixture, to_vary_in_each_message):
self.msg_info_view = MsgInfoView(self.controller, varied_message,
'Message Information', OrderedDict(),
list())
# 9 = 3 labels + 1 blank line + 1 'Reactions' (category) + 4 reactions.
expected_height = 9
# 10 = 4 labels + 1 blank line + 1 'Reactions' (category) + 4
# reactions (excluding 'Message Links').
expected_height = 10
assert self.msg_info_view.height == expected_height

def test_keypress_navigation(self, mocker, widget_size,
Expand Down
7 changes: 6 additions & 1 deletion zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,10 @@ def __init__(self, controller: Any, msg: Message, title: str,
msg_info = [
('', [('Date & Time', date_and_time),
('Sender', msg['sender_full_name']),
('Sender\'s Email ID', msg['sender_email'])]),
('Sender\'s Email ID', msg['sender_email']),
('View message in the web browser', 'Press {}'.format(
', '.join(map(repr, keys_for_command('VIEW_IN_BROWSER'))))),
]),
]
# Only show the 'Edit History' label for edited messages.
self.show_edit_history_label = (
Expand Down Expand Up @@ -1303,6 +1306,8 @@ def keypress(self, size: urwid_Size, key: str) -> str:
message_links=self.message_links,
time_mentions=self.time_mentions,
)
elif is_command_key('VIEW_IN_BROWSER', key):
self.controller.view_in_browser(self.msg['id'])
return super().keypress(size, key)


Expand Down

0 comments on commit 7c0c9fc

Please sign in to comment.