feat: default workflow batch filters to latest batch
This commit is contained in:
@@ -86,6 +86,17 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertIsNotNone(value)
|
||||
self.assertEqual(color, value.name())
|
||||
|
||||
def set_batch_created_at(self, cfg, batch_id, created_at):
|
||||
conn = db.connect(cfg["db_path"])
|
||||
try:
|
||||
with conn:
|
||||
conn.execute(
|
||||
"UPDATE batches SET created_at = ?, updated_at = ? WHERE id = ?",
|
||||
(created_at, created_at, batch_id),
|
||||
)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def make_fake_message_box(self, selected_label):
|
||||
boxes = []
|
||||
|
||||
@@ -511,6 +522,53 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_workflow_batch_filters_default_to_latest_batch_and_remember_selection(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
|
||||
for tab_class in (CollectTab, GenerateTab, ApplyTab):
|
||||
tab = tab_class(config=cfg)
|
||||
self.addCleanup(tab.close)
|
||||
self.assertEqual(0, tab.batch_filter.currentIndex())
|
||||
self.assertIsNone(tab.batch_filter.currentData())
|
||||
|
||||
accounts.create_account("主店", "alias-a", debug_port=9222, config=cfg)
|
||||
older_batch = db.create_batch(["older.xlsx"], path=cfg["db_path"])
|
||||
newer_batch = db.create_batch(["newer.xlsx"], path=cfg["db_path"])
|
||||
self.set_batch_created_at(cfg, older_batch, "2026-07-08T10:00:00")
|
||||
self.set_batch_created_at(cfg, newer_batch, "2026-07-08T11:00:00")
|
||||
for batch_id, item_id in ((older_batch, "1001"), (newer_batch, "2001")):
|
||||
db.insert_tasks(
|
||||
batch_id,
|
||||
[
|
||||
{
|
||||
"source_file_abs": os.path.join(temp_dir, f"{item_id}.xlsx"),
|
||||
"source_sheet": "商品",
|
||||
"source_row": 2,
|
||||
"account_name": "Excel主店",
|
||||
"alias": "alias-a",
|
||||
"item_id": item_id,
|
||||
}
|
||||
],
|
||||
path=cfg["db_path"],
|
||||
)
|
||||
|
||||
for tab_class in (CollectTab, GenerateTab, ApplyTab):
|
||||
tab = tab_class(config=cfg)
|
||||
self.addCleanup(tab.close)
|
||||
self.assertEqual(newer_batch, tab.batch_filter.currentData())
|
||||
self.assertEqual(1, tab.batch_filter.currentIndex())
|
||||
|
||||
tab.batch_filter.setCurrentIndex(tab.batch_filter.findData(older_batch))
|
||||
tab.refresh_tasks()
|
||||
self.assertEqual(older_batch, tab.batch_filter.currentData())
|
||||
|
||||
tab.batch_filter.setCurrentIndex(tab.batch_filter.findData(None))
|
||||
tab.refresh_tasks()
|
||||
self.assertIsNone(tab.batch_filter.currentData())
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_settings_tab_loads_ai_models_and_masks_key_field(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
@@ -2750,6 +2808,7 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
tab = ApplyTab(config=cfg)
|
||||
self.addCleanup(tab.close)
|
||||
tab.batch_filter.setCurrentIndex(tab.batch_filter.findData(None))
|
||||
|
||||
self.assertIsInstance(tab.task_table, QTableView)
|
||||
self.assertEqual(["店铺", "商品ID", "新标题", "新封面", "阶段", "结果"], tab.model.HEADERS)
|
||||
@@ -3718,6 +3777,7 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
tab = GenerateTab(config=cfg)
|
||||
self.addCleanup(tab.close)
|
||||
tab.batch_filter.setCurrentIndex(tab.batch_filter.findData(None))
|
||||
|
||||
self.assertEqual("generateItemFilter", tab.item_filter.objectName())
|
||||
self.assertEqual(4, tab.model.rowCount())
|
||||
@@ -4243,9 +4303,11 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
statuses = []
|
||||
tab = CollectTab(config=cfg, status_callback=statuses.append)
|
||||
self.addCleanup(tab.close)
|
||||
created = {}
|
||||
|
||||
def fake_import(file_paths, path=None):
|
||||
batch_id = db.create_batch(file_paths, path=path)
|
||||
created["batch_id"] = batch_id
|
||||
db.insert_tasks(
|
||||
batch_id,
|
||||
[
|
||||
@@ -4290,6 +4352,7 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertIn("匹配1", tab.summary_label.text())
|
||||
self.assertEqual("", tab.show_unmatched_button.styleSheet())
|
||||
self.assertIn("入库1", statuses[-1])
|
||||
self.assertEqual(created["batch_id"], tab.batch_filter.currentData())
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user