"""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 def test_version_label_follows_light_and_dark(qapp): """It read its color from its own palette, which its stylesheet had pinned — so a launch in one mode left it unreadable in the other.""" from unittest.mock import MagicMock from lintunes import theme from lintunes.gui.version_button import VersionButton updater = MagicMock() updater.short_hash.return_value = "" button = VersionButton(updater) old = theme._mode try: for mode in ("dark", "light"): theme._mode = mode button.refresh_theme() color = theme.text_color() assert f"rgba({color.red()}, {color.green()}, {color.blue()}, 140)" \ in button.styleSheet() assert theme.text_color("dark") != theme.text_color("light") finally: theme._mode = old