import pytest from PySide6.QtCore import QSettings from mtga_assistant.ui.toggles import Toggles ITEMS = [("a", "A"), ("b", "B"), ("c", "C")] @pytest.fixture(autouse=True) def isolated_settings(tmp_path): QSettings.setPath(QSettings.Format.NativeFormat, QSettings.Scope.UserScope, str(tmp_path)) yield def test_default_order_and_visibility(): t = Toggles("g1", ITEMS, defaults_off={"b"}) assert t.order() == ["a", "b", "c"] assert not t.on("b") and t.on("a") def test_order_and_visibility_persist(): t = Toggles("g2", ITEMS) t.apply(["c", "a", "b"], {"a": False}) again = Toggles("g2", ITEMS) assert again.order() == ["c", "a", "b"] assert not again.on("a") and again.on("c") assert [k for k, _ in again.ordered_items()] == ["c", "a", "b"] def test_new_items_slot_in_after_their_default_neighbour(): Toggles("g3", ITEMS).apply(["c", "a", "b"], {}) grown = Toggles("g3", [("a", "A"), ("new", "New"), ("b", "B"), ("c", "C")]) assert grown.order() == ["c", "a", "new", "b"] def test_unknown_saved_keys_are_dropped_and_reset_restores_defaults(): t = Toggles("g4", ITEMS) t.apply(["gone", "b", "a", "c"], {"b": False}) assert t.order() == ["b", "a", "c"] t.reset() assert t.order() == ["a", "b", "c"] and t.on("b")