From e625beb638e2571ef93a80b86d5da3e6a55d99de Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Tue, 27 Dec 2016 21:34:08 -0800 Subject: [PATCH] Changed order-by shortcut to trigger on a single keystroke. #330 --- rtv/page.py | 10 ++-------- tests/test_page.py | 4 ---- tests/test_submission.py | 21 +++++++-------------- tests/test_subreddit.py | 21 +++++++-------------- 4 files changed, 16 insertions(+), 40 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index 7e784c2..d0cef8d 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -97,11 +97,8 @@ class Page(object): @PageController.register(Command('SORT_TOP')) def sort_content_top(self): - if not self.content.order or 'top' not in self.content.order: - self.refresh_content(order='top') - return - choices = { + '\n': 'top', '1': 'top-hour', '2': 'top-day', '3': 'top-week', @@ -129,11 +126,8 @@ class Page(object): @PageController.register(Command('SORT_CONTROVERSIAL')) def sort_content_controversial(self): - if not self.content.order or 'controversial' not in self.content.order: - self.refresh_content(order='controversial') - return - choices = { + '\n': 'controversial', '1': 'controversial-hour', '2': 'controversial-day', '3': 'controversial-week', diff --git a/tests/test_page.py b/tests/test_page.py index 8a4f9ce..44696b6 100644 --- a/tests/test_page.py +++ b/tests/test_page.py @@ -78,14 +78,10 @@ def test_page_unauthenticated(reddit, terminal, config, oauth): # Sort content page.controller.trigger('1') page.refresh_content.assert_called_with(order='hot') - page.controller.trigger('2') - page.refresh_content.assert_called_with(order='top') page.controller.trigger('3') page.refresh_content.assert_called_with(order='rising') page.controller.trigger('4') page.refresh_content.assert_called_with(order='new') - page.controller.trigger('5') - page.refresh_content.assert_called_with(order='controversial') logged_in_methods = [ 'a', # Upvote diff --git a/tests/test_submission.py b/tests/test_submission.py index eb98a8d..49976d9 100644 --- a/tests/test_submission.py +++ b/tests/test_submission.py @@ -146,17 +146,13 @@ def test_submission_prompt(submission_page, terminal): def test_submission_order_top(submission_page, terminal): - # Sort by top - First time selects default - submission_page.controller.trigger('2') - assert submission_page.content.order == 'top' - - # Second time opens the menu + # Open the menu with mock.patch.object(terminal, 'show_notification'): # Invalid selection terminal.show_notification.return_value = ord('x') submission_page.controller.trigger('2') terminal.show_notification.assert_called_with('Invalid option') - assert submission_page.content.order == 'top' + assert submission_page.content.order is None # Valid selection - sort by week terminal.show_notification.reset_mock() @@ -167,22 +163,19 @@ def test_submission_order_top(submission_page, terminal): def test_submission_order_controversial(submission_page, terminal): - # Now do controversial - submission_page.controller.trigger('5') - assert submission_page.content.order == 'controversial' - + # Open the menu with mock.patch.object(terminal, 'show_notification'): # Invalid selection terminal.show_notification.return_value = ord('x') submission_page.controller.trigger('5') terminal.show_notification.assert_called_with('Invalid option') - assert submission_page.content.order == 'controversial' + assert submission_page.content.order is None - # Valid selection - sort by week + # Valid selection - sort by default terminal.show_notification.reset_mock() - terminal.show_notification.return_value = ord('3') + terminal.show_notification.return_value = ord('\n') submission_page.controller.trigger('5') - assert submission_page.content.order == 'controversial-week' + assert submission_page.content.order == 'controversial' def test_submission_move_top_bottom(submission_page): diff --git a/tests/test_subreddit.py b/tests/test_subreddit.py index d1eb7f4..e3337bd 100644 --- a/tests/test_subreddit.py +++ b/tests/test_subreddit.py @@ -115,17 +115,13 @@ def test_subreddit_prompt(subreddit_page, terminal): def test_subreddit_order_top(subreddit_page, terminal): - # Sort by top - First time selects default - subreddit_page.controller.trigger('2') - assert subreddit_page.content.order == 'top' - - # Second time opens the menu + # Sort by top with mock.patch.object(terminal, 'show_notification'): # Invalid selection terminal.show_notification.return_value = ord('x') subreddit_page.controller.trigger('2') terminal.show_notification.assert_called_with('Invalid option') - assert subreddit_page.content.order == 'top' + assert subreddit_page.content.order is None # Valid selection - sort by week terminal.show_notification.reset_mock() @@ -136,22 +132,19 @@ def test_subreddit_order_top(subreddit_page, terminal): def test_subreddit_order_controversial(subreddit_page, terminal): - # Now do controversial - subreddit_page.controller.trigger('5') - assert subreddit_page.content.order == 'controversial' - + # Sort by controversial with mock.patch.object(terminal, 'show_notification'): # Invalid selection terminal.show_notification.return_value = ord('x') subreddit_page.controller.trigger('5') terminal.show_notification.assert_called_with('Invalid option') - assert subreddit_page.content.order == 'controversial' + assert subreddit_page.content.order is None - # Valid selection - sort by week + # Valid selection - sort by default terminal.show_notification.reset_mock() - terminal.show_notification.return_value = ord('3') + terminal.show_notification.return_value = ord('\n') subreddit_page.controller.trigger('5') - assert subreddit_page.content.order == 'controversial-week' + assert subreddit_page.content.order == 'controversial' def test_subreddit_open(subreddit_page, terminal, config):