emmental/tests/tracklist/test_selection.py

50 lines
1.8 KiB
Python

# Copyright 2023 (c) Anna Schumaker.
"""Tests our Tracklist Selection OSD."""
import emmental.buttons
import emmental.tracklist.selection
import tests.util
from gi.repository import Gtk
class TestOsd(tests.util.TestCase):
"""Test the Tracklist OSD."""
def setUp(self):
"""Set up common variables."""
super().setUp()
self.db_plist = self.sql.playlists.create("Test Playlist")
self.playlist = emmental.playlist.playlist.Playlist(self.sql,
self.db_plist)
self.model = Gtk.StringList.new(["Test", "OSD", "Strings"])
self.selection = Gtk.MultiSelection(model=self.model)
self.osd = emmental.tracklist.selection.OSD(self.selection)
def test_init(self):
"""Test that the OSD is set up properly."""
self.assertIsInstance(self.osd, Gtk.Overlay)
self.assertEqual(self.osd.selection, self.selection)
self.assertIsNone(self.osd.playlist)
def test_selection_properties(self):
"""Test updating properties when the selection changes."""
self.assertFalse(self.osd.have_selected)
self.assertEqual(self.osd.n_selected, 0)
self.selection.select_item(1, True)
self.assertTrue(self.osd.have_selected)
self.assertEqual(self.osd.n_selected, 1)
def test_clear_selection(self):
"""Test the clear_selection() function."""
self.selection.select_item(1, True)
self.osd.clear_selection()
self.assertEqual(self.selection.get_selection().get_size(), 0)
self.assertEqual(self.osd.n_selected, 0)
self.assertFalse(self.osd.have_selected)
self.osd.playlist = self.playlist
self.assertEqual(self.selection.get_selection().get_size(), 0)
self.assertEqual(self.osd.n_selected, 0)
self.assertFalse(self.osd.have_selected)