feat(collect): choose product status scope

This commit is contained in:
chengma
2026-07-18 16:46:59 +08:00
parent 0cf23db403
commit 4658a1ca61
11 changed files with 420 additions and 41 deletions
+47 -2
View File
@@ -28,7 +28,7 @@ from app import (
if gui.QT_IMPORT_ERROR is not None:
raise unittest.SkipTest("PySide6 未安装")
from PySide6.QtCore import QItemSelectionModel, QModelIndex, QRect, QSize, Qt
from PySide6.QtCore import QItemSelectionModel, QModelIndex, QRect, QSize, QTimer, Qt
from PySide6.QtGui import QImage, QKeyEvent, QTextCursor
from PySide6.QtWidgets import (
QAbstractItemView,
@@ -38,6 +38,7 @@ from PySide6.QtWidgets import (
QListView,
QPlainTextEdit,
QProgressBar,
QPushButton,
QTableView,
)
@@ -7804,7 +7805,11 @@ class GuiTests(TempDirMixin, unittest.TestCase):
captured["started"] = True
captured = {}
with mock.patch("app.gui.CollectWorker", FakeWorker), mock.patch(
with mock.patch.object(
tab,
"_choose_collect_scope",
return_value="normal_only",
), mock.patch("app.gui.CollectWorker", FakeWorker), mock.patch(
"app.gui.run_worker",
return_value=FakeThread(),
):
@@ -7813,12 +7818,52 @@ class GuiTests(TempDirMixin, unittest.TestCase):
self.assertTrue(captured["started"])
self.assertEqual(["1001"], [task.item_id for task in captured["tasks"]])
self.assertEqual(cfg["db_path"], captured["kwargs"]["db_path"])
self.assertEqual("normal_only", captured["kwargs"]["collect_scope"])
self.assertFalse(tab.shop_filter.isEnabled())
self.assertFalse(tab.item_filter.isEnabled())
self.assertFalse(tab.status_filter.isEnabled())
self.assert_removed(temp_dir)
def test_collect_scope_dialog_uses_safe_default_and_red_all_status_choice(self):
with self.make_temp_dir() as temp_dir:
tab = CollectTab(config=self.make_config(temp_dir))
self.addCleanup(tab.close)
captured = {}
def click_all_statuses():
box = QApplication.activeModalWidget()
normal_button = box.findChild(QPushButton, "collectNormalOnlyButton")
all_button = box.findChild(QPushButton, "collectAllStatusesButton")
captured["default"] = box.defaultButton().objectName()
captured["all_style"] = all_button.styleSheet()
self.assertIsNotNone(normal_button)
self.assertIsNotNone(all_button)
all_button.click()
QTimer.singleShot(0, click_all_statuses)
scope = tab._choose_collect_scope()
self.assertEqual("all", scope)
self.assertEqual("collectNormalOnlyButton", captured["default"])
self.assertIn("#cf222e", captured["all_style"])
self.assert_removed(temp_dir)
def test_collect_without_candidates_does_not_open_scope_dialog(self):
with self.make_temp_dir() as temp_dir:
statuses = []
tab = CollectTab(config=self.make_config(temp_dir), status_callback=statuses.append)
self.addCleanup(tab.close)
with mock.patch.object(tab, "_choose_collect_scope") as choose_scope:
tab.collect_old_data()
choose_scope.assert_not_called()
self.assertEqual("没有可采集任务", statuses[-1])
self.assert_removed(temp_dir)
def test_collect_activity_tracks_step_resets_each_task_and_freezes_on_stop(self):
with self.make_temp_dir() as temp_dir:
tab = CollectTab(config=self.make_config(temp_dir))