Skip to content

Commit 21ac0f7

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 c0329e7 commit 21ac0f7

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

tests/ui_tools/test_popups.py

+33-3
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,41 @@ def mock_external_classes(self, mocker, monkeypatch):
560560
self.controller.model.is_pinned_stream.return_value = False
561561
mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker", return_value=[])
562562
stream_id = 10
563-
self.controller.model.stream_dict = {stream_id: {'name': 'books',
564-
'invite_only': False,
565-
'description': 'hey'}}
563+
self.controller.model.stream_dict = {
564+
stream_id: {
565+
'name': 'books',
566+
'invite_only': False,
567+
'rendered_description': '<p>Hey</p>',
568+
}
569+
}
566570
self.stream_info_view = StreamInfoView(self.controller, stream_id)
567571

572+
@pytest.mark.parametrize('rendered_description, expected_markup', [
573+
(
574+
'<p>Simple</p>',
575+
(None, ['', '', 'Simple']),
576+
),
577+
(
578+
'<p>A city in Italy <a href="http://genericlink.com">ABC</a>'
579+
'<strong>Bold</strong>',
580+
(None, ['', '', 'A city in Italy ', ('msg_link', 'ABC'), ' ',
581+
('msg_link_index', '[1]'), ('msg_bold', 'Bold')]),
582+
),
583+
])
584+
def test_markup_descrption(self, rendered_description, expected_markup,
585+
stream_id=10):
586+
self.controller.model.stream_dict = {
587+
stream_id: {
588+
'name': 'ZT',
589+
'invite_only': False,
590+
'rendered_description': rendered_description,
591+
}
592+
}
593+
594+
stream_info_view = StreamInfoView(self.controller, stream_id)
595+
596+
assert stream_info_view.markup_desc == expected_markup
597+
568598
@pytest.mark.parametrize('key', {*keys_for_command('GO_BACK'),
569599
*keys_for_command('STREAM_DESC')})
570600
def test_keypress_exit_popup(self, key, widget_size):

zulipterminal/ui_tools/views.py

+17-4
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,
@@ -1081,8 +1081,16 @@ def __init__(self, controller: Any, stream_id: int) -> None:
10811081
stream_marker = (STREAM_MARKER_PRIVATE if stream['invite_only']
10821082
else STREAM_MARKER_PUBLIC)
10831083
title = '{} {}'.format(stream_marker, stream['name'])
1084-
desc = stream['description']
1085-
stream_info_content = [('', [desc]), ('Stream settings', [])]
1084+
rendered_desc = stream['rendered_description']
1085+
self.markup_desc, *_ = MessageBox.transform_content(
1086+
rendered_desc,
1087+
self.controller.model.server_url,
1088+
)
1089+
desc = urwid.Text(self.markup_desc)
1090+
1091+
stream_info_content = (
1092+
[('Stream settings', [])]
1093+
) # type: PopUpViewTableContent
10861094
popup_width, column_widths = self.calculate_table_widths(
10871095
stream_info_content, len(title))
10881096

@@ -1101,9 +1109,14 @@ def __init__(self, controller: Any, stream_id: int) -> None:
11011109
# Manual because calculate_table_widths does not support checkboxes.
11021110
# Add 4 to checkbox label to accomodate the checkbox itself.
11031111
popup_width = max(popup_width, len(muted_setting.label) + 4,
1104-
len(pinned_setting.label) + 4)
1112+
len(pinned_setting.label) + 4, desc.pack()[0])
11051113
self.widgets = self.make_table_with_categories(stream_info_content,
11061114
column_widths)
1115+
1116+
# Stream description.
1117+
self.widgets.insert(0, desc)
1118+
self.widgets.insert(1, urwid.Text('')) # Add a newline.
1119+
11071120
self.widgets.append(muted_setting)
11081121
self.widgets.append(pinned_setting)
11091122
super().__init__(controller, self.widgets, 'STREAM_DESC', popup_width,

0 commit comments

Comments
 (0)