feat(ai-studio): add final selection trays

This commit is contained in:
chengma
2026-07-11 14:20:56 +08:00
parent 5451579073
commit 5754e4831a
4 changed files with 369 additions and 14 deletions
+58
View File
@@ -542,6 +542,64 @@ class GuiTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_image_studio_final_selection_order_and_guards(self):
with self.make_temp_dir() as temp_dir:
cfg = self.make_config(temp_dir)
db.init_db(cfg["db_path"])
project = image_studio.create_or_get_project(
account_alias="alias-a",
account_slug="alias_a",
item_id="51100639510",
path=cfg["db_path"],
)
first_path = self.write_test_image(os.path.join(temp_dir, "first.jpg"))
second_path = self.write_test_image(os.path.join(temp_dir, "second.jpg"))
first = image_studio.add_asset(
project.id,
"generated_main",
local_path=first_path,
aspect_ratio="1:1",
path=cfg["db_path"],
)
second = image_studio.add_asset(
project.id,
"generated_main",
local_path=second_path,
aspect_ratio="3:4",
path=cfg["db_path"],
)
tab = ImageStudioTab(config=cfg, db_path=cfg["db_path"])
self.addCleanup(tab.close)
messages = []
tab._message = lambda title, text: messages.append((title, text))
tab._select_project(project.id)
self.assertTrue(tab.add_asset_to_selection("main", first.id))
self.assertTrue(tab.add_asset_to_selection("main", second.id, insert_index=0))
main = image_studio.list_selections(project.id, "main", path=cfg["db_path"])
self.assertEqual([second.id, first.id], [selection.asset_id for selection in main])
self.assertEqual([second.id, first.id], [
tab.main_selection_list.item(row).data(gui.Qt.UserRole)
for row in range(tab.main_selection_list.count())
])
self.assertEqual("#fff8c5", tab.main_selection_list.item(0).background().color().name())
self.assertFalse(tab.add_asset_to_selection("main", first.id))
self.assertIn("不能重复加入", messages[-1][0])
self.assertTrue(tab.add_asset_to_selection("detail", first.id))
detail = image_studio.list_selections(project.id, "detail", path=cfg["db_path"])
self.assertEqual([first.id], [selection.asset_id for selection in detail])
self.assertTrue(tab.move_selection_asset("main", 1, 0))
main = image_studio.list_selections(project.id, "main", path=cfg["db_path"])
self.assertEqual([first.id, second.id], [selection.asset_id for selection in main])
self.assertTrue(tab.remove_asset_from_selection("main", first.id))
main = image_studio.list_selections(project.id, "main", path=cfg["db_path"])
self.assertEqual([second.id], [selection.asset_id for selection in main])
self.assert_removed(temp_dir)
def test_startup_update_gate_forced_blocks_and_opens_download(self):
boxes = []