Files
lintunes/tests/test_round105.py
T
trav 00c3ef7f66 v0.74.0: Sync Settings shares one selection with every friend by default, scrolls on a small screen, and searches playlists
- "Share the same selection with all friends" is on by default (a saved
  choice is kept)
- each page scrolls and the window opens no bigger than the screen; the
  General page with its selector held the window taller than a laptop
- a search box over the Playlists list (every word, case-folded, in the
  name, like the sidebar's); while either search is up, Select All /
  Select None reach only what it shows
2026-10-21 21:33:39 -07:00

93 lines
3.7 KiB
Python

"""Round 105: Sync Settings — "same for all friends" on by default, pages
that scroll on a small screen, and a playlist search in the share selector."""
from lintunes.cassette.state import CassetteState, Friend, Selection
from tests.test_round66 import _library
def test_same_for_all_is_on_by_default():
assert CassetteState().share_same_for_all
assert CassetteState.from_dict({}).share_same_for_all
# A choice already saved is kept.
saved = CassetteState(share_same_for_all=False).to_dict()
assert not CassetteState.from_dict(saved).share_same_for_all
def _selector(qapp, selection=None):
from lintunes.gui.share_selector import ShareSelector
return ShareSelector(_library(), selection or Selection())
def _shown_playlists(selector):
return [selector.playlists.item(r).text()
for r in range(selector.playlists.count())
if not selector.playlists.item(r).isHidden()]
class TestPlaylistSearch:
def test_every_word_case_folded(self, qapp):
selector = _selector(qapp)
assert _shown_playlists(selector) == ["Morning", "Road Trip"]
selector.playlist_search.setText("TRIP")
assert _shown_playlists(selector) == ["Road Trip"]
selector.playlist_search.setText("road morning")
assert _shown_playlists(selector) == []
selector.playlist_search.clear()
assert _shown_playlists(selector) == ["Morning", "Road Trip"]
def test_select_all_reaches_only_what_is_shown(self, qapp):
selection = Selection(playlist_ids={"P2"})
selector = _selector(qapp, selection)
selector.playlist_search.setText("road")
selector.pl_all.click()
assert selection.playlist_ids == {"P1", "P2"}
selector.pl_none.click()
assert selection.playlist_ids == {"P2"}
selector.playlist_search.clear()
selector.pl_none.click()
assert selection.playlist_ids == set()
class TestLibrarySearch:
def test_select_all_reaches_only_matching_songs(self, qapp):
selection = Selection(track_ids={1})
selector = _selector(qapp, selection)
selector.search.setText("marguerite")
selector.lib_all.click()
assert selection.track_ids == {1, 4, 5}
selector.lib_none.click()
assert selection.track_ids == {1}
selector.search.clear()
selector.lib_all.click()
assert selection.track_ids == {1, 2, 3, 4, 5}
class TestDialogFitsTheScreen:
def _dialog(self, tmp_path):
from lintunes.gui.sync_settings_dialog import SyncSettingsDialog
from tests.test_round64 import _NoProbe
state = CassetteState()
state.friends["a"] = Friend(token="a", device_id="A", name="Amy")
return SyncSettingsDialog(state, tmp_path, {}, probe=_NoProbe(),
library=_library())
def test_opens_no_bigger_than_the_screen(self, qapp, tmp_path):
dialog = self._dialog(tmp_path)
room = dialog.screen().availableGeometry()
assert dialog.width() <= room.width()
assert dialog.height() <= room.height()
def test_can_shrink_below_its_pages(self, qapp, tmp_path):
"""The General page with its selector is taller than a laptop screen;
it scrolls instead of holding the window open."""
dialog = self._dialog(tmp_path)
dialog._show_page(1)
assert dialog.general.selector is not None
assert dialog.minimumSizeHint().height() < 600
assert dialog.general.minimumSizeHint().height() > \
dialog.pages.minimumSizeHint().height()
def test_friend_page_still_gets_its_selector(self, qapp, tmp_path):
dialog = self._dialog(tmp_path)
dialog.pages_list.setCurrentRow(1)
assert dialog.friend_pages["a"].selector is not None