Skip to content

Commit

Permalink
boxes/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 Jul 30, 2020
1 parent 7c27223 commit a7cf421
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
14 changes: 11 additions & 3 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,8 +1470,15 @@ def test_keypress_exit_popup(self, key):
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, message_fixture, key):
size = (200, 20)
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 @@ -1518,8 +1525,9 @@ def test_height_reactions(self, message_fixture, to_vary_in_each_message):
varied_message = dict(message_fixture, **to_vary_in_each_message)
self.msg_info_view = MsgInfoView(self.controller, varied_message,
'Message Information', OrderedDict())
# 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,
Expand Down
2 changes: 0 additions & 2 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,6 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
elif is_command_key('MSG_INFO', key):
self.model.controller.show_msg_info(self.message,
self.message_links)
elif is_command_key('VIEW_IN_BROWSER', key):
self.model.controller.view_in_browser(self.message['id'])
return key


Expand Down
16 changes: 12 additions & 4 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import urwid

from zulipterminal.config.keys import (
HELP_CATEGORIES, KEY_BINDINGS, is_command_key,
HELP_CATEGORIES, KEY_BINDINGS, is_command_key, keys_for_command,
)
from zulipterminal.config.symbols import (
CHECK_MARK, LIST_TITLE_BAR_LINE, PINNED_STREAMS_DIVIDER,
Expand Down Expand Up @@ -1067,7 +1067,10 @@ def __init__(self, controller: Any, msg: Message, title: str,
msg_info = [
('', [('Date & Time', time.ctime(msg['timestamp'])[:-5]),
('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'))))),
]),
]
# Render the category using the existing table methods if links exist.
if message_links:
Expand Down Expand Up @@ -1105,8 +1108,13 @@ def __init__(self, controller: Any, msg: Message, title: str,
urwid.AttrMap(urwid.Text(caption), display_attr)
)

# 5 = 3 labels + 1 newline + 1 'Message Links' category label.
widgets = widgets[:5] + message_link_widgets + widgets[5:]
# 6 = 4 labels + 1 newline + 1 'Message Links' category label.
widgets = widgets[:6] + message_link_widgets + widgets[6:]
popup_width = max(popup_width, message_link_width)

super().__init__(controller, widgets, 'MSG_INFO', popup_width, title)

def keypress(self, size: urwid_Size, key: str) -> str:
if is_command_key('VIEW_IN_BROWSER', key):
self.controller.view_in_browser(self.msg['id'])
return super().keypress(size, key)

0 comments on commit a7cf421

Please sign in to comment.