112 lines
4.1 KiB
Python
112 lines
4.1 KiB
Python
"""Round 110: the now-playing panel is a Go to Current Song button."""
|
|
from PyQt6.QtCore import QEvent, QPointF, Qt
|
|
from PyQt6.QtGui import QEnterEvent, QMouseEvent
|
|
|
|
from lintunes.gui.transport import NowPlayingPanel
|
|
|
|
|
|
def _mouse(kind, x=5, y=5):
|
|
return QMouseEvent(kind, QPointF(x, y), QPointF(x, y),
|
|
Qt.MouseButton.LeftButton,
|
|
Qt.MouseButton.LeftButton if kind != QEvent.Type.MouseButtonRelease
|
|
else Qt.MouseButton.NoButton,
|
|
Qt.KeyboardModifier.NoModifier)
|
|
|
|
|
|
def _enter(panel):
|
|
panel.enterEvent(QEnterEvent(QPointF(5, 5), QPointF(5, 5), QPointF(5, 5)))
|
|
|
|
|
|
def test_hover_embosses_and_a_click_goes_to_the_song(qapp):
|
|
panel = NowPlayingPanel()
|
|
panel.resize(200, 60)
|
|
clicks = []
|
|
panel.clicked.connect(lambda: clicks.append(1))
|
|
panel.set_clickable(True)
|
|
assert not panel.property("face")
|
|
_enter(panel)
|
|
assert panel.property("face") == "hover"
|
|
panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress))
|
|
assert panel.property("face") == "down"
|
|
panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease))
|
|
assert clicks == [1] and panel.property("face") == "hover"
|
|
panel.leaveEvent(QEvent(QEvent.Type.Leave))
|
|
assert not panel.property("face")
|
|
|
|
|
|
def test_released_outside_is_no_click(qapp):
|
|
panel = NowPlayingPanel()
|
|
panel.resize(200, 60)
|
|
clicks = []
|
|
panel.clicked.connect(lambda: clicks.append(1))
|
|
panel.set_clickable(True)
|
|
_enter(panel)
|
|
panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress))
|
|
panel.mouseMoveEvent(_mouse(QEvent.Type.MouseMove, 400, 5))
|
|
assert not panel.property("face")
|
|
panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease, 400, 5))
|
|
assert clicks == []
|
|
|
|
|
|
def test_nothing_playing_is_just_a_panel(qapp):
|
|
panel = NowPlayingPanel()
|
|
clicks = []
|
|
panel.clicked.connect(lambda: clicks.append(1))
|
|
_enter(panel)
|
|
panel.mousePressEvent(_mouse(QEvent.Type.MouseButtonPress))
|
|
panel.mouseReleaseEvent(_mouse(QEvent.Type.MouseButtonRelease))
|
|
assert clicks == [] and not panel.property("face")
|
|
|
|
|
|
def test_window_wires_it_to_go_to_current_song(qapp, tmp_path, monkeypatch):
|
|
from lintunes.gui.main_window import MainWindow
|
|
from lintunes.library_manager import LibraryManager
|
|
from lintunes.models.library import Library
|
|
from lintunes.models.track import Track
|
|
from lintunes.preferences import Preferences
|
|
library = Library()
|
|
library.tracks[1] = Track(track_id=1, name="Song", artist="A")
|
|
manager = LibraryManager(library, tmp_path / "data")
|
|
went = []
|
|
monkeypatch.setattr(MainWindow, "_go_to_current_song",
|
|
lambda self: went.append(1))
|
|
window = MainWindow(manager, Preferences(tmp_path / "data"))
|
|
try:
|
|
window._transport.now_playing_clicked.emit()
|
|
assert went == [1]
|
|
panel = window._transport._now_playing
|
|
window._transport._on_track_changed(library.tracks[1])
|
|
assert panel._clickable
|
|
window._transport.set_dj_mode(True)
|
|
assert not panel._clickable
|
|
window._transport.set_dj_mode(False)
|
|
assert panel._clickable
|
|
finally:
|
|
window.close()
|
|
|
|
|
|
def test_version_button_shows_a_face_on_hover_only_once_an_update_is_ready(qapp):
|
|
from PyQt6.QtCore import QObject, pyqtSignal
|
|
from lintunes.gui.version_button import VersionButton
|
|
|
|
class Updater(QObject):
|
|
update_available = pyqtSignal(int)
|
|
update_failed = pyqtSignal(str)
|
|
|
|
def short_hash(self):
|
|
return ""
|
|
|
|
button = VersionButton(Updater())
|
|
assert ":hover" not in button.styleSheet() # an inert readout
|
|
button._on_update_available(3)
|
|
assert ":hover" in button.styleSheet() and ":pressed" in button.styleSheet()
|
|
button.refresh_theme() # a theme switch keeps it
|
|
assert ":hover" in button.styleSheet()
|
|
|
|
|
|
def test_cancel_transfer_is_always_a_button(qapp):
|
|
from lintunes.gui.main_window import _CancelSyncButton
|
|
button = _CancelSyncButton()
|
|
assert not button.isFlat()
|
|
assert "border: none" not in button.styleSheet()
|