Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
views: Hook the view_in_browser functionality with its key.
Browse files Browse the repository at this point in the history
This commit hooks the view_in_browser functionality with the key
for it. Any message can now be viewed in the browser by pressing the
view_in_browser key from the MessageInfo view. It also adds tests
for the corresponding keypress in test_popups.

Test amended.

Co-authored-by: Puneeth Chaganti <punchagan@muse-amuse.in>
Co-authored-by: Preet Mishra <ipreetmishra@gmail.com>
3 people committed Jun 10, 2021
1 parent c4072a7 commit 55708de
Showing 2 changed files with 24 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/ui_tools/test_popups.py
Original file line number Diff line number Diff line change
@@ -580,8 +580,18 @@ 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, mocker, widget_size, message_fixture, key):
size = widget_size(self.msg_info_view)
self.msg_info_view.server_url = "https://chat.zulip.org/"
mocker.patch(VIEWS + ".near_message_url")

self.msg_info_view.keypress(size, key)

assert self.controller.open_in_browser.called

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
@@ -644,8 +654,9 @@ def test_height_reactions(self, message_fixture, to_vary_in_each_message):
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

@pytest.mark.parametrize(
10 changes: 10 additions & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
)
from zulipterminal.config.ui_mappings import EDIT_MODE_CAPTIONS
from zulipterminal.helper import Message, asynch, match_stream, match_user
from zulipterminal.server_url import near_message_url
from zulipterminal.ui_tools.boxes import MessageBox, PanelSearchBox
from zulipterminal.ui_tools.buttons import (
HomeButton,
@@ -1297,9 +1298,11 @@ def __init__(
self.topic_links = topic_links
self.message_links = message_links
self.time_mentions = time_mentions
self.server_url = controller.model.server_url
date_and_time = controller.model.formatted_local_time(
msg["timestamp"], show_seconds=True, show_year=True
)
view_in_browser_keys = ", ".join(map(repr, keys_for_command("VIEW_IN_BROWSER")))

msg_info = [
(
@@ -1308,6 +1311,10 @@ def __init__(
("Date & Time", date_and_time),
("Sender", msg["sender_full_name"]),
("Sender's Email ID", msg["sender_email"]),
(
"View message in browser",
f"Press {view_in_browser_keys} to view message in browser",
),
],
),
]
@@ -1410,6 +1417,9 @@ 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):
url = near_message_url(self.server_url[:-1], self.msg)
self.controller.open_in_browser(url)
return super().keypress(size, key)


0 comments on commit 55708de

Please sign in to comment.