|
5 | 5 | from bs4 import BeautifulSoup |
6 | 6 | from urwid import AttrWrap, Columns, Padding, Text |
7 | 7 |
|
8 | | -from zulipterminal.config.keys import keys_for_command |
| 8 | +from zulipterminal.config.keys import is_command_key, keys_for_command |
9 | 9 | from zulipterminal.helper import powerset |
10 | 10 | from zulipterminal.ui_tools.boxes import MessageBox |
11 | 11 | from zulipterminal.ui_tools.buttons import ( |
12 | 12 | StreamButton, TopButton, TopicButton, UserButton, |
13 | 13 | ) |
14 | 14 | from zulipterminal.ui_tools.views import ( |
15 | 15 | HelpView, LeftColumnView, MessageView, MiddleColumnView, ModListWalker, |
16 | | - MsgInfoView, PopUpConfirmationView, RightColumnView, StreamsView, |
17 | | - TopicsView, UsersView, |
| 16 | + MsgInfoView, PopUpConfirmationView, PopUpView, RightColumnView, |
| 17 | + StreamsView, TopicsView, UsersView, |
18 | 18 | ) |
19 | 19 |
|
20 | 20 |
|
@@ -1093,6 +1093,56 @@ def test_topics_view(self, mocker, stream_button, width=40): |
1093 | 1093 | ]) |
1094 | 1094 |
|
1095 | 1095 |
|
| 1096 | +class TestPopUpView: |
| 1097 | + @pytest.fixture(autouse=True) |
| 1098 | + def pop_up_view(self, mocker): |
| 1099 | + self.controller = mocker.Mock() |
| 1100 | + self.command = 'COMMAND' |
| 1101 | + self.widget = mocker.Mock() |
| 1102 | + self.widgets = [self.widget, ] |
| 1103 | + self.list_walker = mocker.patch(VIEWS + '.urwid.SimpleFocusListWalker', |
| 1104 | + return_value=[]) |
| 1105 | + self.super_init = mocker.patch(VIEWS + '.urwid.ListBox.__init__') |
| 1106 | + self.super_keypress = mocker.patch(VIEWS + '.urwid.ListBox.keypress') |
| 1107 | + self.pop_up_view = PopUpView(self.controller, self.widgets, |
| 1108 | + self.command) |
| 1109 | + |
| 1110 | + def test_init(self): |
| 1111 | + assert self.pop_up_view.controller == self.controller |
| 1112 | + assert self.pop_up_view.command == self.command |
| 1113 | + self.list_walker.assert_called_once_with(self.widgets) |
| 1114 | + self.super_init.assert_called_once_with(self.pop_up_view.log) |
| 1115 | + |
| 1116 | + @pytest.mark.parametrize('key', keys_for_command('GO_BACK')) |
| 1117 | + def test_keypress_GO_BACK(self, key): |
| 1118 | + size = (200, 20) |
| 1119 | + self.pop_up_view.keypress(size, key) |
| 1120 | + assert self.controller.exit_popup.called |
| 1121 | + |
| 1122 | + def test_keypress_command_key(self, mocker): |
| 1123 | + size = (200, 20) |
| 1124 | + mocker.patch(VIEWS + '.is_command_key', side_effect=( |
| 1125 | + lambda command, key: command == self.command |
| 1126 | + )) |
| 1127 | + self.pop_up_view.keypress(size, 'cmd_key') |
| 1128 | + assert self.controller.exit_popup.called |
| 1129 | + |
| 1130 | + def test_keypress_navigation(self, mocker, |
| 1131 | + navigation_key_expected_key_pair): |
| 1132 | + key, expected_key = navigation_key_expected_key_pair |
| 1133 | + size = (200, 20) |
| 1134 | + # Patch `is_command_key` to not raise an 'Invalid Command' exception |
| 1135 | + # when its parameters are (self.command, key) as there is no |
| 1136 | + # self.command='COMMAND' command in keys.py. |
| 1137 | + mocker.patch(VIEWS + '.is_command_key', side_effect=( |
| 1138 | + lambda command, key: |
| 1139 | + False if command == self.command |
| 1140 | + else is_command_key(command, key) |
| 1141 | + )) |
| 1142 | + self.pop_up_view.keypress(size, key) |
| 1143 | + self.super_keypress.assert_called_once_with(size, expected_key) |
| 1144 | + |
| 1145 | + |
1096 | 1146 | class TestHelpMenu: |
1097 | 1147 | @pytest.fixture(autouse=True) |
1098 | 1148 | def mock_external_classes(self, mocker, monkeypatch): |
|
0 commit comments