feat: full implementation - switcher, device watcher, hotkeys, tray, settings UI
This commit is contained in:
67
tests/test_hotkey_manager.py
Normal file
67
tests/test_hotkey_manager.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
import pytest
|
||||
from config.config_manager import ConfigManager
|
||||
from core.hotkey_manager import HotkeyManager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config(tmp_path):
|
||||
return ConfigManager(tmp_path / "config.json")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def switcher():
|
||||
return MagicMock()
|
||||
|
||||
|
||||
def test_register_all_registers_profile_hotkeys(config, switcher):
|
||||
with patch("core.hotkey_manager.keyboard") as mock_kb:
|
||||
hm = HotkeyManager(config, switcher)
|
||||
hm.register_all()
|
||||
assert mock_kb.add_hotkey.call_count == 2
|
||||
calls = [c.args[0] for c in mock_kb.add_hotkey.call_args_list]
|
||||
assert "ctrl+alt+1" in calls
|
||||
assert "ctrl+alt+2" in calls
|
||||
|
||||
|
||||
def test_register_all_skips_empty_hotkeys(config, switcher):
|
||||
cfg = config.get()
|
||||
cfg["profiles"][0]["hotkey"] = ""
|
||||
config.update(cfg)
|
||||
|
||||
with patch("core.hotkey_manager.keyboard") as mock_kb:
|
||||
hm = HotkeyManager(config, switcher)
|
||||
hm.register_all()
|
||||
assert mock_kb.add_hotkey.call_count == 1
|
||||
|
||||
|
||||
def test_unregister_all_removes_hotkeys(config, switcher):
|
||||
with patch("core.hotkey_manager.keyboard") as mock_kb:
|
||||
hm = HotkeyManager(config, switcher)
|
||||
hm.register_all()
|
||||
hm.unregister_all()
|
||||
assert mock_kb.remove_hotkey.call_count == 2
|
||||
|
||||
|
||||
def test_register_all_clears_old_before_registering(config, switcher):
|
||||
with patch("core.hotkey_manager.keyboard") as mock_kb:
|
||||
hm = HotkeyManager(config, switcher)
|
||||
hm.register_all()
|
||||
hm.register_all()
|
||||
assert mock_kb.remove_hotkey.call_count == 2
|
||||
|
||||
|
||||
def test_hotkey_calls_apply_profile(config, switcher):
|
||||
captured_callbacks = {}
|
||||
|
||||
def fake_add_hotkey(hotkey, fn, args):
|
||||
captured_callbacks[hotkey] = (fn, args)
|
||||
|
||||
with patch("core.hotkey_manager.keyboard") as mock_kb:
|
||||
mock_kb.add_hotkey.side_effect = fake_add_hotkey
|
||||
hm = HotkeyManager(config, switcher)
|
||||
hm.register_all()
|
||||
|
||||
fn, args = captured_callbacks["ctrl+alt+1"]
|
||||
fn(*args)
|
||||
switcher.apply_profile.assert_called_once_with("pc1_dp")
|
||||
Reference in New Issue
Block a user