test(02-02): add failing tests for FeishuResponseFormatter
- Test format_success returns valid card with green theme - Test format_error returns red theme - Test format_info returns blue theme - Test format with buttons includes actions element - Test format_paginated adds [N/M] marker - Test card has required structure (schema 2.0, config, elements) TDD RED phase - tests will fail until implementation is added. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
"""
|
||||
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"
|
||||
Reference in New Issue
Block a user