Skip to content

Commit 72bd63f

Browse files
committed
core/views: Add SpoilerView class and corresponding show_* function.
1 parent 9edee49 commit 72bd63f

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

tests/ui_tools/test_popups.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
MsgInfoView,
2525
PopUpConfirmationView,
2626
PopUpView,
27+
SpoilerView,
2728
StreamInfoView,
2829
StreamMembersView,
2930
UserInfoView,
@@ -917,6 +918,47 @@ def test_keypress_exit_popup(
917918
assert self.controller.exit_popup.called
918919

919920

921+
class TestSpoilerView:
922+
@pytest.fixture(autouse=True)
923+
def mock_external_classes(self, mocker: MockerFixture) -> None:
924+
self.controller = mocker.Mock()
925+
mocker.patch.object(
926+
self.controller, "maximum_popup_dimensions", return_value=(64, 64)
927+
)
928+
mocker.patch(MODULE + ".urwid.SimpleFocusListWalker", return_value=[])
929+
self.spoiler_view = SpoilerView(self.controller, "Spoiler View", "")
930+
931+
def test_keypress_any_key(
932+
self, widget_size: Callable[[Widget], urwid_Size]
933+
) -> None:
934+
key = "a"
935+
size = widget_size(self.spoiler_view)
936+
self.spoiler_view.keypress(size, key)
937+
assert not self.controller.exit_popup.called
938+
939+
@pytest.mark.parametrize(
940+
"key", {*keys_for_command("GO_BACK"), *keys_for_command("ENTER")}
941+
)
942+
def test_keypress_exit_popup(
943+
self, key: str, widget_size: Callable[[Widget], urwid_Size]
944+
) -> None:
945+
size = widget_size(self.spoiler_view)
946+
self.spoiler_view.keypress(size, key)
947+
assert self.controller.exit_popup.called
948+
949+
def test_keypress_navigation(
950+
self,
951+
mocker: MockerFixture,
952+
widget_size: Callable[[Widget], urwid_Size],
953+
navigation_key_expected_key_pair: Tuple[str, str] = ("ENTER", "ENTER"),
954+
) -> None:
955+
key, expected_key = navigation_key_expected_key_pair
956+
size = widget_size(self.spoiler_view)
957+
super_keypress = mocker.patch(MODULE + ".urwid.ListBox.keypress")
958+
self.spoiler_view.keypress(size, key)
959+
super_keypress.assert_called_once_with(size, expected_key)
960+
961+
920962
class TestMsgInfoView:
921963
@pytest.fixture(autouse=True)
922964
def mock_external_classes(

zulipterminal/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
MsgInfoView,
4343
NoticeView,
4444
PopUpConfirmationView,
45+
SpoilerView,
4546
StreamInfoView,
4647
StreamMembersView,
4748
UserInfoView,
@@ -481,6 +482,11 @@ def report_warning(
481482
"""
482483
self.view.set_footer_text(text, "task:warning", duration)
483484

485+
def show_spoiler(self, content: str) -> None:
486+
self.show_pop_up(
487+
SpoilerView(self, "Spoiler (up/down scrolls)", content), "area:msg"
488+
)
489+
484490
def show_media_confirmation_popup(
485491
self, func: Any, tool: str, media_path: str
486492
) -> None:

zulipterminal/ui_tools/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,14 @@ def __init__(
10761076
super().__init__(controller, widgets, "GO_BACK", width, title)
10771077

10781078

1079+
class SpoilerView(PopUpView):
1080+
def __init__(self, controller: Any, title: str, content: str) -> None:
1081+
width, _ = controller.maximum_popup_dimensions()
1082+
widget = [urwid.Text(content)]
1083+
1084+
super().__init__(controller, widget, "ENTER", width, title)
1085+
1086+
10791087
class AboutView(PopUpView):
10801088
def __init__(
10811089
self,

0 commit comments

Comments
 (0)