Merge pull request #441 from michael-lazar/controversial_comment_sort
Controversial comment sort
This commit is contained in:
41
rtv/page.py
41
rtv/page.py
@@ -99,47 +99,6 @@ class Page(object):
|
||||
def show_help(self):
|
||||
self.term.open_pager(docs.HELP.strip())
|
||||
|
||||
@PageController.register(Command('SORT_HOT'))
|
||||
def sort_content_hot(self):
|
||||
if self.content.query:
|
||||
self.refresh_content(order='relevance')
|
||||
else:
|
||||
self.refresh_content(order='hot')
|
||||
|
||||
@PageController.register(Command('SORT_TOP'))
|
||||
def sort_content_top(self):
|
||||
order = self._prompt_period('top')
|
||||
if order is None:
|
||||
self.term.show_notification('Invalid option')
|
||||
else:
|
||||
self.refresh_content(order=order)
|
||||
|
||||
@PageController.register(Command('SORT_RISING'))
|
||||
def sort_content_rising(self):
|
||||
if self.content.query:
|
||||
order = self._prompt_period('comments')
|
||||
if order is None:
|
||||
self.term.show_notification('Invalid option')
|
||||
else:
|
||||
self.refresh_content(order=order)
|
||||
else:
|
||||
self.refresh_content(order='rising')
|
||||
|
||||
@PageController.register(Command('SORT_NEW'))
|
||||
def sort_content_new(self):
|
||||
self.refresh_content(order='new')
|
||||
|
||||
@PageController.register(Command('SORT_CONTROVERSIAL'))
|
||||
def sort_content_controversial(self):
|
||||
if self.content.query:
|
||||
self.term.flash()
|
||||
else:
|
||||
order = self._prompt_period('controversial')
|
||||
if order is None:
|
||||
self.term.show_notification('Invalid option')
|
||||
else:
|
||||
self.refresh_content(order=order)
|
||||
|
||||
@PageController.register(Command('MOVE_UP'))
|
||||
def move_cursor_up(self):
|
||||
self._move_cursor(-1)
|
||||
|
||||
@@ -36,6 +36,26 @@ class SubmissionPage(Page):
|
||||
self.nav = Navigator(self.content.get, page_index=-1)
|
||||
self.selected_subreddit = None
|
||||
|
||||
@SubmissionController.register(Command('SORT_HOT'))
|
||||
def sort_content_hot(self):
|
||||
self.refresh_content(order='hot')
|
||||
|
||||
@SubmissionController.register(Command('SORT_TOP'))
|
||||
def sort_content_top(self):
|
||||
self.refresh_content(order='top')
|
||||
|
||||
@SubmissionController.register(Command('SORT_RISING'))
|
||||
def sort_content_rising(self):
|
||||
self.refresh_content(order='rising')
|
||||
|
||||
@SubmissionController.register(Command('SORT_NEW'))
|
||||
def sort_content_new(self):
|
||||
self.refresh_content(order='new')
|
||||
|
||||
@SubmissionController.register(Command('SORT_CONTROVERSIAL'))
|
||||
def sort_content_controversial(self):
|
||||
self.refresh_content(order='controversial')
|
||||
|
||||
@SubmissionController.register(Command('SUBMISSION_TOGGLE_COMMENT'))
|
||||
def toggle_comment(self):
|
||||
"""
|
||||
|
||||
@@ -60,6 +60,47 @@ class SubredditPage(Page):
|
||||
if not self.term.loader.exception:
|
||||
self.nav = Navigator(self.content.get)
|
||||
|
||||
@SubredditController.register(Command('SORT_HOT'))
|
||||
def sort_content_hot(self):
|
||||
if self.content.query:
|
||||
self.refresh_content(order='relevance')
|
||||
else:
|
||||
self.refresh_content(order='hot')
|
||||
|
||||
@SubredditController.register(Command('SORT_TOP'))
|
||||
def sort_content_top(self):
|
||||
order = self._prompt_period('top')
|
||||
if order is None:
|
||||
self.term.show_notification('Invalid option')
|
||||
else:
|
||||
self.refresh_content(order=order)
|
||||
|
||||
@SubredditController.register(Command('SORT_RISING'))
|
||||
def sort_content_rising(self):
|
||||
if self.content.query:
|
||||
order = self._prompt_period('comments')
|
||||
if order is None:
|
||||
self.term.show_notification('Invalid option')
|
||||
else:
|
||||
self.refresh_content(order=order)
|
||||
else:
|
||||
self.refresh_content(order='rising')
|
||||
|
||||
@SubredditController.register(Command('SORT_NEW'))
|
||||
def sort_content_new(self):
|
||||
self.refresh_content(order='new')
|
||||
|
||||
@SubredditController.register(Command('SORT_CONTROVERSIAL'))
|
||||
def sort_content_controversial(self):
|
||||
if self.content.query:
|
||||
self.term.flash()
|
||||
else:
|
||||
order = self._prompt_period('controversial')
|
||||
if order is None:
|
||||
self.term.show_notification('Invalid option')
|
||||
else:
|
||||
self.refresh_content(order=order)
|
||||
|
||||
@SubredditController.register(Command('SUBREDDIT_SEARCH'))
|
||||
def search_subreddit(self, name=None):
|
||||
"""
|
||||
|
||||
1132
tests/cassettes/test_submission_order.yaml
Normal file
1132
tests/cassettes/test_submission_order.yaml
Normal file
File diff suppressed because it is too large
Load Diff
2266
tests/cassettes/test_subreddit_order.yaml
Normal file
2266
tests/cassettes/test_subreddit_order.yaml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -75,22 +75,6 @@ def test_page_unauthenticated(reddit, terminal, config, oauth):
|
||||
page.controller.trigger('?')
|
||||
assert Popen.called
|
||||
|
||||
# Sort content - normal page
|
||||
page.content.query = ''
|
||||
page.controller.trigger('1')
|
||||
page.refresh_content.assert_called_with(order='hot')
|
||||
page.controller.trigger('3')
|
||||
page.refresh_content.assert_called_with(order='rising')
|
||||
page.controller.trigger('4')
|
||||
page.refresh_content.assert_called_with(order='new')
|
||||
|
||||
# Sort content - search results
|
||||
page.content.query = 'search text'
|
||||
page.controller.trigger('1')
|
||||
page.refresh_content.assert_called_with(order='relevance')
|
||||
page.controller.trigger('4')
|
||||
page.refresh_content.assert_called_with(order='new')
|
||||
|
||||
logged_in_methods = [
|
||||
'a', # Upvote
|
||||
'z', # Downvote
|
||||
|
||||
@@ -173,38 +173,18 @@ def test_submission_prompt_submission(submission_page, terminal, prompt):
|
||||
assert submission_page.content.order is None
|
||||
|
||||
|
||||
def test_submission_order_top(submission_page, terminal):
|
||||
def test_submission_order(submission_page):
|
||||
|
||||
# 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 is None
|
||||
|
||||
# Valid selection - sort by week
|
||||
terminal.show_notification.reset_mock()
|
||||
terminal.show_notification.return_value = ord('3')
|
||||
submission_page.controller.trigger('2')
|
||||
assert submission_page.content.order == 'top-week'
|
||||
|
||||
|
||||
def test_submission_order_controversial(submission_page, terminal):
|
||||
|
||||
# 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 is None
|
||||
|
||||
# Valid selection - sort by default
|
||||
terminal.show_notification.reset_mock()
|
||||
terminal.show_notification.return_value = ord('\n')
|
||||
submission_page.controller.trigger('5')
|
||||
assert submission_page.content.order == 'controversial'
|
||||
submission_page.controller.trigger('1')
|
||||
assert submission_page.content.order == 'hot'
|
||||
submission_page.controller.trigger('2')
|
||||
assert submission_page.content.order == 'top'
|
||||
submission_page.controller.trigger('3')
|
||||
assert submission_page.content.order == 'rising'
|
||||
submission_page.controller.trigger('4')
|
||||
assert submission_page.content.order == 'new'
|
||||
submission_page.controller.trigger('5')
|
||||
assert submission_page.content.order == 'controversial'
|
||||
|
||||
|
||||
def test_submission_move_top_bottom(submission_page):
|
||||
|
||||
@@ -185,6 +185,23 @@ def test_subreddit_prompt_submission_invalid(subreddit_page, terminal):
|
||||
assert isinstance(terminal.loader.exception, NotFound)
|
||||
|
||||
|
||||
def test_subreddit_order(subreddit_page):
|
||||
|
||||
subreddit_page.content.query = ''
|
||||
subreddit_page.controller.trigger('1')
|
||||
assert subreddit_page.content.order == 'hot'
|
||||
subreddit_page.controller.trigger('3')
|
||||
assert subreddit_page.content.order == 'rising'
|
||||
subreddit_page.controller.trigger('4')
|
||||
assert subreddit_page.content.order == 'new'
|
||||
|
||||
subreddit_page.content.query = 'search text'
|
||||
subreddit_page.controller.trigger('1')
|
||||
assert subreddit_page.content.order == 'relevance'
|
||||
subreddit_page.controller.trigger('4')
|
||||
assert subreddit_page.content.order == 'new'
|
||||
|
||||
|
||||
def test_subreddit_order_top(subreddit_page, terminal):
|
||||
|
||||
# Sort by top
|
||||
|
||||
@@ -61,7 +61,7 @@ def test_subscription_page_construct(reddit, terminal, config, oauth,
|
||||
def test_subscription_refresh(subscription_page):
|
||||
|
||||
# Refresh content - invalid order
|
||||
subscription_page.controller.trigger('3')
|
||||
subscription_page.refresh_content(order='top')
|
||||
assert curses.flash.called
|
||||
curses.flash.reset_mock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user