From 1902935d588f8b2265597c88499e7cc912f3cafc Mon Sep 17 00:00:00 2001 From: chengma Date: Tue, 18 Aug 2026 17:56:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E8=A7=84=E6=A0=BC?= =?UTF-8?q?=E6=91=98=E8=A6=81=E8=AF=AF=E5=88=A4=E9=A2=9C=E8=89=B2=E6=A0=87?= =?UTF-8?q?=E9=A2=98=20(#277)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/util/select_color_size.py | 22 +++++++++----- client/test/test_select_color_size.py | 44 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/client/src/util/select_color_size.py b/client/src/util/select_color_size.py index 23ce473..5e0ff94 100644 --- a/client/src/util/select_color_size.py +++ b/client/src/util/select_color_size.py @@ -172,23 +172,29 @@ def _screen_bounds(root: ET.Element) -> Optional[Bounds]: return 0, 0, max(item[2] for item in bounds), max(item[3] for item in bounds) +def _spec_heading_name(value: str) -> str: + """返回独立规格标题,排除“请选择”“选择后”等摘要和提示。""" + + compact = re.sub(r"\s+", "", str(value or "")) + compact = re.sub(r"[((]\d+[))]$", "", compact) + supported = _COLOR_HEADINGS + _PACKAGE_HEADINGS + return compact if compact in supported else "" + + def _heading_bounds(root: ET.Element) -> Optional[Bounds]: fuzzy_match: Optional[Bounds] = None package_fallback: Optional[Bounds] = None for node in root.iter("node"): - text = node.get("text", "").strip() + heading = _spec_heading_name(node.get("text", "")) bounds = _parse_bounds(node.get("bounds", "")) - if bounds is None or not _is_available(node): + if not heading or bounds is None or not _is_available(node): continue - # “请选择:颜色分类 尺码”等摘要不能当成颜色列表标题。 - if text == "颜色分类": + if heading == "颜色分类": return bounds - if fuzzy_match is None and any(heading in text for heading in _COLOR_HEADINGS): + if fuzzy_match is None and heading in _COLOR_HEADINGS: fuzzy_match = bounds - if package_fallback is None and any( - heading in text for heading in _PACKAGE_HEADINGS - ): + if package_fallback is None and heading in _PACKAGE_HEADINGS: package_fallback = bounds # “款式 + 套餐”优先定位款式;只有套餐一个维度时才用套餐兜底。 return fuzzy_match or package_fallback diff --git a/client/test/test_select_color_size.py b/client/test/test_select_color_size.py index ff14f3b..77ebbf8 100644 --- a/client/test/test_select_color_size.py +++ b/client/test/test_select_color_size.py @@ -263,6 +263,50 @@ class StaticColorSelectionTest(unittest.TestCase): self.assertTrue(selected) self.assertEqual(device.clicks, [(194, 1389)]) + def test_summary_is_ignored_and_counted_color_heading_is_used(self): + simplified = "紫色诱惑" + traditional = "紫色誘惑" + panel_xml = f''' + + + + + + + + + + + ''' + device = StaticColorDevice(panel_xml, selected_text=simplified) + + selected = select_color( + device, + panel_xml, + traditional, + action_delay=0.001, + ) + + self.assertTrue(selected) + self.assertEqual(device.clicks, [(142, 1537)]) + self.assertEqual(device.swipes, []) + + def test_chinese_parentheses_count_is_a_color_heading(self): + panel_xml = self.panel_xml.replace("颜色分类", "颜色(4)") + device = StaticColorDevice(panel_xml) + + selected = select_color( + device, + panel_xml, + "测试黑色", + action_delay=0.001, + ) + + self.assertTrue(selected) + self.assertEqual(device.clicks, [(194, 1389)]) + def test_non_scrollable_row_ignores_same_row_style_option_as_heading(self): simplified = "纯欲莹白【透.视蕾丝衣.免脱款】" traditional = "純欲瑩白【透.視蕾絲衣.免脫款】"