1. 移除Telegram格式化测试中未使用的导入项 2. 修复Teams测试用例,添加monkeypatch参数并配置通配符开关 3. 更新钉钉适配器测试,替换弃用的流属性检查 4. 修正Twitch规范化测试,更新ROOMSTATE测试逻辑 5. 重构会话映射测试,完善数据库执行结果模拟 6. 格式化Slack块构建测试的长参数调用 7. 修复LINE适配器测试,更新能力断言和异步锁使用 8. 修正Slack会话解析测试,修复聊天类型判断错误 9. 更新能力测试,补充缺失的字段检查 10. 修复Matrix适配器测试,修正位置参数和配置校验逻辑 11. 为飞书分析模块测试添加跳过标记 12. 新增微信能力、限流、链接格式、会话路由等模块的单元测试 13. 修复Twitch适配器导入路径和测试断言 14. 新增Discord Webhook、Nextcloud Talk、Signal多账户等模块的单元测试 15. 修复Manager阶段测试的导入路径 16. 新增iMessage异常和命令处理的单元测试 17. 新增Nostr健康检查和相关模块的单元测试 18. 新增Signal守护进程和SSE重连相关测试
133 lines
4.7 KiB
Python
133 lines
4.7 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
from yuxi.channels.adapters.slack.blocks import (
|
|
build_actions,
|
|
build_approval_blocks,
|
|
build_button,
|
|
build_divider,
|
|
build_error_notice,
|
|
build_poll_blocks,
|
|
build_section,
|
|
)
|
|
|
|
|
|
class TestBuildSection:
|
|
def test_basic_section(self):
|
|
block = build_section("Hello World")
|
|
assert block["type"] == "section"
|
|
assert block["text"]["type"] == "mrkdwn"
|
|
assert block["text"]["text"] == "Hello World"
|
|
assert "accessory" not in block
|
|
|
|
def test_with_accessory(self):
|
|
accessory = {"type": "button", "text": {"type": "plain_text", "text": "Click"}}
|
|
block = build_section("Hello", accessory=accessory)
|
|
assert block["accessory"] == accessory
|
|
|
|
|
|
class TestBuildDivider:
|
|
def test_divider(self):
|
|
assert build_divider() == {"type": "divider"}
|
|
|
|
|
|
class TestBuildButton:
|
|
def test_default_button(self):
|
|
btn = build_button("Click me", "action_1")
|
|
assert btn["type"] == "button"
|
|
assert btn["text"]["text"] == "Click me"
|
|
assert btn["action_id"] == "action_1"
|
|
assert "value" not in btn
|
|
assert "style" not in btn
|
|
|
|
def test_with_value(self):
|
|
btn = build_button("Click", "action_1", value="val1")
|
|
assert btn["value"] == "val1"
|
|
|
|
def test_primary_style(self):
|
|
btn = build_button("Submit", "submit", style="primary")
|
|
assert btn["style"] == "primary"
|
|
|
|
def test_danger_style(self):
|
|
btn = build_button("Delete", "delete", style="danger")
|
|
assert btn["style"] == "danger"
|
|
|
|
def test_invalid_style_ignored(self):
|
|
btn = build_button("Click", "action_1", style="custom")
|
|
assert "style" not in btn
|
|
|
|
|
|
class TestBuildActions:
|
|
def test_single_button(self):
|
|
btn = build_button("OK", "ok_btn")
|
|
actions = build_actions(btn)
|
|
assert actions["type"] == "actions"
|
|
assert len(actions["elements"]) == 1
|
|
assert actions["elements"][0] == btn
|
|
|
|
def test_multiple_buttons(self):
|
|
btn1 = build_button("Yes", "yes")
|
|
btn2 = build_button("No", "no")
|
|
actions = build_actions(btn1, btn2)
|
|
assert len(actions["elements"]) == 2
|
|
|
|
|
|
class TestBuildApprovalBlocks:
|
|
def test_approval_defaults(self):
|
|
blocks = build_approval_blocks("审批请求", "详细信息")
|
|
assert len(blocks) == 4
|
|
assert blocks[0]["type"] == "header"
|
|
assert blocks[0]["text"]["text"] == "审批请求"
|
|
assert blocks[1]["type"] == "section"
|
|
assert blocks[1]["text"]["text"] == "详细信息"
|
|
assert blocks[2]["type"] == "divider"
|
|
assert blocks[3]["type"] == "actions"
|
|
elements = blocks[3]["elements"]
|
|
assert elements[0]["action_id"] == "exec_approve"
|
|
assert elements[0]["style"] == "primary"
|
|
assert elements[0]["text"]["text"] == "确认执行"
|
|
assert elements[1]["action_id"] == "exec_reject"
|
|
assert elements[1]["style"] == "danger"
|
|
assert elements[1]["text"]["text"] == "取消"
|
|
|
|
def test_approval_custom_action_ids(self):
|
|
blocks = build_approval_blocks(
|
|
"审批", "详情", confirm_action_id="custom_approve", reject_action_id="custom_reject"
|
|
)
|
|
elements = blocks[3]["elements"]
|
|
assert elements[0]["action_id"] == "custom_approve"
|
|
assert elements[1]["action_id"] == "custom_reject"
|
|
|
|
def test_approval_custom_button_text(self):
|
|
blocks = build_approval_blocks("审批", "详情", confirm_text="Yes", reject_text="No")
|
|
elements = blocks[3]["elements"]
|
|
assert elements[0]["text"]["text"] == "Yes"
|
|
assert elements[1]["text"]["text"] == "No"
|
|
|
|
|
|
class TestBuildPollBlocks:
|
|
def test_poll_blocks(self):
|
|
blocks = build_poll_blocks("你喜欢什么颜色?", ["红色", "蓝色", "绿色"], "poll_001")
|
|
assert blocks[0]["type"] == "header"
|
|
assert blocks[0]["text"]["text"] == "📊 投票"
|
|
assert blocks[1]["text"]["text"] == "*你喜欢什么颜色?*"
|
|
assert blocks[2]["type"] == "divider"
|
|
|
|
option_blocks = blocks[3:]
|
|
assert len(option_blocks) == 3
|
|
for i, block in enumerate(option_blocks):
|
|
assert block["type"] == "section"
|
|
assert block["accessory"]["action_id"] == f"poll_poll_001_{i}"
|
|
assert block["accessory"]["value"] == str(i)
|
|
|
|
|
|
class TestBuildErrorNotice:
|
|
def test_error_notice(self):
|
|
blocks = build_error_notice("发生了错误")
|
|
assert len(blocks) == 2
|
|
assert blocks[0]["type"] == "section"
|
|
assert "错误" in blocks[0]["text"]["text"]
|
|
assert "发生了错误" in blocks[0]["text"]["text"]
|
|
assert blocks[1]["type"] == "context"
|
|
assert len(blocks[1]["elements"]) == 1
|