fix(suite): prevent wheel changes in generation settings

This commit is contained in:
chengma
2026-07-17 12:05:57 +08:00
parent d5d991e844
commit 01697759fc
4 changed files with 128 additions and 6 deletions
+80 -3
View File
@@ -23,10 +23,10 @@ from app import gui
if gui.QT_IMPORT_ERROR is not None:
raise unittest.SkipTest("PySide6 未安装")
from PySide6.QtCore import QMimeData, Qt, QUrl
from PySide6.QtGui import QIcon, QImage, QPixmap, QTextCursor
from PySide6.QtCore import QMimeData, QPoint, QPointF, Qt, QUrl
from PySide6.QtGui import QIcon, QImage, QPixmap, QTextCursor, QWheelEvent
from PySide6.QtTest import QTest
from PySide6.QtWidgets import QApplication, QLabel, QListWidgetItem, QPushButton
from PySide6.QtWidgets import QApplication, QLabel, QListWidgetItem, QPushButton, QScrollArea
from app.gui.tabs.product_suite import (
AutoHeightPlainTextEdit,
@@ -73,6 +73,21 @@ class ProductSuiteGuiTests(TempDirMixin, unittest.TestCase):
image.fill(0xFF336699)
self.assertTrue(image.save(path))
def _send_wheel(self, widget, delta=-120):
local_position = widget.rect().center()
global_position = widget.mapToGlobal(local_position)
event = QWheelEvent(
QPointF(local_position),
QPointF(global_position),
QPoint(),
QPoint(0, int(delta)),
Qt.NoButton,
Qt.NoModifier,
Qt.ScrollUpdate,
False,
)
QApplication.sendEvent(widget, event)
def _create_project_with_assets(self, temp_dir, config, count, item_id="51100639510"):
account = accounts.create_account(
"主店",
@@ -236,6 +251,68 @@ class ProductSuiteGuiTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_suite_setting_combos_forward_closed_wheel_to_config_scroll(self):
with self.make_temp_dir() as temp_dir:
config = self._config(temp_dir)
accounts.create_account("主店", "alias-a", debug_port=9222, config=config)
tab = ProductSuiteTab(config=config, db_path=config["db_path"])
self.addCleanup(tab.close)
tab.resize(620, 280)
tab.show()
self.app.processEvents()
scroll = tab.findChild(QScrollArea, "suiteConfigScroll")
self.assertIsNotNone(scroll)
scroll.widget().setMinimumHeight(scroll.viewport().height() + 400)
self.app.processEvents()
scroll.verticalScrollBar().setValue(0)
original_values = {
combo.objectName(): combo.currentData()
for combo in (
tab.platform_combo,
tab.country_combo,
tab.language_combo,
tab.ratio_combo,
)
}
for combo in (
tab.platform_combo,
tab.country_combo,
tab.language_combo,
tab.ratio_combo,
):
self._send_wheel(combo)
self.app.processEvents()
self.assertEqual(original_values[combo.objectName()], combo.currentData())
self.assertGreater(scroll.verticalScrollBar().value(), 0)
combo = tab.country_combo
combo.setCurrentIndex(0)
combo.showPopup()
self.app.processEvents()
self._send_wheel(combo.view())
self.app.processEvents()
self.assertEqual(0, combo.currentIndex())
combo.hidePopup()
combo.showPopup()
self.app.processEvents()
target_index = combo.model().index(1, 0)
target_rect = combo.view().visualRect(target_index)
QTest.mouseClick(combo.view().viewport(), Qt.LeftButton, Qt.NoModifier, target_rect.center())
self.app.processEvents()
self.assertEqual("新加坡", combo.currentData())
ratio_before = tab.ratio_combo.currentIndex()
tab.ratio_combo.setFocus()
QTest.keyClick(tab.ratio_combo, Qt.Key_Down)
self.app.processEvents()
self.assertNotEqual(ratio_before, tab.ratio_combo.currentIndex())
self.assertEqual(tab.ratio_combo.currentData(), tab._displayed_state.settings["ratio"])
self.assert_removed(temp_dir)
def test_prompt_settings_dialog_previews_validates_saves_and_restores(self):
with self.make_temp_dir() as temp_dir:
config = self._config(temp_dir)