Updated tests for more links per open link prompt

This commit is contained in:
woorst
2018-10-01 20:09:47 -04:00
parent ee9b231da0
commit 7d14494dcf
2 changed files with 13 additions and 14 deletions

View File

@@ -407,9 +407,6 @@ class Terminal(object):
while i < len(links) and len(link_page) < 10: while i < len(links) and len(link_page) < 10:
link_page.append(links[i]) link_page.append(links[i])
i += 1 i += 1
if i == len(links) - 1:
link_page.append(links[i])
i += 1
link_pages.append(link_page) link_pages.append(link_page)
return link_pages return link_pages

View File

@@ -710,13 +710,13 @@ def test_terminal_get_link_pages(terminal):
# A single link should generate a single page # A single link should generate a single page
assert terminal.get_link_pages([1]) == [[1]] assert terminal.get_link_pages([1]) == [[1]]
# Up to 9 links should fit on a single page # Up to 10 links should fit on a single page
link_pages = terminal.get_link_pages([1, 2, 3, 4, 5, 6, 7, 8, 9]) link_pages = terminal.get_link_pages([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
assert link_pages == [[1, 2, 3, 4, 5, 6, 7, 8, 9]] assert link_pages == [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
# When the 10th link is added, the 9th link should now wrap to a new page # When the 11th link is added a new page is created
link_pages = terminal.get_link_pages([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) link_pages = terminal.get_link_pages([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
assert link_pages == [[1, 2, 3, 4, 5, 6, 7, 8], [9, 10]] assert link_pages == [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [10]]
def test_terminal_get_link_page_text(terminal): def test_terminal_get_link_page_text(terminal):
@@ -732,9 +732,9 @@ def test_terminal_get_link_page_text(terminal):
text = terminal.get_link_page_text(link_page) text = terminal.get_link_page_text(link_page)
assert text == dedent("""\ assert text == dedent("""\
[1] [Reddit Homepage](https://www.reddit.com) [0] [Reddit Homepage](https://www.reddit.com)
[2] [Search Engine](https://www.duckduckgo.com) [1] [Search Engine](https://www.duckduckgo.com)
[3] [This project's home…](https://github.com/michael-lazar/rtv) [2] [This project's home…](https://github.com/michael-lazar/rtv)
""") """)
@@ -742,6 +742,7 @@ def test_terminal_prompt_user_to_select_link(terminal, stdscr):
# Select the 2nd link on the 2nd page # Select the 2nd link on the 2nd page
links = [ links = [
{'href': 'www.website-0.com', 'text': 'Website 0'},
{'href': 'www.website-1.com', 'text': 'Website 1'}, {'href': 'www.website-1.com', 'text': 'Website 1'},
{'href': 'www.website-2.com', 'text': 'Website 2'}, {'href': 'www.website-2.com', 'text': 'Website 2'},
{'href': 'www.website-3.com', 'text': 'Website 3'}, {'href': 'www.website-3.com', 'text': 'Website 3'},
@@ -755,12 +756,13 @@ def test_terminal_prompt_user_to_select_link(terminal, stdscr):
{'href': 'www.website-11.com', 'text': 'Website 11'}, {'href': 'www.website-11.com', 'text': 'Website 11'},
{'href': 'www.website-12.com', 'text': 'Website 12'}, {'href': 'www.website-12.com', 'text': 'Website 12'},
] ]
stdscr.getch.side_effect = [ord('9'), ord('2')] stdscr.getch.side_effect = [ord('j'), ord('2')]
href = terminal.prompt_user_to_select_link(links) href = terminal.prompt_user_to_select_link(links)
assert href == 'www.website-10.com' assert href == 'www.website-12.com'
# Select a link that doesn't exist # Select a link that doesn't exist
links = [ links = [
{'href': 'www.website-0.com', 'text': 'Website 0'},
{'href': 'www.website-1.com', 'text': 'Website 1'}, {'href': 'www.website-1.com', 'text': 'Website 1'},
{'href': 'www.website-2.com', 'text': 'Website 2'}, {'href': 'www.website-2.com', 'text': 'Website 2'},
] ]