149 lines
6.2 KiB
Python
149 lines
6.2 KiB
Python
# Copyright 2022 (c) Anna Schumaker.
|
|
"""Tests our playback controls."""
|
|
import unittest
|
|
import unittest.mock
|
|
import emmental.nowplaying.controls
|
|
from gi.repository import Gtk
|
|
|
|
|
|
class TestButtons(unittest.TestCase):
|
|
"""Test the Control Buttons."""
|
|
|
|
def test_pill(self):
|
|
"""Test that the pill button is configured correctly."""
|
|
button = emmental.nowplaying.controls.PillButton()
|
|
self.assertIsInstance(button, emmental.buttons.Button)
|
|
self.assertEqual(button.icon_size, Gtk.IconSize.LARGE)
|
|
self.assertTrue(button.has_css_class("pill"))
|
|
|
|
|
|
class TestControls(unittest.TestCase):
|
|
"""Tests the Controls widget."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.controls = emmental.nowplaying.controls.Controls()
|
|
self.clicked = unittest.mock.Mock()
|
|
|
|
def test_constants(self):
|
|
"""Test constant values."""
|
|
self.assertEqual(emmental.nowplaying.controls.MARGIN, 24)
|
|
|
|
def test_init(self):
|
|
"""Test that controls were initialized properly."""
|
|
self.assertIsInstance(self.controls, Gtk.Box)
|
|
self.assertEqual(self.controls.get_orientation(),
|
|
Gtk.Orientation.HORIZONTAL)
|
|
self.assertEqual(self.controls.get_valign(), Gtk.Align.START)
|
|
self.assertTrue(self.controls.get_homogeneous())
|
|
self.assertTrue(self.controls.has_css_class("linked"))
|
|
|
|
self.assertEqual(self.controls.get_margin_top(),
|
|
emmental.nowplaying.controls.MARGIN)
|
|
self.assertEqual(self.controls.get_margin_bottom(),
|
|
emmental.nowplaying.controls.MARGIN)
|
|
self.assertEqual(self.controls.get_margin_start(),
|
|
emmental.nowplaying.controls.MARGIN / 2)
|
|
self.assertEqual(self.controls.get_margin_end(),
|
|
emmental.nowplaying.controls.MARGIN)
|
|
|
|
def test_previous_button(self):
|
|
"""Test the previous button."""
|
|
self.assertIsInstance(self.controls._prev,
|
|
emmental.nowplaying.controls.PillButton)
|
|
self.assertEqual(self.controls._prev.get_tooltip_text(),
|
|
"previous track")
|
|
self.assertEqual(self.controls._prev.icon_name, "media-skip-backward")
|
|
self.assertEqual(self.controls.get_first_child(), self.controls._prev)
|
|
|
|
self.controls._prev.connect("clicked", self.clicked)
|
|
self.controls._prev.emit("clicked")
|
|
self.clicked.assert_called_with(self.controls._prev)
|
|
|
|
def test_play_button(self):
|
|
"""Test the play button."""
|
|
self.assertIsInstance(self.controls._play,
|
|
emmental.nowplaying.controls.PillButton)
|
|
self.assertEqual(self.controls._play.get_tooltip_text(), "play")
|
|
self.assertEqual(self.controls._play.icon_name, "play-large")
|
|
self.assertEqual(self.controls._prev.get_next_sibling(),
|
|
self.controls._play)
|
|
|
|
self.assertFalse(self.controls.playing)
|
|
self.assertTrue(self.controls._play.get_visible())
|
|
self.controls.playing = True
|
|
self.assertFalse(self.controls._play.get_visible())
|
|
self.controls.playing = False
|
|
self.assertTrue(self.controls._play.get_visible())
|
|
|
|
self.controls._play.connect("clicked", self.clicked)
|
|
self.controls._play.emit("clicked")
|
|
self.clicked.assert_called_with(self.controls._play)
|
|
|
|
def test_pause_button(self):
|
|
"""Test the pause button."""
|
|
self.assertIsInstance(self.controls._pause,
|
|
emmental.buttons.SplitButton)
|
|
self.assertEqual(self.controls._pause.get_tooltip_text(), "pause")
|
|
self.assertEqual(self.controls._pause.icon_name, "pause-large")
|
|
self.assertEqual(self.controls._pause.icon_size,
|
|
Gtk.IconSize.LARGE)
|
|
self.assertEqual(self.controls._play.get_next_sibling(),
|
|
self.controls._pause)
|
|
|
|
self.assertFalse(self.controls._pause.get_visible())
|
|
self.controls.playing = True
|
|
self.assertTrue(self.controls._pause.get_visible())
|
|
self.controls.playing = False
|
|
self.assertFalse(self.controls._pause.get_visible())
|
|
|
|
self.controls._pause.connect("clicked", self.clicked)
|
|
self.controls._pause.emit("clicked")
|
|
self.clicked.assert_called_with(self.controls._pause)
|
|
|
|
def test_autopause_button(self):
|
|
"""Test the autopause button."""
|
|
self.assertIsInstance(self.controls._autopause,
|
|
emmental.nowplaying.autopause.Button)
|
|
self.assertEqual(self.controls._pause.secondary,
|
|
self.controls._autopause)
|
|
self.assertEqual(self.controls.autopause, -1)
|
|
|
|
self.controls._autopause.value = 42
|
|
self.assertEqual(self.controls.autopause, 42)
|
|
self.controls.autopause = 21
|
|
self.assertEqual(self.controls._autopause.value, 21)
|
|
self.controls.playing = False
|
|
self.assertEqual(self.controls.autopause, -1)
|
|
|
|
def test_next_button(self):
|
|
"""Test the next button."""
|
|
self.assertIsInstance(self.controls._next,
|
|
emmental.nowplaying.controls.PillButton)
|
|
self.assertEqual(self.controls._next.get_tooltip_text(), "next track")
|
|
self.assertEqual(self.controls._next.icon_name, "media-skip-forward")
|
|
|
|
self.controls._next.connect("clicked", self.clicked)
|
|
self.controls._next.emit("clicked")
|
|
self.clicked.assert_called_with(self.controls._next)
|
|
|
|
def test_have_properties(self):
|
|
"""Test the have_{next, previous, track} properties."""
|
|
self.assertFalse(self.controls.have_next)
|
|
self.assertFalse(self.controls.have_previous)
|
|
self.assertFalse(self.controls.have_track)
|
|
|
|
for button in [self.controls._next, self.controls._prev,
|
|
self.controls._play, self.controls._pause]:
|
|
self.assertFalse(button.get_sensitive())
|
|
|
|
self.controls.have_next = True
|
|
self.assertTrue(self.controls._next.get_sensitive())
|
|
|
|
self.controls.have_previous = True
|
|
self.assertTrue(self.controls._prev.get_sensitive())
|
|
|
|
self.controls.have_track = True
|
|
self.assertTrue(self.controls._play.get_sensitive())
|
|
self.assertTrue(self.controls._pause.get_sensitive())
|