"""Tests for diff and artifact renderers."""

from __future__ import annotations

from clients.terminal.tui.renderers.artifact import ArtifactRenderer
from clients.terminal.tui.renderers.diff import DiffRenderer
from clients.terminal.tui.themes import set_active_theme


def test_diff_renderer_accepts_and_highlights() -> None:
    set_active_theme("gnexus-dark")
    renderer = DiffRenderer()
    msg = {
        "type": "diff",
        "old_label": "a.py",
        "new_label": "b.py",
        "content": "--- a.py\n+++ b.py\n@@ -1,2 +1,2 @@\n-old\n+new\n unchanged\n",
    }
    assert renderer.accepts(msg)
    renderable = renderer.render(msg)
    text = str(renderable.renderable)
    assert "old" in text
    assert "new" in text


def test_artifact_renderer_accepts_and_renders() -> None:
    set_active_theme("gnexus-dark")
    renderer = ArtifactRenderer()
    msg = {
        "type": "artifact",
        "path": "src/main.py",
        "content": "def main():\n    pass\n",
    }
    assert renderer.accepts(msg)
    renderable = renderer.render(msg)
    assert renderable.renderable is not None
    assert "src/main.py" in renderable.title


def test_artifact_guesses_language_from_path() -> None:
    renderer = ArtifactRenderer()
    msg = {
        "type": "artifact",
        "path": "config.yaml",
        "content": "key: value\n",
    }
    renderable = renderer.render(msg)
    assert "yaml" in renderable.title
