Skip to content

Commit 0060d6e

Browse files
committed
views: Migrate mouse_event to use keys_for_command.
The migration helps in using keys_for_command in the test as well. Tests amended for Streams/UsersView and added for TopicsView.
1 parent 52426e4 commit 0060d6e

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

tests/ui/test_ui_tools.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,10 @@ def test_keypress_navigation(self, mocker, stream_view,
477477
stream_view.keypress(size, key)
478478
super_view.assert_called_once_with(size, expected_key)
479479

480-
@pytest.mark.parametrize('button, key', [
481-
(4, 'up'),
482-
(5, 'down'),
483-
],
484-
ids=['scroll_wheel_up', 'scroll_wheel_down']
485-
)
486-
def test_mouse_event(self, mocker, stream_view, button, key,
487-
size=(200, 20)):
480+
def test_mouse_event(self, mocker, stream_view,
481+
mouse_press_key_button_pair, size=(200, 20)):
482+
key, button = mouse_press_key_button_pair
483+
mocker.patch(VIEWS + '.keys_for_command', return_value=[key])
488484
mocker.patch.object(stream_view, 'keypress')
489485
stream_view.mouse_event(size, 'mouse press', button, 1, 1, 'WIDGET')
490486
stream_view.keypress.assert_called_once_with(size, key)
@@ -671,6 +667,14 @@ def test_keypress_navigation(self, mocker, topic_view,
671667
topic_view.keypress(size, key)
672668
super_view.assert_called_once_with(size, expected_key)
673669

670+
def test_mouse_event(self, mocker, topic_view, mouse_press_key_button_pair,
671+
size=(200, 20)):
672+
key, button = mouse_press_key_button_pair
673+
mocker.patch(VIEWS + '.keys_for_command', return_value=[key])
674+
mocker.patch.object(topic_view, 'keypress')
675+
topic_view.mouse_event(size, 'mouse press', button, 1, 1, 'WIDGET')
676+
topic_view.keypress.assert_called_with(size, key)
677+
674678

675679
class TestUsersView:
676680

@@ -687,14 +691,10 @@ def test_keypress_navigation(self, mocker, user_view,
687691
user_view.keypress(size, key)
688692
super_view.assert_called_once_with(size, expected_key)
689693

690-
@pytest.mark.parametrize('button, key', [
691-
(4, 'up'),
692-
(5, 'down'),
693-
],
694-
ids=['scroll_wheel_up', 'scroll_wheel_down']
695-
)
696-
def test_mouse_event(self, mocker, user_view, button, key,
694+
def test_mouse_event(self, mocker, user_view, mouse_press_key_button_pair,
697695
size=(200, 20)):
696+
key, button = mouse_press_key_button_pair
697+
mocker.patch(VIEWS + '.keys_for_command', return_value=[key] * 5)
698698
mocker.patch.object(user_view, 'keypress')
699699
user_view.mouse_event(size, 'mouse press', button, 1, 1, 'WIDGET')
700700
user_view.keypress.assert_called_with(size, key)

zulipterminal/ui_tools/views.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ def mouse_event(self, size: urwid_Size, event: str, button: int, col: int,
284284
row: int, focus: bool) -> bool:
285285
if event == 'mouse press':
286286
if button == 4:
287-
self.keypress(size, 'up')
287+
self.keypress(size, keys_for_command('GO_UP').pop())
288288
return True
289289
elif button == 5:
290-
self.keypress(size, 'down')
290+
self.keypress(size, keys_for_command('GO_DOWN').pop())
291291
return True
292292
return super().mouse_event(size, event, button, col, row, focus)
293293

@@ -377,10 +377,10 @@ def mouse_event(self, size: urwid_Size, event: str, button: int, col: int,
377377
row: int, focus: bool) -> bool:
378378
if event == 'mouse press':
379379
if button == 4:
380-
self.keypress(size, 'up')
380+
self.keypress(size, keys_for_command('GO_UP').pop())
381381
return True
382382
elif button == 5:
383-
self.keypress(size, 'down')
383+
self.keypress(size, keys_for_command('GO_DOWN').pop())
384384
return True
385385
return super().mouse_event(size, event, button, col, row, focus)
386386

@@ -422,11 +422,11 @@ def mouse_event(self, size: urwid_Size, event: str, button: int, col: int,
422422
if event == 'mouse press':
423423
if button == 4:
424424
for _ in range(5):
425-
self.keypress(size, 'up')
425+
self.keypress(size, keys_for_command('GO_UP').pop())
426426
return True
427427
elif button == 5:
428428
for _ in range(5):
429-
self.keypress(size, 'down')
429+
self.keypress(size, keys_for_command('GO_DOWN').pop())
430430
return super().mouse_event(size, event, button, col, row, focus)
431431

432432
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:

0 commit comments

Comments
 (0)