2021-10-12 14:36:06 -04:00
|
|
|
# Copyright 2021 (c) Anna Schumaker.
|
2021-10-12 15:43:27 -04:00
|
|
|
import audio
|
2021-10-12 14:36:06 -04:00
|
|
|
import db
|
|
|
|
import lib
|
|
|
|
import unittest
|
|
|
|
from gi.repository import Gtk
|
2021-10-12 15:43:27 -04:00
|
|
|
from . import model
|
2021-10-12 14:36:06 -04:00
|
|
|
from . import stack
|
|
|
|
from . import view
|
2021-10-12 15:43:27 -04:00
|
|
|
from . import widgets
|
2021-10-12 14:36:06 -04:00
|
|
|
|
|
|
|
class TestStack(unittest.TestCase):
|
|
|
|
def playlist_changed(self, stack, playlist):
|
|
|
|
self.changed = playlist
|
|
|
|
|
|
|
|
def test_init(self):
|
|
|
|
s = stack.Stack()
|
|
|
|
self.assertIsInstance(s, Gtk.Stack)
|
|
|
|
self.assertTrue(s.get_vexpand())
|
|
|
|
self.assertEqual(s.get_transition_type(),
|
|
|
|
Gtk.StackTransitionType.OVER_UP_DOWN)
|
|
|
|
|
|
|
|
def test_pages(self):
|
|
|
|
s = stack.Stack()
|
|
|
|
|
|
|
|
child = s.get_child_by_name("Playlists")
|
|
|
|
self.assertIsInstance(child, view.TableWindow)
|
|
|
|
self.assertEqual(child.get_table(), db.user.Table)
|
|
|
|
self.assertEqual(s.get_page(child).get_icon_name(), "audio-x-generic")
|
|
|
|
|
|
|
|
child = s.get_child_by_name("Artists")
|
|
|
|
self.assertIsInstance(child, view.TableWindow)
|
|
|
|
self.assertEqual(child.get_table(), db.artist.Table)
|
|
|
|
self.assertEqual(s.get_page(child).get_icon_name(), "avatar-default-symbolic")
|
|
|
|
|
|
|
|
child = s.get_child_by_name("Genres")
|
|
|
|
self.assertIsInstance(child, view.TableWindow)
|
|
|
|
self.assertEqual(child.get_table(), db.genre.Table)
|
|
|
|
self.assertEqual(s.get_page(child).get_icon_name(), "emblem-generic")
|
|
|
|
|
|
|
|
child = s.get_child_by_name("Decades")
|
|
|
|
self.assertIsInstance(child, view.TableWindow)
|
|
|
|
self.assertEqual(child.get_table(), db.decade.Table)
|
|
|
|
self.assertEqual(s.get_page(child).get_icon_name(), "x-office-calendar")
|
|
|
|
|
|
|
|
child = s.get_child_by_name("Libraries")
|
|
|
|
self.assertIsInstance(child, view.TableWindow)
|
|
|
|
self.assertEqual(child.get_table(), db.library.Table)
|
|
|
|
self.assertEqual(s.get_page(child).get_icon_name(), "folder-music")
|
|
|
|
|
|
|
|
def test_change_page(self):
|
|
|
|
lib.settings.reset()
|
|
|
|
genre = db.genre.Table.find("Test Genre")
|
|
|
|
s = stack.Stack()
|
|
|
|
s.connect("playlist-changed", self.playlist_changed)
|
|
|
|
|
|
|
|
self.assertEqual(lib.settings.get("sidebar.page"), "Playlists")
|
|
|
|
self.assertEqual(s.get_visible_child_name(), "Playlists")
|
|
|
|
s.set_visible_child(s.get_child_by_name("Genres"))
|
|
|
|
self.assertEqual(lib.settings.get("sidebar.page"), "Genres")
|
|
|
|
self.assertEqual(self.changed, genre)
|
|
|
|
|
|
|
|
s2 = stack.Stack()
|
|
|
|
self.assertEqual(s2.get_visible_child_name(), "Genres")
|
|
|
|
|
|
|
|
def test_change_selected(self):
|
|
|
|
g1 = db.genre.Table.find("Test Genre")
|
|
|
|
g2 = db.genre.Table.find("Test Genre 2")
|
|
|
|
s = stack.Stack()
|
|
|
|
|
|
|
|
child = s.get_child_by_name("Genres")
|
|
|
|
s.set_visible_child(child)
|
|
|
|
s.connect("playlist-changed", self.playlist_changed)
|
|
|
|
|
|
|
|
child.get_selection().set_selected(1)
|
|
|
|
self.assertEqual(self.changed, g2)
|
|
|
|
child.get_selection().set_selected(0)
|
|
|
|
self.assertEqual(self.changed, g1)
|
2021-10-12 14:57:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TestSwitcher(unittest.TestCase):
|
|
|
|
def test_init(self):
|
|
|
|
switcher = stack.Switcher()
|
|
|
|
self.assertIsInstance(switcher, Gtk.StackSwitcher)
|
|
|
|
self.assertIsInstance(switcher.get_stack(), stack.Stack)
|
|
|
|
self.assertEqual(switcher.get_orientation(), Gtk.Orientation.VERTICAL)
|
|
|
|
self.assertTrue(switcher.has_css_class("large-icons"))
|
|
|
|
self.assertTrue(switcher.has_css_class("osd"))
|
2021-10-12 15:43:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TestBox(unittest.TestCase):
|
|
|
|
def test_init(self):
|
|
|
|
s = stack.Stack()
|
|
|
|
box = stack.Box(s)
|
|
|
|
self.assertIsInstance(box, Gtk.Box)
|
|
|
|
self.assertEqual(box.get_orientation(), Gtk.Orientation.VERTICAL)
|
|
|
|
|
|
|
|
child = box.get_first_child()
|
|
|
|
self.assertIsInstance(child, audio.artwork.Artwork)
|
|
|
|
|
|
|
|
child = child.get_next_sibling()
|
|
|
|
self.assertIsInstance(child, Gtk.Separator)
|
|
|
|
|
|
|
|
child = child.get_next_sibling()
|
|
|
|
self.assertIsInstance(child, lib.filter.Entry)
|
|
|
|
self.assertEqual(child.filter, model.TableFilter)
|
|
|
|
|
|
|
|
child = child.get_next_sibling()
|
|
|
|
self.assertIsInstance(child, Gtk.Separator)
|
|
|
|
|
|
|
|
child = child.get_next_sibling()
|
|
|
|
self.assertEqual(child, s)
|
|
|
|
|
|
|
|
child = child.get_next_sibling()
|
|
|
|
self.assertIsInstance(child, Gtk.Separator)
|
|
|
|
|
|
|
|
child = child.get_next_sibling()
|
|
|
|
self.assertIsInstance(child, widgets.AddUpdateBox)
|
2021-12-05 12:05:33 -05:00
|
|
|
self.assertEqual(box.get_add_update_button(), child.get_first_child())
|
2021-10-12 15:43:27 -04:00
|
|
|
|
|
|
|
child = child.get_next_sibling()
|
|
|
|
self.assertIsInstance(child, Gtk.Separator)
|
|
|
|
|
|
|
|
child = child.get_next_sibling()
|
|
|
|
self.assertIsInstance(child, widgets.ProgressBar)
|