Adding the search term to the title bar, removing with_search argument
This commit is contained in:
@@ -326,6 +326,7 @@ class SubmissionContent(Content):
|
||||
self.max_indent_level = max_indent_level
|
||||
self.name = submission_data['permalink']
|
||||
self.order = order
|
||||
self.query = None
|
||||
self._loader = loader
|
||||
self._submission = submission
|
||||
self._submission_data = submission_data
|
||||
@@ -662,6 +663,7 @@ class SubscriptionContent(Content):
|
||||
|
||||
self.name = name
|
||||
self.order = None
|
||||
self.query = None
|
||||
self._loader = loader
|
||||
self._subscriptions = subscriptions
|
||||
self._subscription_data = []
|
||||
|
||||
12
rtv/page.py
12
rtv/page.py
@@ -56,7 +56,7 @@ class Page(object):
|
||||
self._row = 0
|
||||
self._subwindows = None
|
||||
|
||||
def refresh_content(self, order=None, name=None, with_search=False):
|
||||
def refresh_content(self, order=None, name=None):
|
||||
raise NotImplementedError
|
||||
|
||||
def _draw_item(self, window, data, inverted):
|
||||
@@ -118,7 +118,7 @@ class Page(object):
|
||||
self.term.show_notification('Invalid option')
|
||||
return
|
||||
|
||||
self.refresh_content(order=choices[ch], with_search=True)
|
||||
self.refresh_content(order=choices[ch])
|
||||
|
||||
@PageController.register(Command('SORT_RISING'))
|
||||
def sort_content_rising(self):
|
||||
@@ -126,7 +126,7 @@ class Page(object):
|
||||
|
||||
@PageController.register(Command('SORT_NEW'))
|
||||
def sort_content_new(self):
|
||||
self.refresh_content(order='new', with_search=True)
|
||||
self.refresh_content(order='new')
|
||||
|
||||
@PageController.register(Command('SORT_CONTROVERSIAL'))
|
||||
def sort_content_controversial(self):
|
||||
@@ -147,7 +147,7 @@ class Page(object):
|
||||
self.term.show_notification('Invalid option')
|
||||
return
|
||||
|
||||
self.refresh_content(order=choices[ch], with_search=True)
|
||||
self.refresh_content(order=choices[ch])
|
||||
|
||||
@PageController.register(Command('MOVE_UP'))
|
||||
def move_cursor_up(self):
|
||||
@@ -408,6 +408,10 @@ class Page(object):
|
||||
sub_name = sub_name.replace('/r/front', 'Front Page')
|
||||
sub_name = sub_name.replace('/u/me', 'My Submissions')
|
||||
sub_name = sub_name.replace('/u/saved', 'My Saved Submissions')
|
||||
|
||||
query = self.content.query
|
||||
if query:
|
||||
sub_name = 'Searching {0}: {1}'.format(sub_name, query)
|
||||
self.term.add_line(window, sub_name, 0, 0)
|
||||
|
||||
# Set the terminal title
|
||||
|
||||
@@ -63,7 +63,7 @@ class SubmissionPage(Page):
|
||||
self.active = False
|
||||
|
||||
@SubmissionController.register(Command('REFRESH'))
|
||||
def refresh_content(self, order=None, name=None, with_search=False):
|
||||
def refresh_content(self, order=None, name=None):
|
||||
"Re-download comments and reset the page index"
|
||||
|
||||
order = order or self.content.order
|
||||
|
||||
@@ -36,12 +36,18 @@ class SubredditPage(Page):
|
||||
self.toggled_subreddit = None
|
||||
|
||||
@SubredditController.register(Command('REFRESH'))
|
||||
def refresh_content(self, order=None, name=None, with_search=False):
|
||||
def refresh_content(self, order=None, name=None):
|
||||
"Re-download all submissions and reset the page index"
|
||||
|
||||
order = order or self.content.order
|
||||
|
||||
# Preserve the query if staying on the current page
|
||||
if name is None:
|
||||
query = self.content.query
|
||||
else:
|
||||
query = None
|
||||
|
||||
name = name or self.content.name
|
||||
query = self.content.query if with_search else None
|
||||
|
||||
# Hack to allow an order specified in the name by prompt_subreddit() to
|
||||
# override the current default
|
||||
|
||||
@@ -28,7 +28,7 @@ class SubscriptionPage(Page):
|
||||
self.selected_subreddit = None
|
||||
|
||||
@SubscriptionController.register(Command('REFRESH'))
|
||||
def refresh_content(self, order=None, name=None, with_search=False):
|
||||
def refresh_content(self, order=None, name=None):
|
||||
"Re-download all subscriptions and reset the page index"
|
||||
|
||||
# reddit.get_my_subreddits() does not support sorting by order
|
||||
|
||||
@@ -59,7 +59,7 @@ class Terminal(object):
|
||||
self.loader = LoadScreen(self)
|
||||
self._display = None
|
||||
self._mailcap_dict = mailcap.getcaps()
|
||||
self._term = os.environ['TERM']
|
||||
self._term = os.environ.get('TERM')
|
||||
|
||||
@property
|
||||
def up_arrow(self):
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -81,7 +81,7 @@ def test_page_unauthenticated(reddit, terminal, config, oauth):
|
||||
page.controller.trigger('3')
|
||||
page.refresh_content.assert_called_with(order='rising')
|
||||
page.controller.trigger('4')
|
||||
page.refresh_content.assert_called_with(order='new', with_search=True)
|
||||
page.refresh_content.assert_called_with(order='new')
|
||||
|
||||
logged_in_methods = [
|
||||
'a', # Upvote
|
||||
|
||||
@@ -87,6 +87,7 @@ def test_subreddit_title(subreddit_page, terminal, capsys):
|
||||
|
||||
|
||||
def test_subreddit_search(subreddit_page, terminal):
|
||||
window = terminal.stdscr.subwin
|
||||
|
||||
# Search the current subreddit
|
||||
with mock.patch.object(terminal, 'prompt_input'):
|
||||
@@ -96,12 +97,31 @@ def test_subreddit_search(subreddit_page, terminal):
|
||||
assert terminal.prompt_input.called
|
||||
assert not terminal.loader.exception
|
||||
|
||||
# The page title should display the query
|
||||
subreddit_page.draw()
|
||||
title = 'Searching /r/python: search term'.encode('utf-8')
|
||||
window.addstr.assert_any_call(0, 0, title)
|
||||
|
||||
# Ordering the results should preserve the query
|
||||
window.addstr.reset_mock()
|
||||
subreddit_page.refresh_content(order='hot')
|
||||
subreddit_page.refresh_content(order='top-all')
|
||||
subreddit_page.refresh_content(order='new')
|
||||
assert subreddit_page.content.name == '/r/python'
|
||||
assert subreddit_page.content.query == 'search term'
|
||||
assert not terminal.loader.exception
|
||||
|
||||
# Searching with an empty query shouldn't crash
|
||||
with mock.patch.object(terminal, 'prompt_input'):
|
||||
terminal.prompt_input.return_value = None
|
||||
subreddit_page.controller.trigger('f')
|
||||
assert not terminal.loader.exception
|
||||
|
||||
# Changing to a new subreddit should clear the query
|
||||
window.addstr.reset_mock()
|
||||
subreddit_page.refresh_content(name='/r/learnpython')
|
||||
assert subreddit_page.content.query is None
|
||||
|
||||
|
||||
def test_subreddit_prompt(subreddit_page, terminal):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user