246 lines
8.1 KiB
Python
246 lines
8.1 KiB
Python
"""
|
|
Unit Tests - Window Manager
|
|
===========================
|
|
|
|
Tests for EU window detection, focus tracking, and overlay positioning.
|
|
"""
|
|
|
|
import pytest
|
|
import sys
|
|
from unittest.mock import Mock, patch, MagicMock
|
|
|
|
|
|
class TestWindowManager:
|
|
"""Test Window Manager functionality."""
|
|
|
|
def test_window_manager_singleton(self):
|
|
"""Test WindowManager is a singleton."""
|
|
from core.window_manager import WindowManager, get_window_manager
|
|
|
|
wm1 = get_window_manager()
|
|
wm2 = get_window_manager()
|
|
|
|
assert wm1 is wm2
|
|
|
|
def test_window_manager_initialization(self):
|
|
"""Test window manager initialization."""
|
|
from core.window_manager import WindowManager
|
|
|
|
wm = WindowManager()
|
|
|
|
assert wm._initialized is True
|
|
assert hasattr(wm, '_window_handle')
|
|
assert hasattr(wm, '_window_info')
|
|
|
|
def test_window_manager_availability_linux(self):
|
|
"""Test window manager availability on Linux."""
|
|
from core.window_manager import WindowManager
|
|
|
|
with patch.object(sys, 'platform', 'linux'):
|
|
wm = WindowManager()
|
|
assert wm.is_available() is False
|
|
|
|
@pytest.mark.skipif(sys.platform != 'win32', reason="Windows only")
|
|
def test_find_eu_window_not_running(self):
|
|
"""Test finding EU window when not running."""
|
|
from core.window_manager import get_window_manager
|
|
|
|
wm = get_window_manager()
|
|
|
|
# This will fail to find EU on systems without the game
|
|
window = wm.find_eu_window()
|
|
|
|
# Should return None or WindowInfo
|
|
assert window is None or hasattr(window, 'title')
|
|
|
|
def test_window_info_dataclass(self):
|
|
"""Test WindowInfo dataclass."""
|
|
from core.window_manager import WindowInfo
|
|
|
|
info = WindowInfo(
|
|
handle=12345,
|
|
title="Test Window",
|
|
pid=67890,
|
|
rect=(0, 0, 800, 600),
|
|
width=800,
|
|
height=600,
|
|
is_visible=True,
|
|
is_focused=False
|
|
)
|
|
|
|
assert info.handle == 12345
|
|
assert info.title == "Test Window"
|
|
assert info.width == 800
|
|
assert info.height == 600
|
|
|
|
def test_process_info_dataclass(self):
|
|
"""Test ProcessInfo dataclass."""
|
|
from core.window_manager import ProcessInfo
|
|
|
|
info = ProcessInfo(
|
|
pid=12345,
|
|
name="entropia.exe",
|
|
executable_path="C:/Games/entropia.exe",
|
|
memory_usage=1024000,
|
|
cpu_percent=5.5
|
|
)
|
|
|
|
assert info.pid == 12345
|
|
assert info.name == "entropia.exe"
|
|
|
|
|
|
class TestOverlayWindow:
|
|
"""Test Overlay Window functionality."""
|
|
|
|
def test_overlay_window_initialization(self, mock_plugin_manager):
|
|
"""Test overlay window initialization."""
|
|
pytest.importorskip("PyQt6")
|
|
from PyQt6.QtWidgets import QApplication
|
|
|
|
# Need a QApplication for QWidget
|
|
app = QApplication.instance() or QApplication([])
|
|
|
|
from core.overlay_window import OverlayWindow
|
|
|
|
with patch.object(OverlayWindow, '_setup_window'):
|
|
with patch.object(OverlayWindow, '_setup_ui'):
|
|
with patch.object(OverlayWindow, '_setup_tray'):
|
|
with patch.object(OverlayWindow, '_setup_shortcuts'):
|
|
with patch.object(OverlayWindow, '_setup_animations'):
|
|
window = OverlayWindow(mock_plugin_manager)
|
|
|
|
assert window.plugin_manager == mock_plugin_manager
|
|
assert window.is_visible is False
|
|
|
|
def test_overlay_window_properties(self, mock_plugin_manager):
|
|
"""Test overlay window properties."""
|
|
pytest.importorskip("PyQt6")
|
|
from PyQt6.QtWidgets import QApplication
|
|
|
|
app = QApplication.instance() or QApplication([])
|
|
|
|
from core.overlay_window import OverlayWindow
|
|
|
|
with patch.object(OverlayWindow, '_setup_window'):
|
|
with patch.object(OverlayWindow, '_setup_ui'):
|
|
with patch.object(OverlayWindow, '_setup_tray'):
|
|
with patch.object(OverlayWindow, '_setup_shortcuts'):
|
|
with patch.object(OverlayWindow, '_setup_animations'):
|
|
window = OverlayWindow(mock_plugin_manager)
|
|
|
|
# Test signals exist
|
|
assert hasattr(window, 'visibility_changed')
|
|
assert hasattr(window, 'theme_changed')
|
|
|
|
|
|
class TestActivityBar:
|
|
"""Test Activity Bar functionality."""
|
|
|
|
def test_activity_bar_config_defaults(self):
|
|
"""Test activity bar default configuration."""
|
|
from core.activity_bar import ActivityBarConfig
|
|
|
|
config = ActivityBarConfig()
|
|
|
|
assert config.enabled is True
|
|
assert config.position == "bottom"
|
|
assert config.icon_size == 32
|
|
assert config.auto_hide is True
|
|
assert config.auto_hide_delay == 3000
|
|
assert config.pinned_plugins == []
|
|
|
|
def test_activity_bar_config_serialization(self):
|
|
"""Test activity bar config serialization."""
|
|
from core.activity_bar import ActivityBarConfig
|
|
|
|
config = ActivityBarConfig(
|
|
enabled=False,
|
|
position="top",
|
|
icon_size=48,
|
|
pinned_plugins=["plugin1", "plugin2"]
|
|
)
|
|
|
|
data = config.to_dict()
|
|
|
|
assert data["enabled"] is False
|
|
assert data["position"] == "top"
|
|
assert data["icon_size"] == 48
|
|
assert data["pinned_plugins"] == ["plugin1", "plugin2"]
|
|
|
|
def test_activity_bar_config_deserialization(self):
|
|
"""Test activity bar config deserialization."""
|
|
from core.activity_bar import ActivityBarConfig
|
|
|
|
data = {
|
|
"enabled": False,
|
|
"position": "top",
|
|
"icon_size": 40,
|
|
"auto_hide": False,
|
|
"auto_hide_delay": 5000,
|
|
"pinned_plugins": ["plugin1"]
|
|
}
|
|
|
|
config = ActivityBarConfig.from_dict(data)
|
|
|
|
assert config.enabled is False
|
|
assert config.position == "top"
|
|
assert config.icon_size == 40
|
|
assert config.auto_hide is False
|
|
assert config.pinned_plugins == ["plugin1"]
|
|
|
|
|
|
class TestDashboard:
|
|
"""Test Dashboard functionality."""
|
|
|
|
def test_dashboard_widget_base(self):
|
|
"""Test dashboard widget base class."""
|
|
pytest.importorskip("PyQt6")
|
|
from PyQt6.QtWidgets import QApplication
|
|
|
|
app = QApplication.instance() or QApplication([])
|
|
|
|
from core.dashboard import DashboardWidget
|
|
|
|
widget = DashboardWidget()
|
|
|
|
assert widget.name == "Widget"
|
|
assert widget.description == "Base widget"
|
|
assert widget.size == (1, 1)
|
|
|
|
def test_dashboard_widget_signals(self):
|
|
"""Test dashboard widget signals."""
|
|
pytest.importorskip("PyQt6")
|
|
from PyQt6.QtWidgets import QApplication
|
|
|
|
app = QApplication.instance() or QApplication([])
|
|
|
|
from core.dashboard import Dashboard
|
|
|
|
with patch.object(Dashboard, '_setup_ui'):
|
|
with patch.object(Dashboard, '_add_default_widgets'):
|
|
dashboard = Dashboard()
|
|
|
|
assert hasattr(dashboard, 'widget_added')
|
|
assert hasattr(dashboard, 'widget_removed')
|
|
|
|
|
|
class TestMultiMonitorSupport:
|
|
"""Test multi-monitor support."""
|
|
|
|
def test_screen_detection(self):
|
|
"""Test screen detection."""
|
|
pytest.importorskip("PyQt6")
|
|
from PyQt6.QtWidgets import QApplication
|
|
from PyQt6.QtCore import QRect
|
|
|
|
app = QApplication.instance() or QApplication([])
|
|
|
|
screens = app.screens()
|
|
|
|
# Should have at least one screen
|
|
assert len(screens) >= 1
|
|
|
|
for screen in screens:
|
|
assert screen.geometry().width() > 0
|
|
assert screen.geometry().height() > 0
|