Изменено: - сервис автоматически применяет обновлённые настройки без перезапуска - графический интерфейс сразу отображает выбранный режим - настройки сохраняются без риска повреждения при фоновом чтении Исправлено: - чрезмерная загрузка процессора при ожидании команд интерфейса - обработка команд после периода бездействия - использование пользовательского пути к конфигурации
115 lines
4.1 KiB
Python
115 lines
4.1 KiB
Python
"""Smoke tests for GUI widgets."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from PySide6.QtWidgets import QApplication, QGridLayout
|
|
|
|
from lgcompanion.config import Config, DeviceProfile
|
|
from lgcompanion.gui.main_window import _DeviceDetailPage, _SettingsPage, _SettingsPage
|
|
|
|
|
|
@pytest.fixture
|
|
def app() -> QApplication:
|
|
instance = QApplication.instance()
|
|
if instance is None:
|
|
return QApplication([])
|
|
return instance # type: ignore[return-value]
|
|
|
|
|
|
def _row(grid: QGridLayout, widget) -> int:
|
|
idx = grid.indexOf(widget)
|
|
return grid.getItemPosition(idx)[0]
|
|
|
|
|
|
def test_device_detail_page_switches_layout_on_resize(app: QApplication) -> None:
|
|
cfg = Config.default()
|
|
cfg.add_device(DeviceProfile(name="Arctis 7", vendor_id="0x1038", product_id="0x12AD"))
|
|
page = _DeviceDetailPage(cfg)
|
|
page.load_device("Arctis 7")
|
|
|
|
grid = page._settings_layout
|
|
page._settings_container.setFixedWidth(800)
|
|
page._update_settings_layout()
|
|
assert _row(grid, page._mode_group) == 0
|
|
assert _row(grid, page._hrir_group) == 0
|
|
|
|
page._settings_container.setFixedWidth(400)
|
|
page._update_settings_layout()
|
|
assert _row(grid, page._mode_group) == 0
|
|
assert _row(grid, page._hrir_group) == 1
|
|
|
|
|
|
def test_status_badge_toggles_enabled(app: QApplication) -> None:
|
|
cfg = Config.default()
|
|
cfg.add_device(DeviceProfile(name="Arctis 7", vendor_id="0x1038", product_id="0x12AD", enabled=True))
|
|
page = _DeviceDetailPage(cfg)
|
|
page.load_device("Arctis 7")
|
|
|
|
assert page._status_badge.text() == "Включено"
|
|
assert cfg.get_device("Arctis 7").enabled is True
|
|
|
|
page._status_badge.click()
|
|
assert cfg.get_device("Arctis 7").enabled is False
|
|
assert page._status_badge.text() == "Отключено"
|
|
|
|
page._status_badge.click()
|
|
assert cfg.get_device("Arctis 7").enabled is True
|
|
assert page._status_badge.text() == "Включено"
|
|
|
|
|
|
def test_refresh_sinks_fills_all_combos(app: QApplication) -> None:
|
|
cfg = Config.default()
|
|
page = _SettingsPage(cfg)
|
|
detected = [
|
|
("alsa_output.usb-SteelSeries_SteelSeries_Arctis_7-00.stereo-game", "SteelSeries Arctis 7 Игра"),
|
|
]
|
|
with patch("lgcompanion.gui.main_window.list_sinks_with_description", return_value=detected):
|
|
page._refresh_sinks()
|
|
|
|
assert page.surround_edit.count() > 0
|
|
assert page.stereo_edit.count() > 0
|
|
assert page.filter_output_edit.count() > 0
|
|
assert page.stereo_edit.findData("alsa_output.usb-SteelSeries_SteelSeries_Arctis_7-00.stereo-game") >= 0
|
|
|
|
|
|
def test_detail_page_survives_repeated_rebuilds_and_resizes(app: QApplication) -> None:
|
|
"""Regression: repaint crashes after HRIR-manager close (queued rebuilds + resize)."""
|
|
cfg = Config.default()
|
|
cfg.add_device(DeviceProfile(name="Arctis 7", vendor_id="0x1038", product_id="0x12AD", enabled=True))
|
|
page = _DeviceDetailPage(cfg)
|
|
page.show()
|
|
|
|
for width in (800, 400, 800):
|
|
page.load_device("Arctis 7") # queues slider rebuild + layout update
|
|
page.set_battery(55) # pixmap update on possibly pending-deletion widgets
|
|
page.resize(width, 600) # resizeEvent must not mutate layout synchronously
|
|
app.processEvents()
|
|
app.sendPostedEvents() # runs deleteLater of the previous widgets
|
|
|
|
grid = page._settings_layout
|
|
assert grid.indexOf(page._mode_group) >= 0
|
|
assert grid.indexOf(page._hrir_group) >= 0
|
|
page.close()
|
|
|
|
|
|
def test_tray_mode_updates_local_config_without_switching_sink(app: QApplication) -> None:
|
|
from unittest.mock import MagicMock
|
|
from lgcompanion.gui.app import TrayApplication
|
|
|
|
tray = TrayApplication.__new__(TrayApplication)
|
|
tray.config = Config.default()
|
|
tray.config.add_device(DeviceProfile(name="Arctis 7", vendor_id="0x1038", product_id="0x12AD"))
|
|
tray._current_device_name = "Arctis 7"
|
|
tray.engine_client = MagicMock()
|
|
tray.auto_action = MagicMock()
|
|
tray.main_window = MagicMock()
|
|
|
|
tray._set_mode("stereo")
|
|
|
|
assert tray.config.get_device("Arctis 7").mode == "stereo"
|
|
tray.engine_client.set_mode.assert_called_once_with("stereo")
|
|
tray.main_window.refresh_device_detail.assert_called_once_with()
|