Changed order-by shortcut to trigger on a single keystroke. #330

This commit is contained in:
Michael Lazar
2016-12-27 21:34:08 -08:00
parent ddf85ea727
commit e625beb638
4 changed files with 16 additions and 40 deletions

View File

@@ -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',

View File

@@ -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

View File

@@ -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):

View File

@@ -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):