feat(product-suite): add independent category rows
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
@@ -166,7 +167,161 @@ class ProductSuiteGuiTests(TempDirMixin, unittest.TestCase):
|
||||
tab._commit_custom_category()
|
||||
self.assertTrue(tab.custom_category_edit.isHidden())
|
||||
self.assertIn("尺寸图", tab._displayed_state.settings["categories"])
|
||||
self.assertEqual("尺寸图", tab._displayed_state.active_category)
|
||||
self.assertEqual(1, tab.category_rows["尺寸图"].count())
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_category_rows_are_vertical_with_helpers_and_independent_counters(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
config = self._config(temp_dir)
|
||||
tab = ProductSuiteTab(config=config, db_path=config["db_path"])
|
||||
self.addCleanup(tab.close)
|
||||
tab.resize(1180, 760)
|
||||
tab.show()
|
||||
self.app.processEvents()
|
||||
|
||||
expected = {
|
||||
"白底图": (1, "白底主图,多角度呈现商品细节"),
|
||||
"场景图": (2, "生活化场景展示商品使用方式"),
|
||||
"卖点图": (2, "突出核心卖点和差异化优势"),
|
||||
}
|
||||
self.assertEqual(list(expected), list(tab.category_rows))
|
||||
for row_index, (name, (count, helper)) in enumerate(expected.items()):
|
||||
row = tab.category_rows[name]
|
||||
layout_index = tab.category_grid.indexOf(row)
|
||||
self.assertEqual(
|
||||
(row_index, 0, 1, 1),
|
||||
tab.category_grid.getItemPosition(layout_index),
|
||||
)
|
||||
self.assertEqual(name, row.name_label.text())
|
||||
self.assertEqual(count, row.count())
|
||||
self.assertEqual(helper, row.helper_label.text())
|
||||
self.assertIsNone(row.rename_button)
|
||||
self.assertIsNone(row.delete_button)
|
||||
|
||||
scene_row = tab.category_rows["场景图"]
|
||||
scene_row.plus_button.click()
|
||||
self.assertIs(scene_row, tab.category_rows["场景图"])
|
||||
self.assertEqual(3, scene_row.count())
|
||||
self.assertEqual(1, tab.category_rows["白底图"].count())
|
||||
self.assertEqual(2, tab.category_rows["卖点图"].count())
|
||||
self.assertEqual("合计 6 张", tab.category_total_label.text())
|
||||
self.assertEqual("生成套图(6)", tab.generate_button.text())
|
||||
|
||||
white_row = tab.category_rows["白底图"]
|
||||
white_row.minus_button.click()
|
||||
self.assertEqual(0, white_row.count())
|
||||
self.assertFalse(white_row.minus_button.isEnabled())
|
||||
white_row.minus_button.click()
|
||||
self.assertEqual(0, tab._displayed_state.settings["categories"]["白底图"])
|
||||
self.assertEqual("合计 5 张", tab.category_total_label.text())
|
||||
|
||||
tab._displayed_state.worker = object()
|
||||
tab._apply_running_state(tab._displayed_state)
|
||||
self.assertTrue(
|
||||
all(
|
||||
not row.plus_button.isEnabled()
|
||||
for row in tab.category_rows.values()
|
||||
)
|
||||
)
|
||||
tab._displayed_state.worker = None
|
||||
tab._apply_running_state(tab._displayed_state)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_custom_category_row_preserves_count_and_order_when_renamed(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
config = self._config(temp_dir)
|
||||
tab = ProductSuiteTab(config=config, db_path=config["db_path"])
|
||||
self.addCleanup(tab.close)
|
||||
|
||||
fixed_counts = {
|
||||
name: tab.category_rows[name].count()
|
||||
for name in ("白底图", "场景图", "卖点图")
|
||||
}
|
||||
tab.add_custom_category()
|
||||
tab.custom_category_edit.setText("尺寸图")
|
||||
tab._commit_custom_category()
|
||||
custom_row = tab.category_rows["尺寸图"]
|
||||
self.assertEqual(1, custom_row.count())
|
||||
self.assertIsNone(custom_row.helper_label)
|
||||
self.assertIsNotNone(custom_row.rename_button)
|
||||
self.assertIsNotNone(custom_row.delete_button)
|
||||
|
||||
custom_row.plus_button.click()
|
||||
self.assertEqual(2, custom_row.count())
|
||||
with mock.patch(
|
||||
"app.gui.tabs.product_suite.QInputDialog.getText",
|
||||
return_value=("规格图", True),
|
||||
):
|
||||
custom_row.rename_button.click()
|
||||
self.assertNotIn("尺寸图", tab.category_rows)
|
||||
self.assertEqual(2, tab.category_rows["规格图"].count())
|
||||
self.assertEqual(
|
||||
["规格图"],
|
||||
tab._displayed_state.settings["custom_category_order"],
|
||||
)
|
||||
|
||||
tab.category_rows["规格图"].delete_button.click()
|
||||
self.assertNotIn("规格图", tab.category_rows)
|
||||
self.assertEqual([], tab._displayed_state.settings["custom_category_order"])
|
||||
self.assertEqual(
|
||||
fixed_counts,
|
||||
{
|
||||
name: tab.category_rows[name].count()
|
||||
for name in ("白底图", "场景图", "卖点图")
|
||||
},
|
||||
)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_category_counts_restore_after_task_switch_and_project_reload(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
config = self._config(temp_dir)
|
||||
account = accounts.create_account(
|
||||
"主店",
|
||||
"alias-a",
|
||||
debug_port=9222,
|
||||
config=config,
|
||||
)
|
||||
project = image_studio.create_or_get_project(
|
||||
account,
|
||||
item_id="51100639510",
|
||||
path=config["db_path"],
|
||||
)
|
||||
first = ProductSuiteTab(config=config, db_path=config["db_path"])
|
||||
state = first._displayed_state
|
||||
state.account_alias = "alias-a"
|
||||
state.item_id = "51100639510"
|
||||
state.project_id = project.id
|
||||
first.change_category_count("场景图", 1)
|
||||
first.add_custom_category()
|
||||
first.custom_category_edit.setText("细节图")
|
||||
first._commit_custom_category()
|
||||
first.category_rows["细节图"].plus_button.click()
|
||||
|
||||
first.add_task(inherit=False)
|
||||
self.assertEqual(2, first.category_rows["场景图"].count())
|
||||
first.task_tabs.setCurrentIndex(0)
|
||||
self.app.processEvents()
|
||||
self.assertEqual(3, first.category_rows["场景图"].count())
|
||||
self.assertEqual(2, first.category_rows["细节图"].count())
|
||||
first.close()
|
||||
first.deleteLater()
|
||||
self.app.processEvents()
|
||||
|
||||
second = ProductSuiteTab(config=config, db_path=config["db_path"])
|
||||
self.addCleanup(second.close)
|
||||
reloaded = second._displayed_state
|
||||
reloaded.account_alias = "alias-a"
|
||||
reloaded.item_id = "51100639510"
|
||||
second._bind_project(reloaded, load_existing=True)
|
||||
self.assertEqual(3, second.category_rows["场景图"].count())
|
||||
self.assertEqual(2, second.category_rows["细节图"].count())
|
||||
self.assertEqual(
|
||||
["细节图"],
|
||||
reloaded.settings["custom_category_order"],
|
||||
)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user