Skip to content

Commit 6d11f72

Browse files
rsashankpreetmishraEzio-Sarthak
committed
core/views: Add SpoilerView class and corresponding show_* function.
This commit adds popup to show hidden spoiler content. Tests added. Co-authored-by: Preet Mishra <[email protected]> Co-authored-by: Ezio-Sarthak <[email protected]>
1 parent 555dfdd commit 6d11f72

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

tests/ui_tools/test_popups.py

Lines changed: 40 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,
@@ -952,6 +953,45 @@ def test_keypress_exit_popup(
952953
assert self.controller.exit_popup.called
953954

954955

956+
class TestSpoilerView:
957+
@pytest.fixture(autouse=True)
958+
def mock_external_classes(self, mocker: MockerFixture) -> None:
959+
self.controller = mocker.Mock()
960+
mocker.patch.object(
961+
self.controller, "maximum_popup_dimensions", return_value=(64, 64)
962+
)
963+
mocker.patch(MODULE + ".urwid.SimpleFocusListWalker", return_value=[])
964+
self.spoiler_view = SpoilerView(self.controller, "Spoiler View", "")
965+
966+
def test_keypress_any_key(
967+
self, widget_size: Callable[[Widget], urwid_Size]
968+
) -> None:
969+
key = "a"
970+
size = widget_size(self.spoiler_view)
971+
self.spoiler_view.keypress(size, key)
972+
assert not self.controller.exit_popup.called
973+
974+
@pytest.mark.parametrize("key", {*keys_for_command("EXIT_POPUP")})
975+
def test_keypress_exit_popup(
976+
self, key: str, widget_size: Callable[[Widget], urwid_Size]
977+
) -> None:
978+
size = widget_size(self.spoiler_view)
979+
self.spoiler_view.keypress(size, key)
980+
assert self.controller.exit_popup.called
981+
982+
def test_keypress_navigation(
983+
self,
984+
mocker: MockerFixture,
985+
widget_size: Callable[[Widget], urwid_Size],
986+
navigation_key_expected_key_pair: Tuple[str, str] = ("ENTER", "ENTER"),
987+
) -> None:
988+
key, expected_key = navigation_key_expected_key_pair
989+
size = widget_size(self.spoiler_view)
990+
super_keypress = mocker.patch(MODULE + ".urwid.ListBox.keypress")
991+
self.spoiler_view.keypress(size, key)
992+
super_keypress.assert_called_once_with(size, expected_key)
993+
994+
955995
class TestMsgInfoView:
956996
@pytest.fixture(autouse=True)
957997
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, "EXIT_POPUP", 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, "MSG_INFO", width, title)
1085+
1086+
10791087
class AboutView(PopUpView):
10801088
def __init__(
10811089
self,

0 commit comments

Comments
 (0)