Added tests, minor refactoring

This commit is contained in:
Michael Lazar
2019-02-03 00:24:38 -05:00
parent e48e93aabf
commit 8042f3e1f0
5 changed files with 269 additions and 18 deletions

View File

@@ -149,7 +149,7 @@ class Content(object):
data['type'] = 'Comment'
data['level'] = comment.nested_level
data['body'] = comment.body
data['html'] = comment.body_html or ''
data['html'] = comment.body_html
data['created'] = cls.humanize_timestamp(comment.created_utc)
data['score'] = '{0} pts'.format(
'-' if comment.score_hidden else comment.score)

View File

@@ -312,19 +312,29 @@ class Page(object):
"""
data = self.get_selected_item()
url_full = data.get('url_full')
if url_full and url_full != data['permalink']:
permalink = data.get('permalink')
if url_full and url_full != permalink:
# The item is a link-only submission that won't contain text
link = data['url_full']
link = url_full
else:
extracted_links = self.content.extract_links(data.get('html', ''))
if not extracted_links:
# Only one selection to choose from, so just pick it
link = data.get('permalink')
html = data.get('html')
if html:
extracted_links = self.content.extract_links(html)
if not extracted_links:
# Only one selection to choose from, so just pick it
link = permalink
else:
# Let the user decide which link to open
links = []
if permalink:
links += [{'text': 'Permalink', 'href': permalink}]
links += extracted_links
link = self.term.prompt_user_to_select_link(links)
else:
# Let the user decide which link to open
links = [{'text': 'Permalink', 'href': data['permalink']}]
links += extracted_links
link = self.term.prompt_user_to_select_link(links)
# Some items like hidden comments don't have any HTML to parse
link = permalink
return link
@PageController.register(Command('COPY_PERMALINK'))

View File

@@ -143,16 +143,16 @@ class SubmissionPage(Page):
If there is more than one link contained in the item, prompt the user
to choose which link to open.
"""
link = self.prompt_and_select_link()
if link:
data = self.get_selected_item()
if data['type'] == 'Submission':
data = self.get_selected_item()
if data['type'] == 'Submission':
link = self.prompt_and_select_link()
if link:
self.config.history.add(link)
self.term.open_link(link)
elif data['type'] == 'Comment' and data['permalink']:
elif data['type'] == 'Comment':
link = self.prompt_and_select_link()
if link:
self.term.open_link(link)
else:
self.term.flash()
else:
self.term.flash()