"""Unit tests for IO image support"""
"""
LLM-Note: Tests for io image support

What it tests:
- Io Image Support functionality

Components under test:
- Module: io_image_support
"""


from connectonion.network.io import WebSocketIO


def test_send_image_helper():
    """Test that send_image() sends agent_image event with base64 data."""
    io = WebSocketIO()

    # Test sending an image
    image_data = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
    io.send_image(image_data)

    # Verify event was appended
    assert len(io._msgs_from_agent) == 1
    event = io._msgs_from_agent[0]
    assert event["type"] == "agent_image"
    assert event["image"] == image_data
    assert "id" in event  # Auto-generated ID
    assert "ts" in event  # Auto-generated timestamp


def test_send_image_multiple():
    """Test sending multiple images."""
    io = WebSocketIO()

    # Send multiple images
    image1 = "data:image/png;base64,first"
    image2 = "data:image/jpeg;base64,second"

    io.send_image(image1)
    io.send_image(image2)

    # Verify both events were appended
    assert len(io._msgs_from_agent) == 2
    assert io._msgs_from_agent[0]["type"] == "agent_image"
    assert io._msgs_from_agent[0]["image"] == image1
    assert io._msgs_from_agent[1]["type"] == "agent_image"
    assert io._msgs_from_agent[1]["image"] == image2
