feat(collect): persist product status snapshots
This commit is contained in:
@@ -39,11 +39,12 @@ class FakeCDP:
|
||||
|
||||
|
||||
class FakeProductCDP:
|
||||
def __init__(self, ws, ready=True, toasts=None, rects=None, url=""):
|
||||
def __init__(self, ws, ready=True, toasts=None, rects=None, alerts=None, url=""):
|
||||
self.ws = ws
|
||||
self.ready = ready
|
||||
self.toasts = list(toasts or [])
|
||||
self.rects = list(rects or [])
|
||||
self.alerts = list(alerts or [])
|
||||
self.url = url
|
||||
self.closed = False
|
||||
self.sent = []
|
||||
@@ -63,6 +64,8 @@ class FakeProductCDP:
|
||||
return json.dumps(self.toasts)
|
||||
if expr == editor.JS_RECTS:
|
||||
return json.dumps(self.rects)
|
||||
if expr == editor.JS_PRODUCT_STATUS_ALERTS:
|
||||
return json.dumps(self.alerts)
|
||||
return None
|
||||
|
||||
def send(self, method, params=None):
|
||||
@@ -910,6 +913,64 @@ class EditorLoginTests(unittest.TestCase):
|
||||
timeout=2.0,
|
||||
)
|
||||
|
||||
def test_read_product_status_uses_warning_alerts_without_vue_scope_selectors(self):
|
||||
cdp = FakeProductCDP(
|
||||
"ws-status",
|
||||
alerts=[
|
||||
{"title": "无关提示", "description": "保留为未知"},
|
||||
{"title": " 審核中 ", "description": " 商品等待审核 "},
|
||||
],
|
||||
)
|
||||
|
||||
result = editor.read_product_status(cdp)
|
||||
|
||||
self.assertEqual("reviewing", result["product_status"])
|
||||
self.assertEqual("标题:審核中;说明:商品等待审核", result["product_status_note"])
|
||||
self.assertIsNone(result["product_status_error"])
|
||||
self.assertIn(".eds-alert.eds-alert--warning", editor.JS_PRODUCT_STATUS_ALERTS)
|
||||
self.assertNotIn("data-v-", editor.JS_PRODUCT_STATUS_ALERTS)
|
||||
|
||||
def test_read_product_status_degrades_to_unknown_when_cdp_response_is_invalid(self):
|
||||
class BrokenStatusCDP:
|
||||
def val(self, _expr):
|
||||
raise RuntimeError("状态读取失败")
|
||||
|
||||
result = editor.read_product_status(BrokenStatusCDP())
|
||||
|
||||
self.assertEqual("unknown", result["product_status"])
|
||||
self.assertIsNone(result["product_status_note"])
|
||||
self.assertIn("状态读取失败", result["product_status_error"])
|
||||
|
||||
def test_collect_reads_product_status_before_title_and_returns_snapshot(self):
|
||||
cdp = FakeProductCDP("ws-new", alerts=[])
|
||||
steps = []
|
||||
|
||||
def read_title_after_status(_cdp):
|
||||
self.assertIn("read_product_status", steps)
|
||||
return "旧标题"
|
||||
|
||||
with mock.patch("app.editor.open_product", return_value=cdp), mock.patch(
|
||||
"app.editor.read_title",
|
||||
side_effect=read_title_after_status,
|
||||
), mock.patch(
|
||||
"app.editor.read_cover_src",
|
||||
return_value="https://down-ws-sg.vod.susercontent.com/cover.jpg",
|
||||
), mock.patch(
|
||||
"app.editor.download_cover",
|
||||
return_value="images/main/51100639510_old.jpg",
|
||||
):
|
||||
result = editor.collect(
|
||||
{"debug_port": 9222},
|
||||
{"item_id": "51100639510", "old_cover_path": "old.jpg"},
|
||||
on_step=steps.append,
|
||||
)
|
||||
|
||||
self.assertEqual("normal", result["product_status"])
|
||||
self.assertEqual(
|
||||
["read_product_status", "read_title", "read_cover", "download_cover"],
|
||||
steps,
|
||||
)
|
||||
|
||||
def test_collect_keeps_reused_product_tab_open(self):
|
||||
cdp = FakeProductCDP("ws-existing")
|
||||
cdp.target_id = "target-existing"
|
||||
|
||||
Reference in New Issue
Block a user