feat(schedule): 增加库存源选项描述字段与站点ID支持
This commit is contained in:
1 parent
f4e74f7b07
commit
8b1efbedb9
37 files changed
+8488
-4126
No files matched your search
@@ -0,0 +1,159 @@
|
||||
"""crane_navigation 报表页导航测试。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def _load_navigation():
|
||||
module_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "crane_navigation.py"
|
||||
spec = importlib.util.spec_from_file_location("crane_navigation_test", module_path)
|
||||
assert spec and spec.loader
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
class _FakeLocator:
|
||||
def __init__(self, *, visible: bool = True) -> None:
|
||||
self.visible = visible
|
||||
self.clicked = False
|
||||
self.hovered = False
|
||||
|
||||
@property
|
||||
def first(self) -> "_FakeLocator":
|
||||
return self
|
||||
|
||||
def is_visible(self, timeout: int = 0) -> bool:
|
||||
return self.visible
|
||||
|
||||
def click(self, timeout: int = 0, force: bool = False) -> None:
|
||||
self.clicked = True
|
||||
|
||||
def hover(self, timeout: int = 0) -> None:
|
||||
self.hovered = True
|
||||
|
||||
|
||||
class _FakePage:
|
||||
def __init__(self, *, url: str = "https://wms-portal.craneww.com/#/") -> None:
|
||||
self.url = url
|
||||
self.frames: list[_FakePage] = []
|
||||
self.goto_calls: list[str] = []
|
||||
|
||||
def locator(self, selector: str) -> _FakeLocator:
|
||||
if "on-hand-details-query" in selector or "On Hand Details" in selector:
|
||||
return _FakeLocator(visible=True)
|
||||
if "Queries" in selector or "navbar" in selector:
|
||||
return _FakeLocator(visible=True)
|
||||
return _FakeLocator(visible=False)
|
||||
|
||||
def get_by_role(self, role: str, name: str, exact: bool = False) -> _FakeLocator:
|
||||
if role == "link" and name in {"On Hand Details", "Queries"}:
|
||||
return _FakeLocator(visible=True)
|
||||
return _FakeLocator(visible=False)
|
||||
|
||||
def goto(self, url: str, wait_until: str = "", timeout: int = 0) -> None:
|
||||
self.goto_calls.append(url)
|
||||
self.url = url
|
||||
|
||||
|
||||
def test_navigate_prefers_dashboard_tile(monkeypatch):
|
||||
"""应优先尝试首页 On Hand Details 卡片。"""
|
||||
module = _load_navigation()
|
||||
page = _FakePage()
|
||||
calls: list[str] = []
|
||||
|
||||
monkeypatch.setattr(module, "is_crane_report_form_ready", lambda page_arg, entry_url: False)
|
||||
monkeypatch.setattr(
|
||||
module,
|
||||
"_click_dashboard_on_hand_details",
|
||||
lambda *args, **kwargs: calls.append("dashboard") or True,
|
||||
)
|
||||
monkeypatch.setattr(module, "_click_navbar_on_hand_details", lambda *args, **kwargs: calls.append("navbar") or True)
|
||||
monkeypatch.setattr(module, "_wait_for_report_navigation", lambda *args, **kwargs: True)
|
||||
|
||||
mode = module.navigate_to_crane_report(
|
||||
page,
|
||||
"https://wms-portal.craneww.com/#/on-hand-details-query",
|
||||
env=lambda name, default="": default,
|
||||
browser_timeout_ms=5_000,
|
||||
)
|
||||
|
||||
assert mode == "dashboard_tile"
|
||||
assert calls == ["dashboard"]
|
||||
assert page.goto_calls == []
|
||||
|
||||
|
||||
def test_navigate_falls_back_to_navbar_when_dashboard_misses(monkeypatch):
|
||||
"""首页卡片未进入报表时应回退顶部 Queries 菜单。"""
|
||||
module = _load_navigation()
|
||||
page = _FakePage()
|
||||
wait_calls = {"n": 0}
|
||||
|
||||
monkeypatch.setattr(module, "is_crane_report_form_ready", lambda page_arg, entry_url: False)
|
||||
monkeypatch.setattr(module, "_click_dashboard_on_hand_details", lambda *args, **kwargs: True)
|
||||
monkeypatch.setattr(module, "_click_navbar_on_hand_details", lambda *args, **kwargs: True)
|
||||
|
||||
def _wait(page_arg, entry_url, *, browser_timeout_ms):
|
||||
wait_calls["n"] += 1
|
||||
return wait_calls["n"] >= 2
|
||||
|
||||
monkeypatch.setattr(module, "_wait_for_report_navigation", _wait)
|
||||
|
||||
mode = module.navigate_to_crane_report(
|
||||
page,
|
||||
"https://wms-portal.craneww.com/#/on-hand-details-query",
|
||||
env=lambda name, default="": default,
|
||||
browser_timeout_ms=5_000,
|
||||
)
|
||||
|
||||
assert mode == "navbar_menu"
|
||||
assert wait_calls["n"] == 2
|
||||
|
||||
|
||||
def test_navigate_uses_direct_goto_as_last_resort(monkeypatch):
|
||||
"""卡片与菜单均失败时应 goto entry_url。"""
|
||||
module = _load_navigation()
|
||||
page = _FakePage()
|
||||
entry = "https://wms-portal.craneww.com/#/on-hand-details-query"
|
||||
|
||||
monkeypatch.setattr(module, "is_crane_report_form_ready", lambda page_arg, entry_url: False)
|
||||
monkeypatch.setattr(module, "_click_dashboard_on_hand_details", lambda *args, **kwargs: True)
|
||||
monkeypatch.setattr(module, "_click_navbar_on_hand_details", lambda *args, **kwargs: True)
|
||||
monkeypatch.setattr(module, "_wait_for_report_navigation", lambda *args, **kwargs: False)
|
||||
|
||||
with pytest.raises(RuntimeError, match="navigation failed"):
|
||||
module.navigate_to_crane_report(page, entry, env=lambda n, d="": d, browser_timeout_ms=5_000)
|
||||
|
||||
assert page.goto_calls[0] == entry
|
||||
assert any(call.rstrip("/") == "https://wms-portal.craneww.com" for call in page.goto_calls)
|
||||
|
||||
|
||||
def test_is_crane_on_report_route_reads_entry_hash():
|
||||
"""应从 entry_url hash 判断当前是否已在目标报表路由。"""
|
||||
module = _load_navigation()
|
||||
page = _FakePage(url="https://wms-portal.craneww.com/#/on-hand-details-query")
|
||||
entry = "https://wms-portal.craneww.com/#/on-hand-details-query"
|
||||
assert module.is_crane_on_report_route(page, entry) is True
|
||||
|
||||
|
||||
def test_homepage_is_not_report_form_ready():
|
||||
"""登录后首页 /#/ 不应被误判为报表表单已就绪。"""
|
||||
module = _load_navigation()
|
||||
page = _FakePage(url="https://wms-portal.craneww.com/#/")
|
||||
entry = "https://wms-portal.craneww.com/#/on-hand-details-query"
|
||||
assert module.is_crane_on_homepage(page) is True
|
||||
assert module.is_crane_report_form_ready(page, entry) is False
|
||||
|
||||
|
||||
def test_report_route_without_controls_is_not_ready(monkeypatch):
|
||||
"""仅有 hash 路由但无 Run Report 控件时仍不算 ready。"""
|
||||
module = _load_navigation()
|
||||
page = _FakePage(url="https://wms-portal.craneww.com/#/on-hand-details-query")
|
||||
entry = "https://wms-portal.craneww.com/#/on-hand-details-query"
|
||||
monkeypatch.setattr(module, "_has_report_form_controls", lambda page_arg: False)
|
||||
assert module.is_crane_report_form_ready(page, entry) is False
|
||||
Reference in new issue
Block a user