144 lines
5.4 KiB
Python
144 lines
5.4 KiB
Python
# Copyright 2021 (c) Anna Schumaker.
|
|
import db
|
|
import scanner
|
|
import unittest
|
|
from gi.repository import Gtk
|
|
from . import view
|
|
from . import widgets
|
|
|
|
class TestLibraryButtons(unittest.TestCase):
|
|
def test_init(self):
|
|
library = db.library.Table.find("/a/b/c")
|
|
buttons = widgets.LibraryButtons(library)
|
|
self.assertIsInstance(buttons, Gtk.Box)
|
|
self.assertTrue(buttons.has_css_class("linked"))
|
|
|
|
child = buttons.get_first_child()
|
|
self.assertIsInstance(child, scanner.widgets.RemoveButton)
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, scanner.widgets.UpdateButton)
|
|
|
|
|
|
class TestLibraryPopover(unittest.TestCase):
|
|
def test_init(self):
|
|
library = db.library.Table.find("/a/b/c")
|
|
popover = widgets.LibraryPopover(library)
|
|
self.assertIsInstance(popover, Gtk.Popover)
|
|
|
|
box = popover.get_child()
|
|
self.assertIsInstance(box, Gtk.Box)
|
|
self.assertEqual(box.get_spacing(), 10)
|
|
|
|
child = box.get_first_child()
|
|
self.assertIsInstance(child, widgets.LibraryButtons)
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, scanner.widgets.EnableSwitch)
|
|
|
|
|
|
class TestProgressBar(unittest.TestCase):
|
|
def test_init(self):
|
|
pbar = widgets.ProgressBar()
|
|
self.assertIsInstance(pbar, Gtk.Box)
|
|
|
|
child = pbar.get_first_child()
|
|
self.assertIsInstance(child, Gtk.Label)
|
|
self.assertEqual(child.get_text(), " ")
|
|
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, scanner.widgets.ProgressBar)
|
|
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, Gtk.Label)
|
|
self.assertEqual(child.get_text(), " ")
|
|
|
|
|
|
class TestAddPlaylistEntry(unittest.TestCase):
|
|
def activated_playlist(self, entry, playlist):
|
|
self.playlist = playlist
|
|
|
|
def test_init(self):
|
|
entry = widgets.AddPlaylistEntry()
|
|
self.assertIsInstance(entry, Gtk.Entry)
|
|
self.assertEqual(entry.get_placeholder_text(), "Add new playlist")
|
|
self.assertEqual(entry.get_icon_name(Gtk.EntryIconPosition.PRIMARY),
|
|
"list-add")
|
|
|
|
def test_clear(self):
|
|
entry = widgets.AddPlaylistEntry()
|
|
self.assertIsNone(entry.get_icon_name(Gtk.EntryIconPosition.SECONDARY))
|
|
entry.set_text("Test")
|
|
self.assertEqual(entry.get_icon_name(Gtk.EntryIconPosition.SECONDARY),
|
|
"edit-clear-symbolic")
|
|
entry.icon_released(entry, Gtk.EntryIconPosition.SECONDARY)
|
|
self.assertEqual(entry.get_text(), "")
|
|
|
|
def test_activate(self):
|
|
entry = widgets.AddPlaylistEntry()
|
|
entry.connect("activated-playlist", self.activated_playlist)
|
|
entry.set_text("Test Playlist")
|
|
self.assertIsNone(db.user.Table.lookup("Test Playlist"))
|
|
|
|
entry.icon_released(entry, Gtk.EntryIconPosition.PRIMARY)
|
|
self.assertEqual(entry.get_text(), "")
|
|
self.assertEqual(self.playlist, db.user.Table.lookup("Test Playlist"))
|
|
self.assertIsNotNone(self.playlist)
|
|
|
|
entry.icon_released(entry, Gtk.EntryIconPosition.PRIMARY)
|
|
self.assertIsNone(db.user.Table.lookup(""))
|
|
|
|
|
|
class TestAddPlaylistPopover(unittest.TestCase):
|
|
def test_init(self):
|
|
popover = widgets.AddPlaylistPopover()
|
|
self.assertIsInstance(popover, Gtk.Popover)
|
|
self.assertIsInstance(popover.box, Gtk.Box)
|
|
self.assertEqual(popover.get_child(), popover.box)
|
|
self.assertEqual(popover.box.get_spacing(), 5)
|
|
self.assertEqual(popover.box.get_orientation(),
|
|
Gtk.Orientation.VERTICAL)
|
|
self.assertEqual(popover.box.get_focus_child(),
|
|
popover.box.get_last_child())
|
|
self.assertTrue(popover.has_css_class("normal-icons"))
|
|
|
|
def test_children(self):
|
|
popover = widgets.AddPlaylistPopover()
|
|
child = popover.box.get_first_child()
|
|
self.assertIsInstance(child, view.UserView)
|
|
self.assertEqual(child, popover.get_view())
|
|
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, widgets.AddPlaylistEntry)
|
|
self.assertEqual(child, popover.get_entry())
|
|
|
|
|
|
class TestAddPlaylistButton(unittest.TestCase):
|
|
def test_init(self):
|
|
add = widgets.AddPlaylistButton()
|
|
self.assertIsInstance(add, Gtk.MenuButton)
|
|
self.assertIsInstance(add.get_popover(), widgets.AddPlaylistPopover)
|
|
self.assertEqual(add.get_icon_name(), "list-add")
|
|
self.assertEqual(add.get_direction(), Gtk.ArrowType.UP)
|
|
|
|
|
|
class TestAddUpdateBox(unittest.TestCase):
|
|
def test_init(self):
|
|
box = widgets.AddUpdateBox()
|
|
self.assertIsInstance(box, Gtk.Box)
|
|
self.assertTrue(box.has_css_class("large-icons"))
|
|
self.assertTrue(box.has_css_class("linked"))
|
|
self.assertTrue(box.get_homogeneous())
|
|
|
|
self.assertEqual(box.get_margin_top(), 5)
|
|
self.assertEqual(box.get_margin_bottom(), 5)
|
|
self.assertEqual(box.get_margin_start(), 5)
|
|
self.assertEqual(box.get_margin_end(), 5)
|
|
|
|
def test_children(self):
|
|
box = widgets.AddUpdateBox()
|
|
child = box.get_first_child()
|
|
self.assertIsInstance(child, widgets.AddPlaylistButton)
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, scanner.widgets.AddFolderButton)
|
|
child = child.get_next_sibling()
|
|
self.assertIsInstance(child, scanner.widgets.UpdateAllButton)
|