Skip to content

Commit 9f8d739

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 cd2e864 commit 9f8d739

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

tests/ui/test_ui_tools.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ def test_keypress_navigation(self, mocker, stream_view,
461461
super_view.assert_called_once_with(size, expected_key)
462462

463463
@pytest.mark.parametrize('event, button, key', [
464-
('mouse press', 4, 'up'),
465-
('mouse press', 5, 'down'),
464+
('mouse press', 4, keys_for_command('GO_UP').pop()),
465+
('mouse press', 5, keys_for_command('GO_DOWN').pop()),
466466
])
467467
def test_mouse_event(self, mocker, stream_view, event, button, key):
468468
size = (200, 20)
@@ -652,6 +652,16 @@ def test_keypress_navigation(self, mocker, topic_view,
652652
topic_view.keypress(size, key)
653653
super_view.assert_called_once_with(size, expected_key)
654654

655+
@pytest.mark.parametrize('event, button, key', [
656+
('mouse press', 4, keys_for_command('GO_UP').pop()),
657+
('mouse press', 5, keys_for_command('GO_DOWN').pop()),
658+
])
659+
def test_mouse_event(self, mocker, topic_view, event, button, key):
660+
mocker.patch.object(topic_view, 'keypress')
661+
size = (200, 20)
662+
topic_view.mouse_event(size, event, button, 1, 1, 'WIDGET')
663+
topic_view.keypress.assert_called_with(size, key)
664+
655665

656666
class TestUsersView:
657667

@@ -669,8 +679,8 @@ def test_keypress_navigation(self, mocker, user_view,
669679
super_view.assert_called_once_with(size, expected_key)
670680

671681
@pytest.mark.parametrize('event, button, key', [
672-
('mouse press', 4, 'up'),
673-
('mouse press', 5, 'down'),
682+
('mouse press', 4, keys_for_command('GO_UP').pop()),
683+
('mouse press', 5, keys_for_command('GO_DOWN').pop()),
674684
])
675685
def test_mouse_event(self, mocker, user_view, event, button, key):
676686
mocker.patch.object(user_view, 'keypress')

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)