fix: 兼容非滚动图片颜色采购选择 (#178)
This commit is contained in:
@@ -240,6 +240,21 @@ class ContextualConfirmPanelDevice(FakeDevice):
|
||||
self.mode = "panel"
|
||||
|
||||
|
||||
class SubmitHintPanelDevice(FakeDevice):
|
||||
"""模拟带提交提示的非滚动图片颜色面板。"""
|
||||
|
||||
def __init__(self, panel_data: str) -> None:
|
||||
super().__init__()
|
||||
self.panel_data = panel_data
|
||||
|
||||
def dump_hierarchy(self):
|
||||
if not self.has_opened:
|
||||
return '<hierarchy><node package="com.xunmeng.pinduoduo" /></hierarchy>'
|
||||
if self.mode == "panel":
|
||||
return self.panel_data
|
||||
return home_xml()
|
||||
|
||||
|
||||
def address_confirmation_xml(address: str) -> str:
|
||||
return f"""<hierarchy>
|
||||
<node package="com.xunmeng.pinduoduo" bounds="[0,0][1080,2376]">
|
||||
@@ -827,6 +842,40 @@ class U2PddPurchaseAdapterTest(unittest.TestCase):
|
||||
self.assertIn("[已脱敏]", content)
|
||||
adapter.close()
|
||||
|
||||
def test_color_mismatch_reports_reason_and_saves_sanitized_tree(self):
|
||||
panel_data = (
|
||||
FIXTURES / "pdd_spec_panel_submit_hint.xml"
|
||||
).read_text(encoding="utf-8")
|
||||
device = SubmitHintPanelDevice(panel_data)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
adapter = U2PddPurchaseAdapter(
|
||||
"USB-001",
|
||||
device_service=PddDeviceService(
|
||||
connector=lambda _serial: device
|
||||
),
|
||||
sleeper=lambda _seconds: None,
|
||||
select_color_fn=lambda *_args, **_kwargs: False,
|
||||
artifact_directory=Path(directory),
|
||||
)
|
||||
adapter.open_goods(GOODS_URL)
|
||||
|
||||
with self.assertRaises(PddPurchaseError) as raised:
|
||||
adapter.select_options({"color": "测试黑色"})
|
||||
|
||||
self.assertEqual(
|
||||
raised.exception.code, "PURCHASE_OPTIONS_MISMATCH"
|
||||
)
|
||||
self.assertIn("点击颜色后", raised.exception.message)
|
||||
self.assertEqual(
|
||||
raised.exception.diagnostics["selection_failure"],
|
||||
"selection_unconfirmed",
|
||||
)
|
||||
artifact = raised.exception.diagnostics["artifacts"][0]
|
||||
content = Path(artifact["path"]).read_text(encoding="utf-8")
|
||||
self.assertNotIn("测试黑色", content)
|
||||
self.assertIn("[已脱敏]", content)
|
||||
adapter.close()
|
||||
|
||||
def test_invalid_non_pdd_url_is_rejected_before_connect(self):
|
||||
device = FakeDevice()
|
||||
adapter = self._adapter(device, [])
|
||||
|
||||
Reference in New Issue
Block a user