feat(product-suite): compact controls and remember settings

This commit is contained in:
chengma
2026-07-14 15:16:09 +08:00
parent 17bb7521fd
commit 21d2dd5253
10 changed files with 431 additions and 47 deletions
+69
View File
@@ -32,6 +32,15 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
self.assertEqual("title", appconfig.shopee_update_config(config)["update_mode"])
self.assertNotIn("allow_cover_update", appconfig.shopee_update_config(config))
self.assertEqual(1, appconfig.shopee_update_config(config)["max_parallel_accounts"])
self.assertEqual(
{
"platform": "Shopee",
"country": "中国台湾",
"language": "繁体中文",
"ratio": "1:1",
},
appconfig.product_suite_last_settings(config),
)
updated = appconfig.update_config(
{"ai": {"resolution": "2k"}},
@@ -66,6 +75,66 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_product_suite_last_settings_are_normalized_and_preserve_other_config(self):
with self.make_temp_dir() as temp_dir:
config_path = os.path.join(temp_dir, "config.json")
with open(config_path, "w", encoding="utf-8") as fh:
json.dump(
{
"chrome_path": "custom-chrome.exe",
"custom_section": {"keep": True},
"product_suite": {
"last_settings": {
"platform": "未知平台",
"country": "新加坡",
"language": "英文",
"ratio": "2:3",
"unexpected": "ignore",
}
},
},
fh,
ensure_ascii=False,
)
loaded = appconfig.load_config(config_path)
self.assertEqual(
{
"platform": "Shopee",
"country": "新加坡",
"language": "英文",
"ratio": "1:1",
},
appconfig.product_suite_last_settings(loaded),
)
updated = appconfig.update_config(
{
"product_suite": {
"last_settings": {
"platform": "Amazon",
"country": "中国台湾",
"language": "繁体中文",
"ratio": "16:9",
}
}
},
path=config_path,
)
self.assertEqual("custom-chrome.exe", updated["chrome_path"])
self.assertEqual({"keep": True}, updated["custom_section"])
self.assertEqual("16:9", appconfig.product_suite_last_settings(updated)["ratio"])
with open(config_path, "r", encoding="utf-8") as fh:
persisted = json.load(fh)
self.assertEqual(
{"platform", "country", "language", "ratio"},
set(persisted["product_suite"]["last_settings"]),
)
self.assert_removed(temp_dir)
def test_shopee_update_legacy_parallel_config_is_migrated(self):
with self.make_temp_dir() as temp_dir:
config_path = os.path.join(temp_dir, "config.json")