Skip to content

Commit

Permalink
minor menu logic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xgi committed Mar 18, 2019
1 parent 245df56 commit be3fc08
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
6 changes: 1 addition & 5 deletions castero/menus/episodemenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ def metadata(self):
if len(self._episodes) == 0:
return ""

episode = self._episodes[self._selected]
if episode is None:
return ""

return episode.metadata
return self._episodes[self._selected].metadata

def update_items(self, feed: Feed):
assert isinstance(feed, Feed) or feed is None
Expand Down
4 changes: 1 addition & 3 deletions castero/menus/feedmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ def update_items(self, obj):
def update_child(self):
if len(self._feeds) == 0:
self.update_items(None)
elif len(self._feeds) > 0:
self._child.update_items(self._feeds[self._selected])
else:
self._child.update_items(None)
self._child.update_items(self._feeds[self._selected])

def invert(self):
super().invert()
Expand Down
18 changes: 17 additions & 1 deletion tests/test_menu_episode.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def test_menu_episode_items(mock_A_NORMAL, mock_color_pair):
} in items


def test_menu_episode_item_none():
mymenu = EpisodeMenu(window, source)
assert mymenu.item() is None


@mock.patch('curses.color_pair')
@mock.patch('curses.A_NORMAL')
def test_menu_episode_item(mock_A_NORMAL, mock_color_pair):
Expand Down Expand Up @@ -70,9 +75,20 @@ def test_menu_episode_metadata(mock_A_NORMAL, mock_color_pair):
assert mymenu.metadata() == episode1.metadata


@mock.patch('curses.color_pair')
@mock.patch('curses.A_NORMAL')
def test_menu_episode_update_child(mock_A_NORMAL, mock_color_pair):
mymenu = EpisodeMenu(window, source)
mymenu.update_items(feed)
items = mymenu._items()
mymenu.update_child()
assert mymenu._items() == items


@mock.patch('curses.color_pair')
@mock.patch('curses.A_NORMAL')
def test_menu_episode_invert(mock_A_NORMAL, mock_color_pair):
mymenu = EpisodeMenu(window, source)
mymenu.invert()
assert mymenu._inverted
assert mymenu._inverted
mymenu.update_items(feed)

0 comments on commit be3fc08

Please sign in to comment.