feat(apply): open product page on left double click
This commit is contained in:
@@ -611,6 +611,89 @@ class EditorLoginTests(unittest.TestCase):
|
||||
fake.sent,
|
||||
)
|
||||
|
||||
def test_open_or_focus_product_tab_reuses_exact_target_without_navigation(self):
|
||||
fake = FakeProductCDP("ws-existing")
|
||||
existing = {
|
||||
"id": "target-existing",
|
||||
"type": "page",
|
||||
"url": "https://seller.shopee.tw/portal/product/51100639510?draft=1",
|
||||
"webSocketDebuggerUrl": "ws-existing",
|
||||
}
|
||||
with mock.patch("app.editor.http_get", return_value=[existing]), mock.patch(
|
||||
"app.editor.create_tab_info"
|
||||
) as create_tab_info, mock.patch(
|
||||
"app.editor.CDP", return_value=fake
|
||||
), mock.patch("app.editor._ensure_page_domains"):
|
||||
result = editor.open_or_focus_product_tab(
|
||||
{"debug_port": 9222}, "51100639510"
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
{"item_id": "51100639510", "created": False, "target_id": "target-existing"},
|
||||
result,
|
||||
)
|
||||
create_tab_info.assert_not_called()
|
||||
self.assertIn(("Page.bringToFront", {}), fake.sent)
|
||||
self.assertNotIn(
|
||||
(
|
||||
"Page.navigate",
|
||||
{
|
||||
"url": (
|
||||
"https://seller.shopee.tw/portal/product/51100639510"
|
||||
"?pageEntry=product_list&ignore-html-cache=1"
|
||||
)
|
||||
},
|
||||
),
|
||||
fake.sent,
|
||||
)
|
||||
self.assertTrue(fake.closed)
|
||||
|
||||
def test_open_or_focus_product_tab_ignores_non_exact_product_target(self):
|
||||
fake = FakeProductCDP("ws-new")
|
||||
non_exact = {
|
||||
"id": "target-other",
|
||||
"type": "page",
|
||||
"url": "https://seller.shopee.tw/portal/product/511006395101",
|
||||
"webSocketDebuggerUrl": "ws-other",
|
||||
}
|
||||
with mock.patch("app.editor.http_get", return_value=[non_exact]), mock.patch(
|
||||
"app.editor.create_tab_info",
|
||||
return_value={"id": "target-new", "webSocketDebuggerUrl": "ws-new"},
|
||||
) as create_tab_info, mock.patch(
|
||||
"app.editor.CDP", return_value=fake
|
||||
), mock.patch("app.editor._ensure_page_domains"), mock.patch(
|
||||
"app.editor._wait_ready", return_value=True
|
||||
) as wait_ready:
|
||||
result = editor.open_or_focus_product_tab(
|
||||
{"debug_port": 9222}, "51100639510"
|
||||
)
|
||||
|
||||
self.assertTrue(result["created"])
|
||||
create_tab_info.assert_called_once_with(
|
||||
"https://seller.shopee.tw/portal/product/51100639510"
|
||||
"?pageEntry=product_list&ignore-html-cache=1",
|
||||
host="127.0.0.1:9222",
|
||||
background=False,
|
||||
)
|
||||
wait_ready.assert_called_once_with(fake)
|
||||
self.assertTrue(fake.closed)
|
||||
|
||||
def test_open_or_focus_product_tab_cleans_only_new_target_on_failure(self):
|
||||
fake = FakeProductCDP("ws-new")
|
||||
with mock.patch("app.editor.http_get", return_value=[]), mock.patch(
|
||||
"app.editor.create_tab_info",
|
||||
return_value={"id": "target-new", "webSocketDebuggerUrl": "ws-new"},
|
||||
), mock.patch("app.editor.CDP", return_value=fake), mock.patch(
|
||||
"app.editor._ensure_page_domains"
|
||||
), mock.patch(
|
||||
"app.editor._wait_ready", side_effect=editor.EditorError("商品失效:测试")
|
||||
), mock.patch("app.editor.close_tab", return_value=True) as close_tab:
|
||||
with self.assertRaises(editor.EditorError):
|
||||
editor.open_or_focus_product_tab({"debug_port": 9222}, "bad-item")
|
||||
|
||||
close_tab.assert_called_once_with("target-new", host="127.0.0.1:9222")
|
||||
self.assertTrue(fake.closed)
|
||||
|
||||
def test_open_product_marks_auto_created_tab(self):
|
||||
fake = FakeProductCDP("ws-new")
|
||||
with mock.patch("app.editor.find_product_tab", return_value=None), mock.patch(
|
||||
|
||||
Reference in New Issue
Block a user