import json from logitech_battery_widget.config import AppConfig, ConfigStore def test_config_round_trip(tmp_path): path = tmp_path / "config.json" store = ConfigStore(path) expected = AppConfig(theme="dark", always_on_top=True, window_x=12, window_y=34) store.save(expected) assert store.load() == expected assert json.loads(path.read_text(encoding="utf-8"))["theme"] == "dark" def test_invalid_config_uses_safe_values(tmp_path): path = tmp_path / "config.json" path.write_text('{"theme": "purple", "refresh_interval_seconds": 1}', encoding="utf-8") loaded = ConfigStore(path).load() assert loaded.theme == "system" assert loaded.refresh_interval_seconds == 15 def test_broken_json_returns_defaults(tmp_path): path = tmp_path / "config.json" path.write_text("not json", encoding="utf-8") assert ConfigStore(path).load() == AppConfig()