fix: 兼容套餐标题滑出后的续页采集 (#168)

This commit is contained in:
chengma
2026-08-11 17:28:18 +08:00
parent 6984e06385
commit 94793ab28f
2 changed files with 288 additions and 13 deletions
+77
View File
@@ -509,6 +509,59 @@ class HorizontalPackageDevice:
self.page = max(self.page - 1, 0)
class VerticalLongPackageDevice:
"""模拟纵向长套餐:滑到第二屏后“套餐”标题不再出现在控件树。"""
packages = tuple(f"套餐{i}" for i in range(1, 11))
def __init__(self):
self.page = 0
self.swipes = []
self.clicks = []
def dump_hierarchy(self):
start = min(self.page * 3, len(self.packages) - 4)
visible = self.packages[start : start + 4]
headings = ""
if self.page == 0:
headings = """
<node text="款式" bounds="[36,720][180,780]" />
<node text="口罩款" clickable="true" selected="true"
bounds="[36,800][300,900]" />
<node text="套餐(10)" bounds="[36,980][240,1040]" />
"""
options = []
for index, text in enumerate(visible):
top = 1080 + index * 210
options.append(
f'<node text="{text}" clickable="true" '
f'bounds="[36,{top}][500,{top + 150}]" />'
)
return f"""<hierarchy>
<node bounds="[0,0][1080,2340]">
<node class="android.widget.ScrollView" scrollable="true"
bounds="[0,650][1080,2200]">
<node text="已选:套餐1" bounds="[36,660][500,710]" />
{headings}
{''.join(options)}
<node text="增加数量" clickable="true"
bounds="[36,1950][220,2050]" />
<node text="提交订单" clickable="true"
bounds="[300,2080][1040,2190]" />
</node>
</node>
</hierarchy>"""
def swipe(self, x1, y1, x2, y2, duration=0.35):
self.swipes.append((x1, y1, x2, y2, duration))
if abs(y2 - y1) <= abs(x2 - x1):
return
if y1 > y2:
self.page = min(self.page + 1, 2)
else:
self.page = max(self.page - 1, 0)
class FakeClock:
"""测试用时钟:sleep 只推进虚拟时间,不真的等待。"""
@@ -1258,6 +1311,30 @@ class PddCollectParserTest(unittest.TestCase):
self.assertEqual(raised.exception.diagnostics["expected_count"], 8)
self.assertEqual(raised.exception.diagnostics["collected_count"], 7)
def test_vertical_packages_continue_after_heading_scrolls_out(self):
device = VerticalLongPackageDevice()
service = PddCollectService(
PddDeviceService(lambda _serial: device),
"USB-001",
"client-001",
sleeper=lambda _seconds: None,
)
result = service._collect_size_dimension(device)
self.assertIsNotNone(result)
self.assertEqual(result.name, "套餐(10)")
self.assertEqual(
[value.text for value in result.values],
list(device.packages),
)
self.assertNotIn("增加数量", [value.text for value in result.values])
self.assertNotIn("提交订单", [value.text for value in result.values])
self.assertEqual(device.clicks, [])
self.assertTrue(
all(abs(y2 - y1) > abs(x2 - x1) for x1, y1, x2, y2, _ in device.swipes)
)
def test_visible_click_is_fallback_when_page_exposes_no_selection_state(self):
xml_data = keep_only_one_sku(self.spec_xml)
root = ET.fromstring(xml_data)