65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
"""
|
|
Tests for response_formatter module - FeishuResponseFormatter class.
|
|
Task 1: Test response formatting as Feishu Card JSON 2.0.
|
|
"""
|
|
import pytest
|
|
from gsd_openclaw.response_formatter import (
|
|
FeishuResponseFormatter, CardTheme, CardButton
|
|
)
|
|
|
|
|
|
class TestFeishuResponseFormatter:
|
|
"""Test response formatting for Feishu cards."""
|
|
|
|
def test_format_success_returns_valid_card(self):
|
|
"""Success card has green theme."""
|
|
formatter = FeishuResponseFormatter()
|
|
card = formatter.format_success("Test Title", "Test content")
|
|
|
|
assert card["schema"] == "2.0"
|
|
assert card["header"]["template"] == "green"
|
|
assert card["header"]["title"]["content"] == "Test Title"
|
|
|
|
def test_format_error_returns_red_theme(self):
|
|
"""Error card has red theme."""
|
|
formatter = FeishuResponseFormatter()
|
|
card = formatter.format_error("Error", "Something went wrong")
|
|
|
|
assert card["header"]["template"] == "red"
|
|
|
|
def test_format_info_returns_blue_theme(self):
|
|
"""Info card has blue theme."""
|
|
formatter = FeishuResponseFormatter()
|
|
card = formatter.format_info("Info", "Status update")
|
|
|
|
assert card["header"]["template"] == "blue"
|
|
|
|
def test_format_with_buttons_includes_actions(self):
|
|
"""Cards with buttons include action element."""
|
|
formatter = FeishuResponseFormatter()
|
|
button = CardButton("OK", {"action": "ok"})
|
|
card = formatter.format_success("Test", "Content", buttons=[button])
|
|
|
|
# Find action element
|
|
actions = [e for e in card["elements"] if e["tag"] == "action"]
|
|
assert len(actions) == 1
|
|
assert actions[0]["actions"][0]["text"]["content"] == "OK"
|
|
|
|
def test_format_paginated_adds_marker(self):
|
|
"""Paginated card has [N/M] marker."""
|
|
formatter = FeishuResponseFormatter()
|
|
card = formatter.format_paginated("Title", "Content", page=1, total_pages=3)
|
|
|
|
# Find the content in elements
|
|
content = card["elements"][0]["text"]["content"]
|
|
assert "[1/3]" in content
|
|
|
|
def test_card_has_required_structure(self):
|
|
"""Card has schema 2.0, config, and elements."""
|
|
formatter = FeishuResponseFormatter()
|
|
card = formatter.format_success("Test", "Content")
|
|
|
|
assert "config" in card
|
|
assert card["config"]["wide_screen_mode"] is True
|
|
assert card["elements"][0]["tag"] == "div"
|