64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
from datetime import timezone, timedelta
|
|
from pathlib import Path
|
|
|
|
|
|
def test_sales_menu_uses_injected_latest_date():
|
|
from services.openclaw_bot import menu_keyboards
|
|
|
|
menu_keyboards.configure_menu_keyboards(
|
|
latest_date_provider=lambda: "2026/04/30",
|
|
goals={},
|
|
taipei_tz=timezone(timedelta(hours=8)),
|
|
)
|
|
|
|
rows = menu_keyboards._submenu_sales()
|
|
|
|
assert rows[0][0]["callback_data"] == "cmd:sales:2026/04/30"
|
|
assert rows[0][0]["text"] == "📊 今日 (04/30)"
|
|
assert rows[0][1]["callback_data"] == "cmd:sales:2026/04/29"
|
|
assert rows[-1] == menu_keyboards._BACK
|
|
|
|
|
|
def test_goal_menu_uses_injected_goal_state():
|
|
from services.openclaw_bot import menu_keyboards
|
|
|
|
menu_keyboards.configure_menu_keyboards(goals={"daily": 1_500_000, "monthly": 0})
|
|
|
|
rows = menu_keyboards._submenu_goals()
|
|
|
|
assert rows[1][0]["text"] == "日目標 (150萬)"
|
|
assert rows[1][1]["text"] == "月目標 (未設)"
|
|
|
|
|
|
def test_category_menu_and_submenu_registry_are_stable():
|
|
from services.openclaw_bot import menu_keyboards
|
|
|
|
menu_keyboards.configure_menu_keyboards(latest_date_provider=lambda: "2026/04/30")
|
|
|
|
rows = menu_keyboards._submenu_category()
|
|
|
|
assert rows[0][0]["callback_data"] == "cmd:catdetail:美妝保養:2026/04/30"
|
|
assert rows[-2] == [{"text": "🗂 全分類清單", "callback_data": "cmd:category:2026/04/30"}]
|
|
assert rows[-1] == menu_keyboards._BACK
|
|
assert set(menu_keyboards._SUBMENUS) >= {
|
|
"main",
|
|
"sales",
|
|
"products",
|
|
"goals",
|
|
"analysis",
|
|
"trend",
|
|
"reports",
|
|
"market",
|
|
"competitor",
|
|
"competitor_ppt",
|
|
"category",
|
|
}
|
|
|
|
|
|
def test_openclaw_routes_import_menu_keyboard_helpers():
|
|
route_source = Path("routes/openclaw_bot_routes.py").read_text(encoding="utf-8")
|
|
|
|
assert "from services.openclaw_bot.menu_keyboards import" in route_source
|
|
assert "configure_menu_keyboards(latest_date_provider=latest_date" in route_source
|
|
assert "def main_menu_keyboard():" not in route_source
|