Skip to content

Commit 39a1ad0

Browse files
committed
views: Markup stream description using MessageBox.transform_content().
Footlinks support is added in a subsequent commit. Test amended. Fixes zulip#743.
1 parent 3c14642 commit 39a1ad0

File tree

2 files changed

+51
-14
lines changed

2 files changed

+51
-14
lines changed

tests/ui_tools/test_popups.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ def mock_external_classes(self, mocker, monkeypatch):
564564
self.stream_id: {
565565
'name': 'books',
566566
'invite_only': False,
567-
'description': 'hey',
568567
'subscribers': [],
569568
'stream_weekly_traffic': 123,
569+
'rendered_description': '<p>Hey</p>',
570570
}
571571
}
572572
self.stream_info_view = StreamInfoView(self.controller, self.stream_id)
@@ -585,6 +585,34 @@ def test_keypress_stream_members(self, mocker, key, widget_size):
585585
stream_id=self.stream_id,
586586
)
587587

588+
@pytest.mark.parametrize('rendered_description, expected_markup', [
589+
(
590+
'<p>Simple</p>',
591+
(None, ['', '', 'Simple']),
592+
),
593+
(
594+
'<p>A city in Italy <a href="http://genericlink.com">ABC</a>'
595+
'<strong>Bold</strong>',
596+
(None, ['', '', 'A city in Italy ', ('msg_link', 'ABC'), ' ',
597+
('msg_link_index', '[1]'), ('msg_bold', 'Bold')]),
598+
),
599+
])
600+
def test_markup_descrption(self, rendered_description, expected_markup,
601+
stream_id=10):
602+
self.controller.model.stream_dict = {
603+
stream_id: {
604+
'name': 'ZT',
605+
'invite_only': False,
606+
'subscribers': [],
607+
'stream_weekly_traffic': 123,
608+
'rendered_description': rendered_description,
609+
}
610+
}
611+
612+
stream_info_view = StreamInfoView(self.controller, stream_id)
613+
614+
assert stream_info_view.markup_desc == expected_markup
615+
588616
@pytest.mark.parametrize('key', {*keys_for_command('GO_BACK'),
589617
*keys_for_command('STREAM_DESC')})
590618
def test_keypress_exit_popup(self, key, widget_size):

zulipterminal/ui_tools/views.py

+22-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from zulipterminal.helper import (
1818
Message, asynch, edit_mode_captions, match_stream, match_user,
1919
)
20-
from zulipterminal.ui_tools.boxes import PanelSearchBox
20+
from zulipterminal.ui_tools.boxes import MessageBox, PanelSearchBox
2121
from zulipterminal.ui_tools.buttons import (
2222
HomeButton, MentionedButton, MessageLinkButton, PMButton, StarredButton,
2323
StreamButton, TopicButton, UnreadPMButton, UserButton,
@@ -1087,18 +1087,22 @@ def __init__(self, controller: Any, stream_id: int) -> None:
10871087
stream_marker = (STREAM_MARKER_PRIVATE if stream['invite_only']
10881088
else STREAM_MARKER_PUBLIC)
10891089
title = '{} {}'.format(stream_marker, stream['name'])
1090+
rendered_desc = stream['rendered_description']
1091+
self.markup_desc, *_ = MessageBox.transform_content(
1092+
rendered_desc,
1093+
self.controller.model.server_url,
1094+
)
1095+
desc = urwid.Text(self.markup_desc)
1096+
1097+
stream_info_content = [
1098+
('Stream Details', [
1099+
('Weekly Message Count', str(weekly_msg_count)),
1100+
('Stream Members', '{} (Press {} to view list)'.format(
1101+
total_members, member_keys)),
1102+
]),
1103+
('Stream settings', []),
1104+
] # type: PopUpViewTableContent
10901105

1091-
desc = stream['description']
1092-
1093-
stream_info_content = [('', [desc]),
1094-
('Stream Details', [
1095-
('Weekly Message Count',
1096-
str(weekly_msg_count)),
1097-
('Stream Members',
1098-
'{} (Press {} to view list)'.format(
1099-
total_members, member_keys))
1100-
]),
1101-
('Stream settings', [])]
11021106
popup_width, column_widths = self.calculate_table_widths(
11031107
stream_info_content, len(title))
11041108

@@ -1117,9 +1121,14 @@ def __init__(self, controller: Any, stream_id: int) -> None:
11171121
# Manual because calculate_table_widths does not support checkboxes.
11181122
# Add 4 to checkbox label to accomodate the checkbox itself.
11191123
popup_width = max(popup_width, len(muted_setting.label) + 4,
1120-
len(pinned_setting.label) + 4)
1124+
len(pinned_setting.label) + 4, desc.pack()[0])
11211125
self.widgets = self.make_table_with_categories(stream_info_content,
11221126
column_widths)
1127+
1128+
# Stream description.
1129+
self.widgets.insert(0, desc)
1130+
self.widgets.insert(1, urwid.Text('')) # Add a newline.
1131+
11231132
self.widgets.append(muted_setting)
11241133
self.widgets.append(pinned_setting)
11251134
super().__init__(controller, self.widgets, 'STREAM_DESC', popup_width,

0 commit comments

Comments
 (0)